use std::error::Error;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum InitializationError<E>
where
E: Error + 'static,
{
#[error("random initialization requires rank {minimum}..={maximum}, got {actual}")]
InvalidRank {
actual: usize,
minimum: usize,
maximum: usize,
},
#[error("initialization parameter {parameter} must be finite, got {value}")]
NonFiniteParameter {
parameter: &'static str,
value: f64,
},
#[error("uniform lower bound must not exceed upper bound, got {low} > {high}")]
InvalidUniformBounds {
low: f64,
high: f64,
},
#[error("normal standard deviation must be non-negative, got {value}")]
NegativeStandardDeviation {
value: f64,
},
#[error("{parameter} must be positive, got {value}")]
InvalidFan {
parameter: &'static str,
value: usize,
},
#[error("attention d_model {d_model} must be positive and divisible by {heads} heads")]
InvalidHeadConfiguration {
d_model: usize,
heads: usize,
},
#[error("transformer layer count must be positive, got {layers}")]
InvalidLayerCount {
layers: usize,
},
#[error("fan_in + fan_out exceeds usize: {fan_in} + {fan_out}")]
FanArithmeticOverflow {
fan_in: usize,
fan_out: usize,
},
#[error("{lhs_name} * {rhs_name} exceeds usize: {lhs} * {rhs}")]
FanProductOverflow {
lhs_name: &'static str,
lhs: usize,
rhs_name: &'static str,
rhs: usize,
},
#[error("{operation} backend initialization failed")]
Backend {
operation: &'static str,
#[source]
source: E,
},
}
impl<E> From<E> for InitializationError<E>
where
E: Error + 'static,
{
fn from(source: E) -> Self {
Self::Backend {
operation: "parameter construction",
source,
}
}
}