candle_mi/error.rs
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! Error types for candle-mi.
4
5/// Errors that can occur during MI operations.
6///
7/// This enum is `#[non_exhaustive]`: new variants will be added in future
8/// releases as new backends and capabilities are added.
9#[non_exhaustive]
10#[derive(Debug, thiserror::Error)]
11pub enum MIError {
12 /// Model loading or forward pass error (wraps candle).
13 #[error("model error: {0}")]
14 Model(#[from] candle_core::Error),
15
16 /// Hook capture or lookup error.
17 #[error("hook error: {0}")]
18 Hook(String),
19
20 /// Intervention validation or application error.
21 #[error("intervention error: {0}")]
22 Intervention(String),
23
24 /// Model configuration parsing error.
25 #[error("config error: {0}")]
26 Config(String),
27
28 /// Tokenizer error.
29 #[error("tokenizer error: {0}")]
30 Tokenizer(String),
31
32 /// I/O error.
33 #[error(transparent)]
34 Io(#[from] std::io::Error),
35
36 /// Model download error.
37 ///
38 /// Returned when downloading a model from the `HuggingFace` Hub fails.
39 #[error("download error: {0}")]
40 Download(String),
41
42 /// Memory measurement error.
43 ///
44 /// Returned when a platform API for RAM or VRAM measurement fails.
45 #[error("memory error: {0}")]
46 Memory(String),
47}
48
49/// Result type alias for candle-mi operations.
50pub type Result<T> = std::result::Result<T, MIError>;