CRTP base supplying boilerplate fields and methods to concrete backward nodes with a fixed number of forward inputs.
Inherit as class FooBackward : public AutogradNode<FooBackward, N> —
or, more commonly, through the FuncOp alias — to obtain
N-slot saved-input storage, automatic version validation, and an
engine-friendly release_saved implementation. The derived class
must expose a static constexpr OpSchema schema_v1 whose .name
field identifies the op in error messages and traces, and must
implement apply returning one Storage per forward
input.
Template Parameters
Derived : class
The concrete backward node class (CRTP self-type). Must expose a
static constexpr member schema_v1 with at least a .name
std::string_view field.
N_IN : std::size_t
Number of input tensors the corresponding forward op consumes.
Determines the compile-time size of saved_inputs_,
input_shapes_, input_tensors_, and
saved_impl_inputs_.
See Also
Node — the abstract base whose virtuals this class overrides.
FuncOp — alias used by most concrete backward classes.
Notes
Lifecycle. The forward op builder constructs an instance, fills
input_tensors_, input_shapes_, saved_inputs_,
saved_output_, dtype_, and device_, then calls
Node::set_next_edges and Node::set_saved_versions
before attaching the node to the output TensorImpl via
set_grad_fn. During backward the engine calls
validate_versions then apply. After apply
returns, the engine calls release_saved, which resets every
Storage slot to a default-constructed (zero-byte)
CpuStorage so referenced memory can be freed immediately.
Thread safety. None. All access happens on the single backward thread.
Slot ordering. saved_inputs_ and the gradients returned
from apply are ordered to match the forward op's positional
argument list — changing that order is a wire-format break.