Skip to main content

AutodiffError

Enum AutodiffError 

Source
#[non_exhaustive]
pub enum AutodiffError { Shape(ShapeError), Backward(String), TapeMismatch, InvalidArgument(String), Backend(BackendError), GradientTrackingDisabled, DeviceMismatch { requested: Device, actual: Device, }, }
Expand description

autodiff の公開 API が返すエラー型。

#[non_exhaustive] を付す理由: 公開 API 非破壊はガードレール条件 (.claude/rules/security.md)であり、TASK-1.5 で演算セットが拡張 されるたびに新しい失敗要因(Conv 系の padding 不整合等)の variant 追加を非破壊にするため(docs/public-api-design.md §3.1 準拠)。

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Shape(ShapeError)

順伝播時の shape 不整合(matmul/add/mul の不正なブロード キャスト、sum/max/mse_loss の shape 不一致等)。 tensor-core::ShapeError をラップする。

§

Backward(String)

Tape::backward(backward.rs・TASK-1.5c・#18)時のグラフ不整合 用に予約された variant。当初はクロステープ検査 (TapeMismatch。下記)で表現できる範囲のみを想定し構築箇所を 持たなかったが、TASK-12.1d(#164)の遅延評価統合で materialize_fallible(tape.rs)の OnceCell 不変条件違反 (set/get の理論上到達しないはずの None 分岐)検出用途に 転用する(docs/fusion-graph-design.md §3.5.2「OnceCell::set の Err は通常分岐として扱う」節。materialize_fallible は &'a Tensor<f32> を返す関数であり None 分岐で捏造した値への 参照を作れないため、安全側のフォール先を型付きエラーとする)。

§

TapeMismatch

二項演算(matmul/add/mul/mse_loss)に、異なる Tape に 属する Var が渡された。ライフタイム 't の一致は同一 Tape を指す証明にはならない(同一スコープに複数の Tape が存在する 場合、それぞれの Var<'t> は同一の 't を持ちうる)ため、 Var::matmul/add/mul/mse_loss は shape 検査より前に self.tape.id と相手側の TapeId を実行時照合し、不一致なら 本 variant を返す(docs/public-api-design.md §3.1 「クロステープ安全性」)。

§

InvalidArgument(String)

呼び出し元が渡した引数がテンソル未生成の段階で構築不可能な 組み合わせだった(例: nn::Linear::new の in_features == 0。 1/√in_features が非有限になるため shape 検査より前に弾く)。

tensor-core::ShapeError(#[non_exhaustive])へ variant を 追加する案もあったが、ShapeError は「テンソル生成・view 操作・ reshape の shape 不整合」(tensor-core/src/error.rs 冒頭)専用の 型であり、nn 層のコンストラクタ引数検証はその責務外 (tensor-core は nn を知らない下位クレート)。そのため autodiff 側で ShapeError をラップしない専用 variant として 追加する(review 指摘 #91: 既存 AxisOutOfRange への転用は 意味不一致だったため撤回)。

§

Backend(BackendError)

融合実行・実体化(TASK-12.1d・#164。materialize_fallible。 tape.rs)で発生した型付きバックエンドエラー。 fandhe_ai_tensor_core::BackendError をラップする(docs/ fusion-graph-design.md §3.5.2「層 1 は Unsupported 以外の run_fused の失敗をフォールバックせずそのまま伝播する」)。

§

GradientTrackingDisabled

Gradients::get の対象ノードが requires_grad == false (Tape::var_no_grad で登録した葉、または Var::detach で 切り離した葉、およびそれらのみを祖先に持つ非葉ノード)だった (イシュー #1748・docs/autodiff-nograd-leaf-dinput-skip-decision.md §5「案 B」)。「loss から未到達(Ok(None))」とは型で区別する ——未到達は「たまたま今回の loss には寄与しなかった」ことを、 本 variant は「この Var は構造的に勾配を持ちえない」ことを表す。

§

DeviceMismatch

crate::Var::to(イシュー #1614)が要求先デバイスと実際の デバイスの不一致を検出した。Var は所属する 1 つの Tape (=1 デバイス)に束縛されており(docs/public-api-design.md §3.1「クロステープ安全性」)、同一テープ内でデバイスを差し 替える演算は表現できない。単位 variant ではなく要求先・実際の 両方の Device を保持するのは、呼び出し元が「なぜ失敗した か」をエラー値だけから判断できるようにするため(BackendError:: DeviceUnavailable と同じ設計方針)。別デバイスへ実際に値を 転送したい場合は crate::Var::to_tape(もしくは facade Tape::transfer)を使う。

Fields

§requested: Device

呼び出し元が crate::Var::to へ渡した要求先デバイス。

§actual: Device

この Var が実際に属する Tape のデバイス。

Trait Implementations§

Source§

impl Debug for AutodiffError

Source§

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

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

impl Display for AutodiffError

Source§

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

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

impl Error for AutodiffError

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<BackendError> for AutodiffError

Source§

fn from(err: BackendError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<BinningError> for AutodiffError

tensor-core::binning の形状・引数検査失敗を写像する(イシュー #2638)。 写像規則は fandhe_ai_tensor_core::FftError 版と同じ。

Source§

fn from(err: BinningError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<FftError> for AutodiffError

tensor-core::fft の形状・引数検査失敗を写像する(イシュー #2631)。 形状違反は Shape、引数不正は InvalidArgument(バックエンド経由の unify_backend_error と同じ見え方に揃える)。

Source§

fn from(err: FftError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<PadModeError> for AutodiffError

tensor-core::pad_modes の形状・引数検査失敗を写像する(イシュー #2642)。 写像規則は fandhe_ai_tensor_core::StatReduceError 版と同じ。

Source§

fn from(err: PadModeError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<ShapeError> for AutodiffError

Source§

fn from(err: ShapeError) -> AutodiffError

Converts to this type from the input type.
Source§

impl From<StatReduceError> for AutodiffError

tensor-core::stat_reduce の形状・引数検査失敗を写像する(イシュー #2637)。 写像規則は fandhe_ai_tensor_core::FftError 版と同じ。

Source§

fn from(err: StatReduceError) -> AutodiffError

Converts to this type from the input type.

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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