use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
pub enum TieredError {
#[error("VRAM allocation failed: {message}")]
VramAllocation {
message: String,
requested: u64,
available: u64,
},
#[error("RAM allocation failed: {message}")]
RamAllocation {
message: String,
requested: u64,
available: u64,
},
#[error("NVMe cache error: {message}")]
NvmeCache {
message: String,
path: Option<PathBuf>,
},
#[error("HCT decompression failed for {tensor}: {message}")]
Decompression {
tensor: String,
message: String,
},
#[error("layer {0} not found (model has {1} layers)")]
LayerNotFound(usize, usize),
#[error("tensor '{0}' not found")]
TensorNotFound(String),
#[error("shape mismatch: expected {expected}, got {got}")]
Shape {
expected: String,
got: String,
},
#[error("CUDA error: {0}")]
Cuda(String),
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("prefetch thread panicked: {0}")]
PrefetchPanic(String),
#[error("channel send failed: {0}")]
ChannelSend(String),
#[error("invalid configuration: {0}")]
Config(String),
#[error("failed to load model: {0}")]
ModelLoad(String),
#[error("weight store error: {0}")]
WeightStore(String),
}
impl TieredError {
pub fn vram_alloc(message: impl Into<String>, requested: u64, available: u64) -> Self {
Self::VramAllocation {
message: message.into(),
requested,
available,
}
}
pub fn ram_alloc(message: impl Into<String>, requested: u64, available: u64) -> Self {
Self::RamAllocation {
message: message.into(),
requested,
available,
}
}
pub fn nvme(message: impl Into<String>) -> Self {
Self::NvmeCache {
message: message.into(),
path: None,
}
}
pub fn nvme_path(message: impl Into<String>, path: impl Into<PathBuf>) -> Self {
Self::NvmeCache {
message: message.into(),
path: Some(path.into()),
}
}
pub fn decompress(tensor: impl Into<String>, message: impl Into<String>) -> Self {
Self::Decompression {
tensor: tensor.into(),
message: message.into(),
}
}
}
impl From<cudarc::driver::DriverError> for TieredError {
fn from(e: cudarc::driver::DriverError) -> Self {
Self::Cuda(e.to_string())
}
}
impl From<super::super::InferenceError> for TieredError {
fn from(e: super::super::InferenceError) -> Self {
Self::WeightStore(e.to_string())
}
}