Well given the fact the gradients of the sum are additive I’d say if you keep track of the 1st loss, then compute the second and substract you should get that.
EDIT:
To give more context, gradients in pytorch are accumulative so each time you backward gradients are retained and sumed.