Skip to main content

cherenkov/model/
mod.rs

1//! Hardware-independent checkpoint inspection and preparation requirements.
2//!
3//! Adapters assign meaning to checkpoint names. Consumers use typed roles,
4//! encodings, and data references; display names never select execution behavior.
5
6mod format;
7pub mod index;
8mod inspect;
9mod preparation;
10pub(crate) mod qwen;
11
12pub use cherenkov_model_data::{
13    AffineOffset, BitPacking, ByteSource, DataSpan, Dtype, GgmlEncoding, MappedBytes,
14    MappedObjects, ObjectId, ObjectInfo, StoredTensor, Tensor, TensorEncoding, TensorId,
15    TensorRole, TensorType,
16};
17pub use format::*;
18pub use inspect::Checkpoint;
19pub(crate) use inspect::describe_raw;
20pub use preparation::*;
21use serde::{Deserialize, Serialize};
22
23/// Architecture-adapted metadata and storage views, independent of execution hardware.
24#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct ModelDescription {
26    /// Version of this description's serialized schema.
27    pub schema_version: u32,
28    /// Container format and conventions used to interpret its tensors.
29    pub format: CheckpointFormat,
30    /// Recognized architecture, or its original name when no adapter is available.
31    pub architecture: Architecture,
32    /// Source metadata retained by the adapter.
33    pub metadata: serde_json::Value,
34    /// Tensor descriptors, indexed by `TensorId`.
35    pub tensors: Vec<Tensor>,
36    /// N-gram hashing and shard layout, when present and understood.
37    pub ngram: Option<NgramTable>,
38}
39
40/// Model architecture recognized by the loader.
41#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(tag = "kind", rename_all = "snake_case")]
43pub enum Architecture {
44    Qwen4Exp,
45    Opaque { name: String },
46}
47
48/// A table's hashing semantics are separate from its row encoding and placement.
49#[derive(Debug, Clone, Serialize, Deserialize)]
50pub struct NgramTable {
51    /// Hash parameters used to select table rows.
52    pub hashing: NgramHash,
53    /// Row ranges and the tensors storing them.
54    pub shards: Vec<TableShard>,
55}
56
57/// Hashing scheme and parameters, separate from the table's stored representation.
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(tag = "kind", rename_all = "snake_case")]
60pub enum NgramHash {
61    Qwen4Exp {
62        ngram_size: u64,
63        heads_per_ngram: u64,
64        head_offsets: Vec<u64>,
65        head_vocab_sizes: Vec<u64>,
66        layer_multipliers: Vec<i64>,
67    },
68    Opaque {
69        name: String,
70    },
71}
72
73/// A contiguous logical row range backed by a tensor.
74#[derive(Debug, Clone, Serialize, Deserialize)]
75pub struct TableShard {
76    /// First row in the logical table.
77    pub first_row: u64,
78    /// Number of rows in this shard.
79    pub rows: u64,
80    /// Backing tensor in the enclosing model description.
81    pub tensor: TensorId,
82}
83
84#[cfg(test)]
85#[path = "../../tests/unit/model/mod.rs"]
86mod tests;