Skip to main content

WeightStore

Struct WeightStore 

Source
pub struct WeightStore {
    pub weights: HashMap<ValueId, WeightRef>,
    /* private fields */
}
Expand description

A resolved set of initializer weights, keyed by the value they populate, plus the live memory maps backing any external data files.

Fields§

§weights: HashMap<ValueId, WeightRef>

IR weight descriptors, keyed by the graph value they initialize.

Implementations§

Source§

impl WeightStore

Source

pub fn mapped_external_bytes(&self) -> u64

Total bytes of external-data file currently mapped by this store.

This is file size, which is only an upper bound on the weights the graph references — see ReferencedWeightBytes. Compare the two with Self::unreferenced_external_bytes rather than treating either alone as “how big is this model”.

Source

pub fn unreferenced_external_bytes( &self, referenced: &ReferencedWeightBytes, ) -> u64

Mapped external bytes that no initializer points at.

Nonzero means the blob carries dead weight — most commonly an orphaned prefix left by a re-export that appended fresh tensors without truncating the original. It is worth surfacing because nothing fails when it happens: the model loads and produces byte-identical output, so the only symptom is a file twice the size it should be. qwen14b-zp carried 8.32 GB of it (50.02% of the blob), which cost double the disk, double the page-locked host RAM on the memory-mapped weight path, and — before #856 — a weight budget derived from file length that was wrong by exactly 2.00x (#853).

Saturates at zero: a store may legitimately map a file whose declared lengths exceed what is mapped (a truncated or shared blob), and that is a different failure with its own error path.

Source§

impl WeightStore

Source

pub fn new() -> Self

An empty store.

Source

pub fn map_external( &mut self, path: impl AsRef<Path>, ) -> Result<(), LoaderError>

Memory-map an external-data file and register it under path, so any WeightRef::External whose path matches resolves zero-copy via bytes. Idempotent: mapping the same path twice is a no-op. This is the programmatic counterpart to the loader path (which maps files while resolving TensorProto initializers), useful when constructing a store by hand.

The map is read-only and kept alive for the store’s lifetime; callers must not mutate or unlink the file while the store is live.

Source

pub fn bytes<'a>(&'a self, weight: &'a WeightRef) -> Option<&'a [u8]>

Resolve a weight descriptor to its raw little-endian bytes.

For inline weights this borrows the stored bytes; for external weights it slices into the memory-mapped file. Returns None if an external mapping is missing or the [offset, offset+length) window is out of bounds.

Source

pub fn external_mmap_provenance( &self, weight: &WeightRef, ) -> Option<(usize, usize, usize)>

Return stable mmap identity and the validated absolute tensor range.

Source

pub fn mmap_region_bytes( &self, mapping_id: usize, offset: usize, len: usize, ) -> Option<&[u8]>

Resolve a validated external-data region by stable mmap id.

Lazy device weight paging carries this id instead of a path so the hot page-in path can copy directly from the live mmap. That prevents the WDDM offload failure mode where every page-in first rebuilt an owned host tensor and spent most of decode time in redundant CPU materialization.

Source

pub fn mmap_full_bytes(&self, mapping_id: usize) -> Option<&[u8]>

Return the whole live mmap backing mapping_id.

The zero-copy hybrid (#864) registers an entire mapping once with cuMemHostRegister(READ_ONLY | DEVICEMAP) so that every weight’s device pointer (from cuMemHostGetDevicePointer) is contiguous for its full length — a per-weight registration would only be contiguous up to the registration boundary, so a weight spanning two registrations would read past valid device addresses.

Trait Implementations§

Source§

impl Debug for WeightStore

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WeightStore

Source§

fn default() -> WeightStore

Returns the “default value” for a type. 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, 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.