Skip to main content

Gradients

Struct Gradients 

Source
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

Source

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§

Source§

impl Debug for Gradients

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Drop for Gradients

host arena(#2104・opt-in 既定 OFF)へ勾配バッファを返す回収点。学習ループでは Tape より先に Gradients が drop されるため、ここで回収しないと勾配バッファを 取りこぼす。無効時は何もしない。

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V