Is the pseudocode something like this:
loss = criterion(mdl(x), y)
loss.backward()
for name, w in mdl.named_parameters():
    w.grad = w.grad + 1.0


note:  I wanted to do something like the above but collect the gradients from an rpc (hence my curiosity for actual code example but the link didn’t seem super useful, I’d probably do something like w.grad = rpc_grads in my real example)