RunTime Error:Expected batch2_sizes[0] == bs && batch2_sizes[1] == contraction_size to be true, but got false

def forward(self, xf):

``````    a, b = self.model(torch.ones((self.size, self.size,2)), torch.zeros((self.size, self.size,2)))
c, d = self.model(torch.zeros((self.size, self.size,2)), torch.ones((self.size, self.size,2)))
b_c=b @ c  ***Error is shown here***
di_v=torch.div(b_c,d)

fin=a-di_v

yf=fin@xf

yf_abs = torch.sqrt(yf[..., 0] * yf[..., 0] + yf[..., 1] * yf[..., 1])

output = self.softmax(detector_region(yf_abs))

return output
``````

for this code, I am getting following error. Any suggestion will be highly appreciatedâ€¦

RuntimeError: Expected batch2_sizes[0] == bs && batch2_sizes[1] == contraction_size to be true, but got false. (Could this error message be improved? If so, please report an enhancement request to PyTorch.)

Could you print the shapes of `b` and `c` and check, if they would be compatible for a matrix multiplication?
Based on the error message it seems that one of these two tensors might have an unexpected shape.

The size for both b and c are ([200, 200, 2]). I am not sure how still there is a mismatch in the size.

A shape of `[200, 200, 2]` for both tensors is incompatible for a matrix multiplication.
The docs explain the shape requirements.

Assuming the first dimension is the batch size, you would have to make sure the shapes are defined as:

``````C = A @ B
[k, m, p] = [k, m, n] @ [k, n, p]
``````
1 Like