Hi,
You need to be careful because it is not because a function has a value of 0 that its gradient is going to be 0.
Why don’t you just do something like this:
    a = torch.autograd.Variable(torch.Tensor((1,2)), requires_grad=True)
    loss = torch.sum(torch.exp(-2*(a[0]-a[1])**2))
    loss.backward()
    print('loss:', loss)
    print('grad:', a.grad)