import torch
import torch.nn as nn
class M(nn.Module):
def __init__(self):
super().__init__()
self.l1 = nn.Linear(10,100)
def forward(self, inp):
out = self.l1(inp)
return out
m = M()
inp = torch.empty(10, 100)
out = m(inp)
print(out)
RuntimeError: size mismatch, m1: [10 x 100], m2: [10 x 100] at /pytorch/aten/src/TH/generic/THTensorMath.cpp:961
The number of input features for the linear layer is defined as 10, while you pass an input of [batch_size=10, features=100].
Also note, that torch.empty returns an uninitialized tensor, so you might have random values, Infs, NaNs, etc. in the tensor.