use std::path::PathBuf;
use thiserror::Error;
#[derive(Debug, Error)]
pub enum PackError {
#[error(
"module '{module}': weight has {got} columns, expected in/16 = {expected} \
(in_features = {in_features})"
)]
WeightColumnsMismatch {
module: String,
got: usize,
expected: usize,
in_features: usize,
},
#[error(
"module '{module}': {which} has {got} columns, expected in/128 = {expected} \
(in_features = {in_features})"
)]
GroupColumnsMismatch {
module: String,
which: &'static str,
got: usize,
expected: usize,
in_features: usize,
},
#[error("module '{module}': {which} has {got} elements, expected {expected}")]
BufferLengthMismatch {
module: String,
which: &'static str,
got: usize,
expected: usize,
},
#[error("module '{module}': in_features = {in_features} is not a positive multiple of 128")]
InFeaturesNotAligned {
module: String,
in_features: usize,
},
#[error(
"module '{module}' [row {row}, group {group}]: 2-bit code value {value} > 2 \
(reserved q=3 found; tensor is not ternary)"
)]
CodeOutOfRange {
module: String,
row: usize,
group: usize,
value: u8,
},
#[error(
"module '{module}' [row {row}, group {group}]: bias ({bias}) != -scale (-{scale}); \
affine quantization is not symmetric ternary"
)]
AsymmetricBias {
module: String,
row: usize,
group: usize,
bias: f32,
scale: f32,
},
}
#[derive(Debug, Error)]
pub enum MlxImageImportError {
#[error("I/O error for {path:?}: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("failed to parse safetensors file {path:?}: {msg}")]
Parse {
path: PathBuf,
msg: String,
},
#[error("module '{module}': {reason}")]
BadModule {
module: String,
reason: String,
},
#[error("packing failed: {0}")]
Pack(#[from] PackError),
#[error("GGUF writer error: {0}")]
GgufWrite(String),
#[error("unsupported quantisation format '{0}'; only 'tq2_0_g128' is supported")]
UnsupportedQuant(String),
}