Hello @adrianalbert,
well, in theory you could do
model = nn.Conv2d(1,1,3,padding=1, bias=False) # you'll have a better model
img_input = Variable(torch.ones(1,1,2,2), requires_grad=True)
img_output = model(img_input)

onepix = torch.FloatTensor(1,1,2,2)
for x in range(2):
    for y in range(2):
        onepix.zero_()
        onepix[0,0,x,y] = 1
        img_input.grad = None
        img_output.backward(gradient=onepix, retain_graph=True)
        print (x,y,img_input.grad)

(with retain_graph being retain_variables for <= 0.1.12).
Of course, that is cool for 1x2x2 images to check things out but not  anything you would want to use on a larger scale.
Best regards
Thomas