Skip to main content

CreateGraphResult

Struct CreateGraphResult 

Source
pub struct CreateGraphResult<'c> { /* private fields */ }
Expand description

Tape::backward_create_graph の戻り値。1 階勾配 (Self::first_order。既存 backward_impl の無変更な結果)に 加え、子テープ 'c 上に構築した「元テープの祖先ノードの写し」 (Self::child_var)と「その 1 階勾配(子テープ上の Var)」 (Self::grad)を保持する。

Implementations§

Source§

impl<'c> CreateGraphResult<'c>

Source

pub fn first_order(&self) -> &Gradients

既存 Tape::backward と同一の 1 階勾配(Tensor<f32> の 入れ物)。子テープ構築とは独立のパス(Tape::backward をその まま呼ぶのみ)で計算するため、単体で backward を呼んだ場合と bit 同一(設計 doc §9「1 階勾配の bit 同一性」選択肢 (i)。 推奨として本イシューで採用)。

Source

pub fn grad( &self, parent_var: &Var<'_>, ) -> Result<Option<Var<'c>>, AutodiffError>

parent_var(元テープ上の Var)の 1 階勾配を、子テープ上の Var<'c> として返す(これをさらに child.backward(..) で 微分すれば二階勾配が得られる)。

  • parent_var が本 CreateGraphResult を生んだ親テープ・世代と 一致しない場合: Err(TapeMismatch)。
  • parent_var が requires_grad == false(var_no_grad/ detach の葉、またはそれのみを祖先に持つノード)の場合: Err(GradientTrackingDisabled)(Gradients::get と同じ区別。 docs/autodiff-nograd-leaf-dinput-skip-decision.md §5)。
  • loss から未到達、または対象 Op が Op::supports_create_graph を満たさない部分木の外側にある 場合: Ok(None)。
Source

pub fn child_var( &self, parent_var: &Var<'_>, ) -> Result<Option<Var<'c>>, AutodiffError>

parent_var の子テープ上の写し(forward 値の再生・または 定数葉化)を返す。cg.grad(&cg.child_var(&x)?.unwrap()) の ように、子テープ上でさらに backward した Gradients から 二階勾配を読み出す際の鍵として使う。

検査は Self::grad と同一。

Trait Implementations§

Source§

impl<'c> Debug for CreateGraphResult<'c>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'c> !RefUnwindSafe for CreateGraphResult<'c>

§

impl<'c> !Send for CreateGraphResult<'c>

§

impl<'c> !Sync for CreateGraphResult<'c>

§

impl<'c> !UnwindSafe for CreateGraphResult<'c>

§

impl<'c> Freeze for CreateGraphResult<'c>

§

impl<'c> Unpin for CreateGraphResult<'c>

§

impl<'c> UnsafeUnpin for CreateGraphResult<'c>

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