Run the hooks of output output_nr of producer on that slot's whole gradient, then retain the result if the tensor asked for it.
The hooks run with the GIL held and grad mode off. A hook that returned a
tensor replaces the gradient — after the checks Tensor.grad = makes —
and one that returned None leaves it as the hook left it, in-place
writes included. Once a hook has run, a CPU gradient is copied before it
flows on: the hook may keep what it was handed, or hand back a tensor
somebody else reads, and the engine adds into gradients in place.
Raises
:error_already_setA hook raised; the exception reaches the caller of backward as it was.
:type_errorA hook returned something that is neither a tensor nor
None.DtypeMismatch, DeviceMismatch, ShapeMismatchA hook returned a gradient of another kind than it was given.