Hi,
You will have to create new intermediary Tensors like the following.
Also hooks are a good way to modify these gradients.
b = # some tensor that requires_grad
b1 = b.view_as(b) # returns a new Tensor that is the same as b
def modif_for_grad1(grad):
  return 3 * grad + 42
b1.register_hook(modif_for_grad1)
b2 = b.view_as(b) # returns a new Tensor that is the same as b
b2.register_hook(modif_for_grad2)

loss1 = function(a, b1)
loss2 = function(b2)