pub struct Adjoints { /* private fields */ }Expand description
The recorded reverse-mode result: one gradient symbol per wrt
entry, in wrt order, paired with the entry it differentiates.
Tape::differentiate and
Tape::vjp return this carrier instead of bare
symbols because their product exists to be paired — each gradient
with its wrt entry for
Run::recorded_gradients, and
all of them with the target for a training request’s roots.
Holding the pairs makes misordered pairs unrepresentable: no
consumer rebuilds the pairing by parallel-vector discipline.
The carrier is plain data — detached symbols, no tape borrow — so
it survives sealing the tape and crosses threads like any
Symbol.
Implementations§
Source§impl Adjoints
impl Adjoints
Sourcepub fn target(&self) -> Symbol
pub fn target(&self) -> Symbol
Returns the differentiated value: the scalar loss for
Tape::differentiate, the seeded
value — any shape — for Tape::vjp.
Sourcepub fn wrt(&self) -> impl Iterator<Item = Symbol> + '_
pub fn wrt(&self) -> impl Iterator<Item = Symbol> + '_
Returns the wrt entries in their original order.
Sourcepub fn gradients(&self) -> impl Iterator<Item = Symbol> + '_
pub fn gradients(&self) -> impl Iterator<Item = Symbol> + '_
Returns the gradient symbols in wrt order.
Sourcepub fn of(&self, wrt: Symbol) -> Symbol
pub fn of(&self, wrt: Symbol) -> Symbol
Returns the gradient recorded for wrt.
§Panics
Panics if wrt was not an entry of the transform that produced
this carrier.
Sourcepub fn roots(&self) -> impl Iterator<Item = Symbol> + '_
pub fn roots(&self) -> impl Iterator<Item = Symbol> + '_
Returns the training roots: the target, then every gradient in
wrt order — the exact root list a compiled training plan
wants, so Entry::roots(adjoints.roots()) replaces the
hand-chained loss-plus-gradients idiom.
Sourcepub fn map_gradients(&self, rewrite: impl FnMut(Symbol) -> Symbol) -> Self
pub fn map_gradients(&self, rewrite: impl FnMut(Symbol) -> Symbol) -> Self
Returns a new carrier with each gradient symbol rewritten by
rewrite, pairing and target preserved.
The emission consumers use this to substitute same-shape reshape aliases for the raw gradient nodes — pinning the emitted result order — without ever holding gradients as a bare list.