Skip to main content

haagenti_sparse/
error.rs

1//! Error types for sparse attention
2
3use thiserror::Error;
4
5/// Errors that can occur during sparse attention operations
6#[derive(Debug, Error)]
7pub enum SparseError {
8    /// Invalid mask dimensions
9    #[error("Invalid mask dimensions: expected {expected_heads} heads, {expected_layers} layers, got {actual_heads}x{actual_layers}")]
10    InvalidDimensions {
11        expected_heads: usize,
12        expected_layers: usize,
13        actual_heads: usize,
14        actual_layers: usize,
15    },
16
17    /// Head index out of range
18    #[error("Head index {index} out of range (max: {max})")]
19    HeadIndexOutOfRange { index: usize, max: usize },
20
21    /// Layer index out of range
22    #[error("Layer index {index} out of range (max: {max})")]
23    LayerIndexOutOfRange { index: usize, max: usize },
24
25    /// Sparsity constraint violation
26    #[error("Sparsity {actual:.2} below minimum required {minimum:.2}")]
27    SparsityTooLow { actual: f32, minimum: f32 },
28
29    /// Quality constraint violation
30    #[error("Quality loss {actual:.3} exceeds threshold {threshold:.3}")]
31    QualityLoss { actual: f32, threshold: f32 },
32
33    /// Kernel execution error
34    #[error("Kernel execution failed: {0}")]
35    KernelError(String),
36
37    /// Prediction model error
38    #[error("Prediction failed: {0}")]
39    PredictionError(String),
40
41    /// Analysis error
42    #[error("Analysis failed: {0}")]
43    AnalysisError(String),
44}
45
46/// Result type for sparse attention operations
47pub type Result<T> = std::result::Result<T, SparseError>;