pub struct Gradients { /* private fields */ }Expand description
Tape::backward が返す勾配の入れ物。Var 単位で get() から
引ける(docs/public-api-design.md §3.1)。
ノードごとの勾配を Option で保持し、loss から到達しないノードは
None のまま残す(PoC-v2-2 の「None を zeros 埋め」はしない設計。
未到達ノードの勾配を暗黙に 0 とみなすと、呼び出し側が「そもそも
loss に寄与していない」ことと「寄与はあるが偶然 0」を区別できなく
なるため、get() の戻り値を Option のまま伝える)。
Implementations§
Source§impl Gradients
impl Gradients
Sourcepub fn get(&self, var: &Var<'_>) -> Result<Option<&Tensor<f32>>, AutodiffError>
pub fn get(&self, var: &Var<'_>) -> Result<Option<&Tensor<f32>>, AutodiffError>
var に対応する勾配を取得する。var が別 Tape に属する場合、
または var が属する Tape が本 Gradients 計算後に reset()
された場合(#1048。同一 TapeId のまま世代だけ進んだ場合を含む)
は Err(TapeMismatch)(Var::matmul 等のクロステープ検査
〈var.rs〉と同じ契約を世代不一致にも拡張)。backward 実行後に
同一世代内で追加された Var(node_id() が grads.len() 以上)
や、loss から到達しない Var は Ok(None)(境界外アクセスで
panic しない。.claude/rules/coding-rust.md 本番経路 panic
禁止方針)。
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Gradients
impl RefUnwindSafe for Gradients
impl Send for Gradients
impl Sync for Gradients
impl Unpin for Gradients
impl UnsafeUnpin for Gradients
impl UnwindSafe for Gradients
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more