Skip to main content

combs_models/
lib.rs

1//! # combs-models
2//!
3//! Model architecture registry. The runtime drives any architecture through
4//! the fixed [`GenerativeModel`] contract (MLC's `embed/prefill/decode/
5//! create_kv_cache` function set); architectures register themselves in the
6//! [`ModelRegistry`]. Phase 1 ships the Llama family (incl. SmolLM2).
7
8mod kv;
9mod llama;
10mod matmul;
11mod norm;
12mod quant_linear;
13mod registry;
14mod rope;
15mod smolvlm;
16mod traits;
17
18pub use kv::{CacheConfig, CacheKind, ContiguousKVCache, KVCache, PagedKVCache};
19pub use llama::LlamaModel;
20pub use norm::rms_norm;
21pub use quant_linear::QuantizedLinear;
22pub use registry::ModelRegistry;
23pub use rope::RotaryEmbedding;
24pub use smolvlm::{SmolVlmModel, image_prompt_expansion, pixels_to_tensor};
25pub use traits::GenerativeModel;
26
27/// Errors produced while constructing or running models.
28#[derive(Debug, thiserror::Error)]
29pub enum ModelError {
30    /// A format-adapter error.
31    #[error(transparent)]
32    Format(#[from] combs_formats::FormatError),
33
34    /// No registered architecture matches the source metadata.
35    #[error("unsupported architecture: {0}")]
36    UnsupportedArchitecture(String),
37
38    /// Media input (image/audio) was passed to a model that cannot take it.
39    #[error("unsupported media input: {0}")]
40    UnsupportedMedia(String),
41
42    /// A required weight tensor is missing from the source.
43    #[error("missing weight tensor: {0}")]
44    MissingTensor(String),
45
46    /// A weight tensor has an unexpected shape.
47    #[error("bad shape for {tensor}: expected {expected:?}, got {got:?}")]
48    BadShape {
49        /// Tensor name.
50        tensor: String,
51        /// Expected shape.
52        expected: Vec<usize>,
53        /// Actual shape.
54        got: Vec<usize>,
55    },
56}
57
58/// Convenient result alias for this crate.
59pub type Result<T> = std::result::Result<T, ModelError>;