I assume you would like to calculate the gradients for a few time steps.
If that’s the case, you could probably call:
loss1 = ...
loss2 = ...
loss1.backward(retain_graph=True)  # doesn't clear the intermediates
loss2.backward()

Note that this procedure will accumulate the gradients.