Here is a simple test model, which is incorrect due to size mismatch between fc1 and fc2. Trying to use the model gives a mat size mismatch error as expected. However, on computing the same on a GPU gives an output without any errors!
class testModel(nn.Module): def __init__(self) -> None: super().__init__() #Python3 syntax self.fc1 = nn.Linear(10, 10) self.fc2 = nn.Linear(5,1) def forward(self, x): x = self.fc1(x) x = self.fc2(x) return x
This does not work (As expected):
inp = torch.ones((1,10)) model = testModel() out = model(inp)
The resulting error:
“RuntimeError: mat1 and mat2 shapes cannot be multiplied (1x10 and 5x1)”
But this works!
inp = torch.ones((1,10)).to('cuda:0') model = testModel().to('cuda:0') out = model(inp)
I am assuming it has something to do with “has_torch_function_variadic” in nn.functional.
Is this a bug or any reason this is allowed to happen?