pub struct ModuleList { /* private fields */ }Expand description
PyTorch nn.ModuleList 相当。forward を持たない子 Module の保持器。
forward は常に AutodiffError::InvalidArgument を返す。モードの正は自身のフラグ
(既定 true)で、set_training は全子へ伝播する。
Implementations§
Source§impl ModuleList
impl ModuleList
Trait Implementations§
Source§impl Default for ModuleList
impl Default for ModuleList
Source§impl From<ModuleList> for Sequential
impl From<ModuleList> for Sequential
Source§fn from(inner: ModuleList) -> Self
fn from(inner: ModuleList) -> Self
Converts to this type from the input type.
Source§impl FromIterator<Box<dyn Module>> for ModuleList
impl FromIterator<Box<dyn Module>> for ModuleList
Source§impl Module for ModuleList
impl Module for ModuleList
Source§fn forward<'t>(
&self,
_tape: TapeRef<'t>,
_input: &Var<'t>,
) -> Result<Var<'t>, AutodiffError>
fn forward<'t>( &self, _tape: TapeRef<'t>, _input: &Var<'t>, ) -> Result<Var<'t>, AutodiffError>
nn.ModuleList は forward を持たない。誤用を型付きエラーで検出する。
Source§fn children(&self) -> Vec<(String, &dyn Module)>
fn children(&self) -> Vec<(String, &dyn Module)>
子は "{index}"(named_parameters の接頭辞と一致。#2401)。
Source§fn set_requires_grad(
&mut self,
requires_grad: bool,
) -> Result<(), AutodiffError>
fn set_requires_grad( &mut self, requires_grad: bool, ) -> Result<(), AutodiffError>
全子へ伝播する。失敗したら適用済みの子と失敗した子自身(0..=index)を逆順に
適用前の値へ必ず戻し(requires_grad() が一致して見えても set_requires_grad を
呼ぶ)、復元失敗は打ち切らず集約して Err に含める。子孫は children/children_mut
経由で葉単位に復元するため、凍結済みと追跡中が混在する内側の複合層も
呼び出し前と完全一致に戻る(children_mut 不整合な構成は変更前に InvalidArgument)(autodiff 側と同じ契約。PR #2426 レビュー指摘)。
Source§fn requires_grad(&self) -> bool
fn requires_grad(&self) -> bool
パラメータを持つ子のどれかが true なら true。該当する子がいなければ true。
Source§fn set_parameter(
&mut self,
name: &str,
value: Tensor<f32>,
) -> Result<(), AutodiffError>
fn set_parameter( &mut self, name: &str, value: Tensor<f32>, ) -> Result<(), AutodiffError>
"{index}.{name}" を分解して子へ委譲する。区切りなし・index 非数値・範囲外は
すべて InvalidArgument(fail-closed。panic しない)。
Source§fn set_training(&mut self, training: bool)
fn set_training(&mut self, training: bool)
学習/評価モードの切替。既定は no-op(無状態層向け)。モード依存層は
Self::training と必ず両方を override して自層に保持すること。Source§fn named_parameters(&self) -> Vec<(String, &Tensor<f32>)>
fn named_parameters(&self) -> Vec<(String, &Tensor<f32>)>
学習可能パラメータの「名前, 参照」列。名前は struct フィールド名/accessor 名
を正とし、順序は登録順(weight → bias)。既定は空(無状態層向け)。
Source§fn state_dict(&self) -> HashMap<String, Tensor<f32>>
fn state_dict(&self) -> HashMap<String, Tensor<f32>>
Self::named_parameters のキー付きビュー(各値は clone)。順序契約は持たない。Source§fn load_state_dict(
&mut self,
state: HashMap<String, Tensor<f32>>,
) -> Result<(), AutodiffError>
fn load_state_dict( &mut self, state: HashMap<String, Tensor<f32>>, ) -> Result<(), AutodiffError>
Self::state_dict の逆(strict 限定)。 Read moreSource§fn freeze(&mut self) -> Result<(), AutodiffError>
fn freeze(&mut self) -> Result<(), AutodiffError>
Self::set_requires_grad(false) の別名(転移学習で backbone を固定する典型呼び出し)。Source§fn named_modules(&self) -> Vec<(String, &dyn Module)>
fn named_modules(&self) -> Vec<(String, &dyn Module)>
子孫を深さ優先(子自身 → その子孫)・登録順で再帰列挙する
(autodiff
Module::named_modules の鏡写し。#2134・#2401)。 Read moreSource§fn parameter_count(&self) -> usize
fn parameter_count(&self) -> usize
Self::named_parameters が公開する学習可能パラメータの総要素数
(autodiff Module::parameter_count の鏡写し。#2134・#2401)。
saturating_add で合計するためオーバーフローでも panic せず usize::MAX に飽和する。Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
実装型名(
std::any::type_name::<Self>())。出力形式は標準ライブラリが安定を
保証しないため表示用途に限る(autodiff Module::type_name の鏡写し。#2134・#2401)。
例外として、凍結ロールバックが子の型の照合キーに使う(Self::children_mut の (b)。
異なる型は区別できるが同じ型の別インスタンスは区別できない。偽る override は範囲外)。Auto Trait Implementations§
impl !RefUnwindSafe for ModuleList
impl !Send for ModuleList
impl !Sync for ModuleList
impl !UnwindSafe for ModuleList
impl Freeze for ModuleList
impl Unpin for ModuleList
impl UnsafeUnpin for ModuleList
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