As far as I know backward computes the gradients all the way back to the leave nodes. I mean, there’s no way for backward knowing which particular gradients you are interested in and when. Maybe the simplest way for computing the gradients you are interested in is doing it semi-automatically via the grad function:
from torch.autograd import grad

d_a_b = grad(a, b, retain_graph=True)
d_a_c = grad(a, c, retain_graph=True)
...

Then use d_a_b etc. to update the weights