Skip to main content

ModuleList

Struct ModuleList 

Source
pub struct ModuleList { /* private fields */ }
Expand description

PyTorch nn.ModuleList 相当。forward を持たない子 Module の保持器。

forward は常に AutodiffError::InvalidArgument を返す。モードの正は自身のフラグ (既定 true)で、set_training は全子へ伝播する。

Implementations§

Source§

impl ModuleList

Source

pub fn new() -> Self

空の ModuleList を作る。

Source

pub fn push(&mut self, module: Box<dyn Module>)

子 Module を末尾へ追加する(子のモードは同期しない)。

Source

pub fn len(&self) -> usize

保持している子 Module の数。

Source

pub fn is_empty(&self) -> bool

子 Module を 1 つも保持していないか。

Source

pub fn get(&self, index: usize) -> Option<&dyn Module>

index の子への参照(範囲外は None。panic しない)。

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut (dyn Module + 'static)>

Self::get の可変版。

Source

pub fn iter(&self) -> impl Iterator<Item = &Box<dyn Module>>

子の走査(層順)。

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Box<dyn Module>>

Self::iter の可変版。

Trait Implementations§

Source§

impl Default for ModuleList

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl From<ModuleList> for Sequential

Source§

fn from(inner: ModuleList) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Box<dyn Module>> for ModuleList

Source§

fn from_iter<I: IntoIterator<Item = Box<dyn Module>>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Module for ModuleList

Source§

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)>

子は "{index}"(named_parameters の接頭辞と一致。#2401)。

Source§

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

パラメータを持つ子のどれかが true なら true。該当する子がいなければ true。

Source§

fn children_mut(&mut self) -> Vec<(String, &mut dyn Module)>

children の可変版(名前・順序は同一。#2400)。

Source§

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)

学習/評価モードの切替。既定は no-op(無状態層向け)。モード依存層は Self::training と必ず両方を override して自層に保持すること。
Source§

fn training(&self) -> bool

現在のモード。既定は true(PyTorch Module.training の初期値と同じ)。
Source§

fn named_parameters(&self) -> Vec<(String, &Tensor<f32>)>

学習可能パラメータの「名前, 参照」列。名前は struct フィールド名/accessor 名 を正とし、順序は登録順(weight → bias)。既定は空(無状態層向け)。
Source§

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>

Self::state_dict の逆(strict 限定)。 Read more
Source§

fn freeze(&mut self) -> Result<(), AutodiffError>

Self::set_requires_grad(false) の別名(転移学習で backbone を固定する典型呼び出し)。
Source§

fn named_modules(&self) -> Vec<(String, &dyn Module)>

子孫を深さ優先(子自身 → その子孫)・登録順で再帰列挙する (autodiff Module::named_modules の鏡写し。#2134・#2401)。 Read more
Source§

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

実装型名(std::any::type_name::<Self>())。出力形式は標準ライブラリが安定を 保証しないため表示用途に限る(autodiff Module::type_name の鏡写し。#2134・#2401)。 例外として、凍結ロールバックが子の型の照合キーに使う(Self::children_mut の (b)。 異なる型は区別できるが同じ型の別インスタンスは区別できない。偽る override は範囲外)。

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