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