Solved by ptrblck in post #6 
              
              
                Yes, you can use the inputs argument to loss.backward to specify which tensors should be used for the gradient computation. All other tensors will be ignored.