import torch.nn.functional as F from torch.autograd import Variable F.conv2d(Variable(a.view(1,1,3,3)),Variable(b.view(1,1,3,3)))