Yes you could. The only question is whether autograd will recognize the operation that you are making (which in this case it will). So to make an example:
>>> A = torch.autograd.Variable(torch.Tensor(2,2), requires_grad=True)
>>> B = torch.autograd.Variable(torch.Tensor(2,2), requires_grad=True)
>>> f = lambda x,y: (x-y).sum()
>>> loss = f(A,B)
>>> loss
Variable containing:
 8.5899e+09
[torch.FloatTensor of size 1]

>>> loss.backward()
>>> A.grad
Variable containing:
 1  1
 1  1
[torch.FloatTensor of size 2x2]

>>> B.grad
Variable containing:
-1 -1
-1 -1
[torch.FloatTensor of size 2x2]

So as you can see we did not need to specify a backward() method because autograd was able to infer how to compute the gradient automatically from the operation we did on our variables.