ruvector_sparse_inference/
error.rs1use thiserror::Error;
4
5pub type Result<T> = std::result::Result<T, SparseInferenceError>;
7
8#[derive(Debug, Error)]
10pub enum SparseInferenceError {
11 #[error("Predictor error: {0}")]
13 Predictor(#[from] PredictorError),
14
15 #[error("Model error: {0}")]
17 Model(#[from] ModelError),
18
19 #[error("Inference error: {0}")]
21 Inference(#[from] InferenceError),
22
23 #[error("Cache error: {0}")]
25 Cache(String),
26
27 #[error("Quantization error: {0}")]
29 Quantization(String),
30
31 #[error("IO error: {0}")]
33 Io(#[from] std::io::Error),
34
35 #[error("Serialization error: {0}")]
37 Serialization(String),
38
39 #[error("GGUF error: {0}")]
41 Gguf(#[from] GgufError),
42}
43
44#[derive(Debug, Error)]
46pub enum PredictorError {
47 #[error("Invalid predictor configuration: {0}")]
49 InvalidConfig(String),
50
51 #[error("Dimension mismatch: expected {expected}, got {actual}")]
53 DimensionMismatch { expected: usize, actual: usize },
54
55 #[error("Predictor not calibrated")]
57 NotCalibrated,
58
59 #[error("Invalid rank: {0}")]
61 InvalidRank(usize),
62
63 #[error("Calibration failed: {0}")]
65 CalibrationFailed(String),
66}
67
68#[derive(Debug, Error)]
70pub enum InferenceError {
71 #[error("Input dimension mismatch: expected {expected}, got {actual}")]
73 InputDimensionMismatch { expected: usize, actual: usize },
74
75 #[error("No active neurons predicted")]
77 NoActiveNeurons,
78
79 #[error("Inference failed: {0}")]
81 Failed(String),
82
83 #[error("Backend error: {0}")]
85 Backend(String),
86
87 #[error("Invalid input: {0}")]
89 InvalidInput(String),
90}
91
92#[derive(Debug, Error)]
94pub enum ModelError {
95 #[error("Invalid model configuration: {0}")]
97 InvalidConfig(String),
98
99 #[error("Weight dimension mismatch: {0}")]
101 WeightDimensionMismatch(String),
102
103 #[error("Model not loaded")]
105 NotLoaded,
106
107 #[error("Invalid activation type: {0}")]
109 InvalidActivation(String),
110
111 #[error("Failed to load model: {0}")]
113 LoadFailed(String),
114}
115
116#[derive(Debug, Error)]
118pub enum GgufError {
119 #[error("Invalid GGUF format: {0}")]
121 InvalidFormat(String),
122
123 #[error("GGUF IO error: {0}")]
125 Io(String),
126
127 #[error("Unsupported tensor type: {0}")]
129 UnsupportedTensorType(String),
130
131 #[error("Invalid tensor type: {0}")]
133 InvalidTensorType(u32),
134
135 #[error("Invalid GGUF magic number: {0:#010X}")]
137 InvalidMagic(u32),
138
139 #[error("Unsupported GGUF version: {0}")]
141 UnsupportedVersion(u32),
142
143 #[error("Missing metadata: {0}")]
145 MissingMetadata(String),
146
147 #[error("Invalid metadata type: {0}")]
149 InvalidMetadataType(String),
150
151 #[error("Invalid value type: {0}")]
153 InvalidValueType(u32),
154
155 #[error("Tensor not found: {0}")]
157 TensorNotFound(String),
158}
159
160impl From<std::io::Error> for GgufError {
161 fn from(err: std::io::Error) -> Self {
162 GgufError::Io(err.to_string())
163 }
164}
165
166impl From<std::string::FromUtf8Error> for GgufError {
167 fn from(err: std::string::FromUtf8Error) -> Self {
168 GgufError::InvalidFormat(format!("Invalid UTF-8 string: {}", err))
169 }
170}
171
172impl From<serde_json::Error> for SparseInferenceError {
173 fn from(err: serde_json::Error) -> Self {
174 SparseInferenceError::Serialization(err.to_string())
175 }
176}
177
178impl From<String> for SparseInferenceError {
179 fn from(err: String) -> Self {
180 SparseInferenceError::Model(ModelError::LoadFailed(err))
181 }
182}