Skip to main content

unsloth_rs/
error.rs

1// SPDX-License-Identifier: MIT
2// Copyright 2026 Tyler Zervas
3
4//! Error types for unsloth-rs.
5
6use thiserror::Error;
7
8/// Result type alias for unsloth-rs operations.
9pub type Result<T> = std::result::Result<T, UnslothError>;
10
11/// Errors that can occur in unsloth-rs operations.
12#[derive(Error, Debug)]
13#[non_exhaustive]
14pub enum UnslothError {
15    /// GPU kernel error.
16    #[error("kernel error: {0}")]
17    Kernel(String),
18
19    /// Out of memory.
20    #[error("out of memory: required {required} bytes, available {available} bytes")]
21    OutOfMemory {
22        /// Required memory in bytes
23        required: usize,
24        /// Available memory in bytes
25        available: usize,
26    },
27
28    /// Device not available.
29    #[error("device not available: {0}")]
30    DeviceNotAvailable(String),
31
32    /// Shape mismatch.
33    #[error("shape mismatch: expected {expected:?}, got {actual:?}")]
34    ShapeMismatch {
35        /// Expected shape
36        expected: Vec<usize>,
37        /// Actual shape
38        actual: Vec<usize>,
39    },
40
41    /// Invalid configuration.
42    #[error("invalid configuration: {0}")]
43    InvalidConfig(String),
44
45    /// Quantization error.
46    #[error("quantization error: {0}")]
47    Quantization(String),
48
49    /// Ternary operation error.
50    #[error("ternary operation error: {0}")]
51    Ternary(String),
52
53    /// Candle error.
54    #[error("candle error: {0}")]
55    Candle(#[from] candle_core::Error),
56}