pub struct GradientTape { /* private fields */ }Expand description
Thread-affine reverse-mode recording scope.
Constructing a tape selects it for operations on the current thread.
GradientTape::backward closes the recording scope and records the
corresponding backward operations into the originating runtime’s eager batch.
Implementations§
Source§impl GradientTape
impl GradientTape
Sourcepub fn backward(&self, root: &Matrix) -> Result<()>
pub fn backward(&self, root: &Matrix) -> Result<()>
Record the reverse-mode operations leading to one scalar loss.
The current checkpoint supports any recorded FP32 scalar result whose
reverse path is composed entirely from admitted operations. Gradients
accumulate on stable crate::ml::Parameter handles. This method records
but does not submit or wait.
§Errors
Returns an error when the tape was already consumed, root was not
produced by this tape, a saved parameter changed before backward, or
gradient operation validation/allocation/recording fails.
Source§impl GradientTape
impl GradientTape
Sourcepub fn watch(&self, parameter: &Parameter) -> Result<()>
pub fn watch(&self, parameter: &Parameter) -> Result<()>
Watch a parameter so backward accumulates its adjoint into the leaf.
Module forwards register their parameters automatically; raw matrix-or
audio-operation compositions that use parameter.data() directly must
watch the parameter explicitly or its gradient is silently dropped.
Watching is deduplicated by parameter identity and validates the
parameter version at backward time, so a parameter mutated in place
after recording still fails loudly.