Skip to main content

CmfStreamWriter

Struct CmfStreamWriter 

Source
pub struct CmfStreamWriter { /* private fields */ }

Implementations§

Source§

impl CmfStreamWriter

Source

pub fn head_reserve_for(n_tensors: usize, avg_name: usize) -> u64

A gap that comfortably holds the head for n_tensors whose names run to avg_name bytes: the directory’s fixed records, the name pool, the envelope, and a header JSON with room for arch metadata — then doubled, because being wrong here costs a whole re-run.

Source

pub fn new(path: impl AsRef<Path>, gap: u64) -> Result<Self, CmfError>

gap bytes are reserved for envelope + header + directory.

Source

pub fn push( &mut self, name: &str, dtype: TensorDtype, shape: &[usize], data: &[u8], ) -> Result<(), CmfError>

Append one tensor. The payload is consumed here, so the caller can drop it immediately — that is the entire point of this writer.

Source

pub fn push_bounded( &mut self, name: &str, dtype: TensorDtype, shape: &[usize], data: &[u8], chunk_bytes: usize, ) -> Result<(), CmfError>

Append one tensor while limiting each write syscall to chunk_bytes.

The source is normally an mmap, so this does not change the caller’s memory residency. It does make the bounded-copy contract explicit for very large auxiliary tensors (DeepSeek-V4.1’s native Engram tables are hundreds of gigabytes): the writer never asks an I/O layer to stage the whole payload as one buffer. Hashing remains one streaming pass over the borrowed bytes, and the directory entry is identical to Self::push.

Source

pub fn with_manifest(self, path: impl AsRef<Path>) -> Result<Self, CmfError>

Start recording a sidecar manifest at path. One JSON line per tensor, flushed as it goes, plus a first line pinning the gap size.

Source

pub fn appending_manifest( self, path: impl AsRef<Path>, ) -> Result<Self, CmfError>

Keep recording into an existing manifest — for a writer from CmfStreamWriter::resume, whose earlier lines must survive.

Source

pub fn resume( path: impl AsRef<Path>, manifest: impl AsRef<Path>, ) -> Result<(Self, ResumeState), CmfError>

Rebuild a writer over an output file whose payloads are already on disk, from the manifest that recorded them. The file is reopened for writing without truncation and the cursor is placed after the last recorded tensor, so finish can complete a conversion that died.

Source

pub fn mark(&mut self, note: &str) -> Result<(), CmfError>

Note a milestone in the manifest — a source shard fully consumed, say. Resume reads these back, which is what lets a restart skip work whose payloads are already in the file rather than only skipping tensors it happens to recognise by name.

Source

pub fn tensor_count(&self) -> usize

Source

pub fn data_len(&self) -> u64

Bytes of weight blob written so far.

Source

pub fn finish( self, header: &CmfHeader, masks: Option<&MaskCatalog>, vocab: Option<&[u8]>, ) -> Result<(), CmfError>

Write the trailing sections, then patch the head into the reserved gap.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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