I’m not familiar with your use case, but given your description I think your suggestion sounds right.
output_from_A.backward() can take any gradients in the shape of output_from_A, so as long as this condition is met you could pass the manually gradients to this method.