use std::path::PathBuf;
use thiserror::Error;
use crate::format::{FormatError, ProjectionName};
#[derive(Debug, Error)]
pub enum IoError {
#[error(transparent)]
Format(#[from] FormatError),
#[error("{}: {source}", path.display())]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("layer {layer} out of range ({n_layers} layers)")]
LayerOutOfRange {
layer: u32,
n_layers: u32,
},
#[error("layer {layer}: expert {expert} out of range ({n_experts} experts)")]
ExpertOutOfRange {
layer: u32,
expert: u32,
n_experts: u32,
},
#[error("layer {layer}: layout has no {name:?} projection")]
MissingProjection {
layer: u32,
name: ProjectionName,
},
#[error("{what}: unknown quant format {quant:?}")]
UnknownQuant {
what: String,
quant: String,
},
#[error("{what}: range {offset}+{len} out of bounds ({available} bytes)")]
RangeOutOfBounds {
what: String,
offset: u64,
len: u64,
available: u64,
},
#[error("{what}: {value} does not fit usize on this platform")]
TooLarge {
what: &'static str,
value: u64,
},
#[error(
"expert cache budget of {given} B buys {slots} slot(s) per layer but \
the model routes {top_k} experts per step; use at least {needed} B \
({:.2} MiB)", *needed as f64 / (1024.0 * 1024.0)
)]
CacheBudgetTooSmall {
given: u64,
needed: u64,
slots: u32,
top_k: u32,
},
#[error(transparent)]
Slots(#[from] crate::io::SlotError),
#[error(transparent)]
Cache(#[from] crate::io::CacheError),
#[error(transparent)]
Sweep(#[from] Box<crate::io::SweepError>),
}
impl From<crate::io::SweepError> for IoError {
fn from(error: crate::io::SweepError) -> Self {
Self::Sweep(Box::new(error))
}
}
impl IoError {
pub(crate) fn io(path: &std::path::Path, source: std::io::Error) -> Self {
Self::Io {
path: path.to_path_buf(),
source,
}
}
}