x = torch.rand(1, 1, 64, 64)
gauss_kernel = torch.Tensor([[0, 0, 0], [0, 1, 0], [0, 0, 0]]).unsqueeze(0).unsqueeze(0)
out = F.conv2d(x, gauss_kernel, padding=1)
print(x)
print(gauss_kernel)
print(out)
tensor([[[[0.7888, 0.7222, 0.9251,  ..., 0.1763, 0.8585, 0.7747],
          [0.8203, 0.2307, 0.4474,  ..., 0.8498, 0.3399, 0.2610],
          [0.0001, 0.2678, 0.2113,  ..., 0.9698, 0.3422, 0.1166],
          ...,
          [0.7921, 0.1250, 0.1268,  ..., 0.8102, 0.1775, 0.4617],
          [0.1761, 0.6137, 0.6097,  ..., 0.0786, 0.8547, 0.4948],
          [0.7365, 0.6266, 0.6305,  ..., 0.6367, 0.0811, 0.8240]]]])
tensor([[[[0., 0., 0.],
          [0., 1., 0.],
          [0., 0., 0.]]]])
tensor([[[[0.7888, 0.7222, 0.9251,  ..., 0.1763, 0.8585, 0.7747],
          [0.8203, 0.2307, 0.4474,  ..., 0.8498, 0.3399, 0.2610],
          [0.0001, 0.2678, 0.2113,  ..., 0.9698, 0.3422, 0.1166],
          ...,
          [0.7921, 0.1250, 0.1268,  ..., 0.8102, 0.1775, 0.4617],
          [0.1761, 0.6137, 0.6097,  ..., 0.0786, 0.8547, 0.4948],
          [0.7365, 0.6266, 0.6305,  ..., 0.6367, 0.0811, 

This way you don’t have to wrap your kernel into a Parameter and you don’t have to modify the weights by hand, it might also reduce some memory (which really is not that relevant in this small example).