I used this as a solution:
import torch
import torch.nn.functional as F
x= torch.randn([10, 3, 4, 4], dtype=torch.float32)
xsize= x.shape
xx= x.view(xsize[0]*xsize[1], 1, xsize[2], xsize[3])
f= torch.tensor([[0,0.5,0],[0,-1,0],[0,0.5,0]], dtype=torch.float32)
f=f.view(1,1,3,3)
y= F.conv2d(xx, f, bias= None, padding=1, stride=1)