Hi Matthew!



 matthewleigh:

I am allowed to multiply matrices of incompatible sizes so long as it takes place on the gpu.


I would say this is a bug (@ptrblck) – in any event it violates the
principle of least surprise.
I can reproduce this on version 1.9.0:
>>> import torch
>>> torch.__version__
'1.9.0'
>>> torch.nn.Linear (3, 3) (torch.randn (5, 10))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<path_to_pytorch>/torch/nn/modules/module.py", line 1051, in _call_impl
    return forward_call(*input, **kwargs)
  File "<path_to_pytorch>/torch/nn/modules/linear.py", line 96, in forward
    return F.linear(input, self.weight, self.bias)
  File "<path_to_pytorch>/torch/nn/functional.py", line 1847, in linear
    return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (5x10 and 3x3)
>>> torch.nn.Linear (3, 3).cuda() (torch.randn (5, 10).cuda())
tensor([[-0.2980, -0.2856,  0.2935],
        [-0.3196, -0.7825, -0.0424],
        [-0.0242, -0.7375,  0.1639],
        [-0.9905, -0.4888,  0.2138],
        [-0.8091, -0.5870,  0.1135]], device='cuda:0', grad_fn=<AddmmBackward>)

Best.
K. Frank