Hi,
If we assume TF.get_total_loss computes just adddition of multiple loss terms then we have these scenarios:
But the error you are getting is from calling loss.backward for multiple times.
Lets say you have following scenario (scenario #1):
input = #sth
ground_truth = #sth
output = model(input)
loss1 = criterion(output, ground_truth)
loss2 = criterion(changed_output, another_ground_truth)
# etc
total_loss = loss1 + loss2 + ...
total_loss.backward()  # this works 

Now scenario #2:
input = #sth
ground_truth = #sth
output = model(input)
loss1 = criterion(output, ground_truth)
loss1.backward()  #now graph buffers have been freed, you cannot do backward on the same forward 
loss2 = criterion(changed_output, another_ground_truth)
loss2.backward()  # error, trying to do backward second time
# etc
total_loss = loss1 + loss2 + ...
total_loss.backward()  # this obviously does not work

You have not showed how you compute loss.backward or how many times you call it, but if you set retain_graph=True for previously used backwards, such as loss1 and loss2 in scenario #2, then you should be able to do another backward using total_loss.
TF docs are not clear but I think they are using first scenario.
Bests