btil:

loss = Variable(loss, requires_grad=True)


Doing this is 100% wrong. You break the graph and create a new Tensor with no history. So your backward will just stop at loss.
If you properly use the actions that require grads to compute the loss. Then the loss will require gradients naturally and all will work.
You need to make sure you don’t do any op that breaks the link.