Skip to main content

CmfModel

Struct CmfModel 

Source
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

Source

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.

Source

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.

Source

pub fn arch(&self) -> &ModelArch

Source

pub fn tensor(&self, name: &str) -> Option<&TensorEntry>

Source

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.

Source

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.

Source

pub fn tensor_bytes(&self, name: &str) -> Result<&[u8], CmfError>

Zero-copy bytes of a tensor from the mmap’d data section.

Source

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).

Source

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).

Source

pub fn entry_bytes(&self, entry: &TensorEntry) -> &[u8]

Source

pub fn layer_tensors(&self, layer_idx: usize) -> Vec<&TensorEntry>

Tensors belonging to layer i (prefix model.layers.{i}.).

Source

pub fn total_param_count(&self) -> u64

Total parameter count estimated from matrix tensors (ndim ≥ 2).

Source

pub fn verify(&self) -> Vec<String>

Recompute all tensor hashes; returns human-readable problems (empty = file intact).

Source

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).

Source

pub fn write( path: impl AsRef<Path>, header: &CmfHeader, tensors: &[TensorSpec], masks: Option<&MaskCatalog>, vocab: Option<&[u8]>, ) -> Result<(), CmfError>

Write a CMF v2 file. Offsets, alignment, hashes and the sparse index are computed here — the caller supplies content only.

Trait Implementations§

Source§

impl Debug for CmfModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more