pub struct GradNode<Op: GraphOp> { /* private fields */ }Expand description
Backward computation node for eager reverse-mode AD.
A GradNode records one primal operation, the stable input aliases used to
replay that operation during backward, the user-visible output keys that can
receive cotangent seeds, and the edges to parent eager values.
§Examples
ⓘ
use tidu::{GradEdge, GradNode};
let node = GradNode::new(
op,
input_aliases,
output_keys,
saved_forward_values,
vec![GradEdge::new(parent_node, input_key, true)],
);Implementations§
Source§impl<Op: GraphOp> GradNode<Op>
impl<Op: GraphOp> GradNode<Op>
Sourcepub fn new(
op: Op,
primal_in_keys: Vec<GlobalValKey<Op>>,
primal_out_keys: Vec<GlobalValKey<Op>>,
saved_data: HashMap<GlobalValKey<Op>, Arc<Op::Operand>>,
input_edges: Vec<GradEdge<Op>>,
) -> Self
pub fn new( op: Op, primal_in_keys: Vec<GlobalValKey<Op>>, primal_out_keys: Vec<GlobalValKey<Op>>, saved_data: HashMap<GlobalValKey<Op>, Arc<Op::Operand>>, input_edges: Vec<GradEdge<Op>>, ) -> Self
Create a grad node and validate the shape of its eager AD metadata.
primal_in_keys must contain GlobalValKey::Input aliases. The eager
backward path linearizes one operation at a time and rebuilds those
aliases as fragment inputs.
§Examples
ⓘ
let node = tidu::GradNode::new(
op,
input_aliases,
output_keys,
saved_data,
input_edges,
);Sourcepub fn primal_in_keys(&self) -> &[GlobalValKey<Op>]
pub fn primal_in_keys(&self) -> &[GlobalValKey<Op>]
Stable input aliases used for single-op backward replay.
Sourcepub fn primal_out_keys(&self) -> &[GlobalValKey<Op>]
pub fn primal_out_keys(&self) -> &[GlobalValKey<Op>]
User-visible output keys, one per primal output slot.
Sourcepub fn saved_data(&self) -> &HashMap<GlobalValKey<Op>, Arc<Op::Operand>>
pub fn saved_data(&self) -> &HashMap<GlobalValKey<Op>, Arc<Op::Operand>>
Saved concrete primal input and derived output values.
Sourcepub fn input_edges(&self) -> &[GradEdge<Op>]
pub fn input_edges(&self) -> &[GradEdge<Op>]
Edges to the eager values that provided this node’s inputs.
Auto Trait Implementations§
impl<Op> Freeze for GradNode<Op>where
Op: Freeze,
impl<Op> RefUnwindSafe for GradNode<Op>where
Op: RefUnwindSafe,
<Op as GraphOp>::InputKey: RefUnwindSafe,
<Op as GraphOp>::Operand: RefUnwindSafe,
impl<Op> Send for GradNode<Op>
impl<Op> Sync for GradNode<Op>
impl<Op> Unpin for GradNode<Op>
impl<Op> UnsafeUnpin for GradNode<Op>where
Op: UnsafeUnpin,
impl<Op> UnwindSafe for GradNode<Op>where
Op: UnwindSafe + RefUnwindSafe,
<Op as GraphOp>::InputKey: UnwindSafe + RefUnwindSafe,
<Op as GraphOp>::Operand: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more