Hi, the issue is the way you are calculating norm. As outputs do not have same shape, torch broadcast values so you get wrong norm.



 bernardomig:

torch.norm(conv(x) - linear(x.view(3, 16)))


linear = nn.Linear(16, 8)
conv = nn.Conv2d(16, 8, 1)

conv.weight = nn.Parameter(linear.weight.reshape(8, 16, 1, 1))
conv.bias = nn.Parameter(linear.bias)

batch=5
x = torch.randn(batch, 16, 1, 1)
co = conv(x)
lo = linear(x.view(batch, 1, 16))
co = co.view(lo.shape)
torch.norm(co - lo)  # small value around 2.0e-07

Bests