Static methods
2The forward argument slot j stands for, which the error names: Derived::kArgPositions where the node is wired on fewer inputs than its op takes (lu_solve(LU, pivots, B) wires {LU, B}), otherwise j itself.
Whether the gradient of input i reads input j's values: Derived::kGradReads where the node declares it, otherwise every gradient is taken to read every input the node saved.
Virtual methods
4Drop every reference held for backward so that memory can be reclaimed immediately after the engine finishes with this node.
Resets all entries of saved_inputs_, clears
saved_output_, empties the input_tensors_ weak
array, releases the strong TensorImpl references in
saved_impl_inputs_, and clears the weak
saved_impl_output_ handle.
Notes
Called by Engine once apply returns, except when
retain_graph=True. After this call the node retains only its
sequence number and (now-empty) metadata; calling apply
again is undefined.
Put back, for graph-mode backward, every saved tensor a write since forward may have changed without validate_versions refusing.
An input is replaced by the tensor it was at forward time, rebuilt
from saved_inputs_ and its edge (forward_time_input),
when it no longer sits where it did — reachable past the version check
only while that check is waived. The output is always rebuilt — from
saved_output_, with this node as its grad_fn — by dropping the
weak handle, which is the case a reader already covers for an output
that is gone: no version guards it, and a write under no_grad
leaves its grad_fn where it was, so nothing on the live tensor says
whether it still holds the values this node saw. Either way
graph-mode backward reads the values eager backward reads.
Raises
LucidErrorapply reads the values this node kept: those in its slots (keep_input, keep_output), and those a node keeps in members of its own, which it declares with kKeepsOwnValues (tools/check_saved_versions.py requires it of every node class holding a tensor of its own). A node that kept none frees just the tensors graph-mode backward reads, and an eager pass may run it again.
Verify that no input whose values apply reads has been written in place since forward.
An input is guarded when its values sit in saved_inputs_
(holds_saved_values) — the slot a backward that reads them
saves them in — and a gradient that is needed reads them: one whose
input takes a gradient (a live edge), by grad_reads. The
others are not: add, sum or a view read at most their shape,
and x * c with a constant c reads x only for c's
gradient, which nothing asks for. Refusing a write into one of them
refused what the reference allows. Expired weak references are
skipped — if the input has been destroyed, no consumer can observe a
corrupted gradient.
Raises
VersionMismatchDerived::schema_v1.name) and the offending input index.Methods
12The inputs kept for graph-mode backward; the output is held weakly.
Keep s as input i's values, or the output's, for apply. The slot is recorded as kept whatever its size: an eager pass reads it even for a tensor of no elements — on Metal as the GPU buffer a release replaces — so a released one must be refused, as the reference refuses it.
Every input's values at once.
keep_needed_input
void keep_needed_input(int i, const int & impl, const int & storage_src, bool saves)Keep input i for backward when saves is false (recording only impl for graph-mode metadata) or when some needed gradient reads input i (saving both storage_src->storage() and impl).
Human-readable name of the op, sourced from Derived::schema_v1.
Returns
std::string_viewThe schema name (e.g. "linear", "matmul"). Used in error messages, profiler traces, and create_graph failure reports.
Whether input i has a valid outgoing autograd edge (requires grad).
Whether some input that takes a gradient has one reading input j.
Return saved_inputs_[i] when it was kept, or a zero-filled storage of input_shapes_[i] when no needed gradient reads input i (used by fused multi-output backward kernels whose unneeded output slots are discarded).