I believe sum is automatic as a result of how gradients are accumulated during backward. You won’t need to do any summation yourself.
A simple example could be:
import torch

a = torch.tensor(2., requires_grad=True)
b = a * a
c = a + 1

grad_out = torch.ones_like(a)

db_da = torch.autograd.grad(b, a, grad_out, retain_graph=True)
dc_da = torch.autograd.grad(c, a, grad_out, retain_graph=True)
dbc_da = torch.autograd.grad((b, c), a, (grad_out, grad_out))

print(f"{dbc_da} = {db_da} + {dc_da}")