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>
impl<'c> CreateGraphResult<'c>
Sourcepub fn first_order(&self) -> &Gradients
pub fn first_order(&self) -> &Gradients
既存 Tape::backward と同一の 1 階勾配(Tensor<f32> の
入れ物)。子テープ構築とは独立のパス(Tape::backward をその
まま呼ぶのみ)で計算するため、単体で backward を呼んだ場合と
bit 同一(設計 doc §9「1 階勾配の bit 同一性」選択肢 (i)。
推奨として本イシューで採用)。
Sourcepub fn grad(
&self,
parent_var: &Var<'_>,
) -> Result<Option<Var<'c>>, AutodiffError>
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)。
Sourcepub fn child_var(
&self,
parent_var: &Var<'_>,
) -> Result<Option<Var<'c>>, AutodiffError>
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§
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> 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