Barrier autograd node inserted on each gradient-bearing input of a hooked nn.Module.
Mirrors ModuleOutputHookNode but on the other side of the
module: it collects the gradients flowing back into the module's inputs
and fires the full backward hooks (which receive both grad_input and
grad_output tuples) before forwarding the (possibly replaced)
gradients to the upstream graph.
See Also
ModuleOutputHookNode : sibling barrier on the output side.
Notes
Hooks may return None (keep current gradients) or a tuple matching
the positional input signature with None entries for slots that
should remain untouched. A returned gradient must have the dtype, device
and shape of the one it replaces — downstream nodes read it with the
metadata captured in ModuleBackwardHookState::input_metas — and a
tuple of another length, an entry that is not a tensor, or a tensor for an
argument that takes no gradient is refused. When a hook is refused, or
raises, nothing any hook returned flows on and the state is reset.
Constructors
1ModuleInputHookNode
void ModuleInputHookNode(int state)Construct an input-side barrier bound to shared hook state.
Parameters
statestd::shared_ptr<ModuleBackwardHookState>Virtual methods
4A hook's None, or a slot no gradient reached, is an empty storage.
Identifies this node as a staged barrier.
Once the module's output barrier has run in this pass, the input barrier runs even when every output gradient was dropped on the way in, so the inputs and full hooks still receive materialized zeros.
Methods
8Add an incoming input gradient to what its slot holds.
Parameters
input_ nrstd::uint32_tModuleBackwardHookState::grad_inputs). Out-of-range values are ignored.gradStorageaccumulate_barrier_grad_for_graph
void accumulate_barrier_grad_for_graph(int input_nr, int grad)accumulate_barrier_grad for a create_graph pass.
Convenience non-barrier entry point — see ModuleOutputHookNode::apply.
Parameters
grad_ outStorageReturns
std::vector<Storage>One Storage per outgoing edge.
Fire the full-backward hooks and emit one gradient per outgoing edge. The module's backward ends here, so the shared state is reset for the next pass.
Returns
std::vector<Storage>One Storage per input edge in declaration order. Hooks may have replaced individual entries via their return tuple; empty slots become empty CpuStorage placeholders.
apply_barrier for a create_graph pass.
Graph label — "ModuleInputHook" — for debug printing and profiler traces. Overrides Node::node_name.
Fire the full-backward hooks once per pass; graph as for ModuleOutputHookNode::run_hooks.