Skip to main content

littlebit_core/
error.rs

1//! Typed errors for `littlebit-core`.
2
3use thiserror::Error;
4
5/// Result alias for `littlebit-core` operations.
6pub type Result<T> = std::result::Result<T, LittleBitError>;
7
8/// Errors produced by LittleBit quantization, SVD/ITQ decomposition, packing, or I/O.
9#[derive(Debug, Error)]
10pub enum LittleBitError {
11    /// Underlying Candle tensor operation failed.
12    #[error("tensor operation failed: {0}")]
13    Candle(#[from] candle_core::Error),
14
15    /// Safetensors serialization or deserialization failed.
16    #[error("safetensors error: {0}")]
17    SafeTensors(#[from] safetensors::SafeTensorError),
18
19    /// Filesystem I/O failure.
20    #[error("i/o error: {0}")]
21    Io(#[from] std::io::Error),
22
23    /// JSON configuration or index parsing failure.
24    #[error("json error: {0}")]
25    Json(#[from] serde_json::Error),
26
27    /// Invalid quantization configuration or hyperparameter.
28    #[error("invalid quantization config: {0}")]
29    InvalidConfig(String),
30
31    /// Tensor shape did not match expected dimensions.
32    #[error("invalid tensor shape: expected {expected}, got {actual}")]
33    InvalidShape {
34        /// Expected shape description.
35        expected: String,
36        /// Actual shape description.
37        actual: String,
38    },
39
40    /// Binary tensor contained a value other than `-1` or `+1`.
41    #[error("invalid binary value {value} at ({row}, {col}); expected -1 or +1")]
42    InvalidBinaryValue {
43        /// Row index.
44        row: usize,
45        /// Column index.
46        col: usize,
47        /// Observed value.
48        value: i8,
49    },
50
51    /// Linear algebra SVD computation failed.
52    #[error("svd decomposition failed: {0}")]
53    SvdFailed(String),
54
55    /// Required checkpoint tensor was missing from the state dictionary.
56    #[error("missing tensor `{0}` in state dict")]
57    MissingTensor(String),
58
59    /// Tensor dtype is not supported by the operation.
60    #[error("unsupported tensor dtype: {0}")]
61    UnsupportedDtype(String),
62
63    /// Model directory contains no recognized checkpoint weights.
64    #[error("no model weights found in `{0}`")]
65    CheckpointNotFound(String),
66}
67
68const _: () = {
69    const fn assert_send_sync<T: Send + Sync + 'static>() {}
70    assert_send_sync::<LittleBitError>();
71};