rwth-i6 / pytorch-to-returnn

Make PyTorch code runnable within RETURNN
3 stars 6 forks source link

Broadcasting after transpose #58

Closed vieting closed 3 years ago

vieting commented 3 years ago

In the case of a multiplication of a transposed tensor with some other tensor, we currently run into issues when matching axes, see also https://github.com/rwth-i6/returnn/issues/719

I added a testcase to demonstrate the problem. If the logic in _unify_tensor_axes_returnn_meta() would not add a broadcasting dim, this would work fine.

vieting commented 3 years ago

As pointed out in https://github.com/rwth-i6/returnn/issues/719, we generally don't want to add unnecessary broadcasting dims in RETURNN. The auto-added dim is also the reason why the test case fails.

I added a fix which removes the behavior of adding broadcasting dims by default. The remaining changes revert the order in which the axes are scrolled through to match the broadcasting behavior.