File size: 880 Bytes
f4f166e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;

#[derive(Debug, Error)]
pub enum Error {
    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("json error: {0}")]
    Json(#[from] serde_json::Error),

    #[error("checkpoint format error: {0}")]
    Checkpoint(String),

    #[error("model error: {0}")]
    Model(String),

    #[error("shape mismatch: expected {expected:?}, got {got:?} for tensor {name}")]
    Shape {
        name: String,
        expected: Vec<usize>,
        got: Vec<usize>,
    },

    #[error("missing tensor {0} in checkpoint")]
    MissingTensor(String),

    #[error("unsupported dtype {0}")]
    Dtype(String),

    #[error("shape error: {0}")]
    Shapes(String),
}

impl From<ndarray::ShapeError> for Error {
    fn from(e: ndarray::ShapeError) -> Self {
        Error::Shapes(e.to_string())
    }
}