pub struct CmfModel {
pub path: PathBuf,
pub header: CmfHeader,
pub required_features: u32,
pub tensors: Vec<TensorEntry>,
pub masks: MaskCatalog,
pub sparse_index: Vec<SparseIndexEntry>,
pub vocab: Option<Vec<u8>>,
/* private fields */
}Expand description
A loaded CMF model: metadata owned, weights zero-copy via mmap.
Fields§
§path: PathBuf§header: CmfHeader§required_features: u32§tensors: Vec<TensorEntry>§masks: MaskCatalog§sparse_index: Vec<SparseIndexEntry>§vocab: Option<Vec<u8>>Embedded tokenizer.json bytes, if present.
Implementations§
Source§impl CmfModel
impl CmfModel
Sourcepub fn open(path: impl AsRef<Path>) -> Result<Self, CmfError>
pub fn open(path: impl AsRef<Path>) -> Result<Self, CmfError>
Open and strictly validate a CMF v2 file. Any inconsistency is an error — this function never substitutes defaults.
Sourcepub fn open_sharded(path: impl AsRef<Path>) -> Result<Self, CmfError>
pub fn open_sharded(path: impl AsRef<Path>) -> Result<Self, CmfError>
Open a sharded model (spec §10): pass shard 1; siblings found by
the -{no:05}-of-{count:05}.cmf convention. Directories merge;
masks/vocab/index/skills come from shard 1.
pub fn arch(&self) -> &ModelArch
pub fn tensor(&self, name: &str) -> Option<&TensorEntry>
Sourcepub fn resolve_tensor(
&self,
name: &str,
skill: Option<&str>,
) -> Option<&TensorEntry>
pub fn resolve_tensor( &self, name: &str, skill: Option<&str>, ) -> Option<&TensorEntry>
Tensor-source indirection (spec §9, Patent 15 fig3/302): the skill’s replacement is read IN PLACE OF the backbone tensor — either/or, never combined. None skill → backbone directly.
Sourcepub fn skill_tensors(
&self,
skill_id: &str,
) -> impl Iterator<Item = &TensorEntry>
pub fn skill_tensors( &self, skill_id: &str, ) -> impl Iterator<Item = &TensorEntry>
The per-skill delta index view (claim 2): directory entries of one skill — exactly the byte ranges lazy loading pages in.
Sourcepub fn tensor_bytes(&self, name: &str) -> Result<&[u8], CmfError>
pub fn tensor_bytes(&self, name: &str) -> Result<&[u8], CmfError>
Zero-copy bytes of a tensor from the mmap’d data section.
Sourcepub fn primary_bytes(&self) -> &[u8] ⓘ
pub fn primary_bytes(&self) -> &[u8] ⓘ
All bytes of the primary mapping (GPU path: no-copy Metal buffer over the same mmap — unified memory, zero copying).
Sourcepub fn entry_abs_offset(&self, entry: &TensorEntry) -> Option<usize>
pub fn entry_abs_offset(&self, entry: &TensorEntry) -> Option<usize>
Absolute offset of the tensor within the primary mapping (None for tensors from sibling shards).
pub fn entry_bytes(&self, entry: &TensorEntry) -> &[u8] ⓘ
Sourcepub fn layer_tensors(&self, layer_idx: usize) -> Vec<&TensorEntry>
pub fn layer_tensors(&self, layer_idx: usize) -> Vec<&TensorEntry>
Tensors belonging to layer i (prefix model.layers.{i}.).
Sourcepub fn total_param_count(&self) -> u64
pub fn total_param_count(&self) -> u64
Total parameter count estimated from matrix tensors (ndim ≥ 2).
Sourcepub fn verify(&self) -> Vec<String>
pub fn verify(&self) -> Vec<String>
Recompute all tensor hashes; returns human-readable problems (empty = file intact).
Sourcepub fn compute_active_size(&self, mask: &TaskMask) -> u64
pub fn compute_active_size(&self, mask: &TaskMask) -> u64
Approximate active weight bytes under a mask, from real tensor sizes in the directory (not from a formula).