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
impl WeightStore
Sourcepub fn mapped_external_bytes(&self) -> u64
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”.
Sourcepub fn unreferenced_external_bytes(
&self,
referenced: &ReferencedWeightBytes,
) -> u64
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
impl WeightStore
Sourcepub fn map_external(
&mut self,
path: impl AsRef<Path>,
) -> Result<(), LoaderError>
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.
Sourcepub fn bytes<'a>(&'a self, weight: &'a WeightRef) -> Option<&'a [u8]>
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.
Sourcepub fn external_mmap_provenance(
&self,
weight: &WeightRef,
) -> Option<(usize, usize, usize)>
pub fn external_mmap_provenance( &self, weight: &WeightRef, ) -> Option<(usize, usize, usize)>
Return stable mmap identity and the validated absolute tensor range.
Sourcepub fn mmap_region_bytes(
&self,
mapping_id: usize,
offset: usize,
len: usize,
) -> Option<&[u8]>
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.
Sourcepub fn mmap_full_bytes(&self, mapping_id: usize) -> Option<&[u8]>
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.