use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum DequantError {
#[error("unsupported MatMulNBits configuration: {0}")]
Unsupported(String),
#[error("length mismatch for {what}: expected {expected} bytes, got {got}")]
LengthMismatch {
what: &'static str,
expected: usize,
got: usize,
},
#[error(
"4-bit ZP nibble value {value} at index {index} exceeds 2-bit maximum (3); \
GatherBlockQuantized 'bits=4' attribute appears inconsistent with the \
actual packed data"
)]
NibbleOutOfRange {
index: usize,
value: u8,
},
}
#[derive(Debug, Error)]
pub enum OnnxImportError {
#[error("I/O error for {path:?}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to parse ONNX file {path:?}: {msg}")]
Parse {
path: PathBuf,
msg: String,
},
#[error("missing external_data entry '{key}' for initializer '{tensor}'")]
MissingExternalEntry {
tensor: String,
key: &'static str,
},
#[error("unsupported initializer dtype {dtype} for tensor '{tensor}'")]
UnsupportedDtype {
tensor: String,
dtype: i32,
},
#[error("config.json not found near {onnx_path:?}")]
ConfigJsonMissing {
onnx_path: PathBuf,
},
#[error("failed to parse {path:?}: {source}")]
ConfigJsonInvalid {
path: PathBuf,
#[source]
source: serde_json::Error,
},
#[error("MatMulNBits node '{node}' input[{index}] ('{name}') is not an initializer")]
MissingInitializer {
node: String,
index: usize,
name: String,
},
#[error("MatMulNBits node '{node}' missing attribute '{attr}'")]
MissingAttribute {
node: String,
attr: &'static str,
},
#[error("expected initializer '{name}' not found in graph")]
MissingNamedInitializer {
name: String,
},
#[error("dequantization failed for node '{node}': {source}")]
Dequant {
node: String,
#[source]
source: DequantError,
},
#[error("TQ2_0_g128 quantization failed for tensor '{tensor}': {msg}")]
Requantize {
tensor: String,
msg: String,
},
#[error("GGUF writer error: {0}")]
GgufWrite(String),
#[error("{0}")]
Other(String),
}