pub struct GradMap { /* private fields */ }Expand description
Map from forward-graph node IDs to the IDs of their accumulated
backward-graph gradient nodes, returned by NodeHandle::backward.
All gradient nodes live on the same graph as the forward nodes. Getting
a gradient by calling GradMap::get returns a new NodeHandle handle
pointing at the gradient node so callers can realize it, plug it into
further computation, or back-propagate through it again.
Implementations§
Source§impl GradMap
impl GradMap
Sourcepub fn get(&self, forward: &NodeHandle) -> Option<NodeHandle>
pub fn get(&self, forward: &NodeHandle) -> Option<NodeHandle>
Get the gradient tensor for a forward tensor from the same graph.
Returns None if the forward tensor was not reachable from the
root passed to backward (i.e. not part of the computation being
differentiated).
§Panics
Panics if any operand belongs to a different Graph than the one this
builder is building into. Operand identity is graph-scoped and checked by
pointer identity (Arc::ptr_eq), which cannot alias; the panic is
deliberate and replaces the hang a cross-graph handle used to produce.
Build every operand from one graph, or use a Result-returning entry
point where one exists.