If you want to compute these two contributions independently, then you will need to either:

create a graph with only that one branch using .detach() in the other
use hooks on the second branch to zero-out its contribution (u.register_hook(lambda x: torch.zeros_like(x))`).

That way you can get the two terms by doing two backward passes. And then you can accumulate the gradients from the two backward to get the final value that you want.