Problem with Einsum

Hi everyone,i am having some trouble with torch.einsum.Basically i am trying to mutliply two tensors in a certain way:

first = torch.rand(12,8192,2)

weights1 = torch.rand(12,8192,2)

torch.einsum('bix,iox->box',first,weights1)

But i get the following error:
einsum() operands do not broadcast with remapped shapes [original->remapped]: [12, 8192, 2]->[12, 1, 2, 8192] [12, 8192, 2]->[1, 8192, 2, 12]

Can someone explain to me what I am doing wrong?

Something is up with the i dimensions: in the first tensor it is 8192, in the second 12.

I must admit the error message isn’t as clear as it could be, so I took the liberty to file an issue with your example: Clarity of error message in einsum regressed in performance improvements · Issue #58380 · pytorch/pytorch · GitHub

Thank you for asking this and providing a straightforward example, it gives us a chance to improve the error message.

Best regards

Thomas

1 Like

Thank you so much for your answer!