Barrier autograd node inserted on each output of a hooked nn.Module.
Plays two roles during backward:
- Receives output gradients from downstream nodes through
accumulate_barrier_grad, parking them into the sharedModuleBackwardHookStaterather than producing input gradients on the fly. This lets the engine reach the barrier from every consumer before any hook fires. - When
apply_barrierruns, invokes the user-registered pre-backward hooks (if any), giving them an opportunity to replace the output gradients before they continue propagating back through the module body.
See Also
ModuleInputHookNode : sibling barrier on the input side.
ModuleBackwardHookState : shared state container.
Notes
Marked as a barrier (is_barrier() == true), which the engine uses to
switch from the fast apply() path to the staged barrier protocol.
The node does not modify gradients unless a registered hook explicitly
returns a replacement tuple.
Constructors
1ModuleOutputHookNode
void ModuleOutputHookNode(int state)Construct an output-side barrier bound to shared hook state.
Parameters
statestd::shared_ptr<ModuleBackwardHookState>Virtual methods
1Methods
4Park a single incoming gradient into the shared state.
Parameters
input_nrstd::uint32_tgradStorageConvenience entry point used when the engine reaches this node via the non-barrier fast path: forwards to accumulate_barrier_grad and then immediately runs apply_barrier.
Parameters
grad_outStorageReturns
std::vector<Storage>One Storage per outgoing edge, in output_edge_indices order.
Fire the pre-backward hooks and emit one Storage per outgoing edge. Called by the engine exactly once after all incoming gradients have been accumulated.
Returns
std::vector<Storage>Gradients to push along each outgoing edge. Empty slots become empty CpuStorage placeholders.
Graph label — "ModuleOutputHook" — for debug printing and profiler traces. Overrides Node::node_name.