Hi,
You don’t actually need to do two backwards if you just want to accumulate the gradients, you can do:
tm.a_optimizer.zero_grad()  
tm.b_optimizer.zero_grad()
(a_loss + b_loss).backward()

And you will get gradients for a and b parameters as long as they were used to compute loss.