WeightStore

Struct WeightStore 

Source
pub struct WeightStore { /* private fields */ }
Expand description

All model weights loaded onto the GPU, keyed by HuggingFace name.

Implementations§

Source§

impl WeightStore

Source

pub fn empty() -> Self

Create an empty weight store (for testing).

Source

pub fn defer(&mut self, name: String, t: DeferredTensor)

Record a tensor that was skipped at load, with its on-disk location.

Source

pub fn deferred(&self, name: &str) -> Option<&DeferredTensor>

Look up a deferred (not-uploaded) tensor’s on-disk location.

Source

pub fn deferred_sorted(&self) -> Vec<(&String, &DeferredTensor)>

Every deferred tensor, name-sorted (NUMERIC on a trailing index, so embedders.10 sorts after embedders.2 — a lexicographic sort here silently mis-maps the n-gram tables, which cost a real debugging session the first time).

Source

pub fn from_map(weights: HashMap<String, WeightTensor>) -> Self

Wrap a pre-built map. Used by alternate loaders (e.g. fast_weights::FastSafetensorsLoader, and the RDMA weight loader in spark-storage, which lives in a different crate and so needs this pub).

Source

pub fn get(&self, name: &str) -> Result<&WeightTensor>

Get a weight tensor by name. Fails fast if not found.

Source

pub fn contains(&self, name: &str) -> bool

Check if a weight exists.

Source

pub fn len(&self) -> usize

Number of loaded weights.

Source

pub fn is_empty(&self) -> bool

True if no weights are loaded.

Source

pub fn resident_bytes(&self) -> usize

Device bytes the store still holds. Not the on-disk load estimate: this shrinks as free_matching drops tensors the binders replaced.

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Iterator over all weight names.

Source

pub fn free_matching( &mut self, gpu: &dyn GpuBackend, pred: impl Fn(&str) -> bool, ) -> Result<(usize, usize)>

Free and forget every tensor whose name matches pred. Returns (tensors freed, bytes freed).

For loaders that do NOT bind zero-copy from the store’s device pointers: they upload their own copy, so the original is dead weight the moment the binder returns, and on a unified-memory GB10 that duplicate is the difference between fitting a KV cache and not.

🪤 The caller owns the “is it dead?” question. A tensor bound zero-copy (every routed expert, and the fused per-expert views in weight_loader/step3p7.rs) is still live in a layer struct — freeing it here is a use-after-free with no diagnostic. Match narrowly.

Per-entry free is sound for the same reason release gives below: the loaders allocate one gpu.alloc per tensor, and no loader inserts an .offset() view of a shared block into this map.

Source

pub fn total_bytes(&self) -> usize

Total bytes across all weight tensors on the GPU.

Source

pub fn has_fp8_weights(&self) -> bool

Check if any tensor has FP8 dtype.

Source

pub fn fp8_kv_scale_count(&self) -> usize

Number of per-layer FP8 KV-cache scale tensors (*.k_scale) the checkpoint ships. >0 means the model carries calibrated KV scales, so FP8 KV needs no online calibration; 0 means the scales default to 1.0 (which clips BF16 into E4M3 range), so online calibration or a non-FP8 KV dtype is required. Used to log the right guidance at serve time.

Trait Implementations§

Source§

impl ModelResource<dyn GpuBackend> for WeightStore

Release every weight tensor.

Safe to free per-entry because the loaders allocate per-tensor: the fast path calls gpu.alloc(meta.len) once per tensor before inserting it (fast_weights/mod.rs:360-388), and no loader inserts an .offset() view of a shared block into this map. (Fused per-expert views DO exist — see weight_loader/step3p7.rs:93 — but they live in the layer structs that own the fused allocation, not here, so this cannot double-free them.)

Source§

fn label(&self) -> &'static str

Human name, for the teardown report and for attributing a failure.
Source§

fn release(&mut self, gpu: &dyn GpuBackend) -> Result<()>

Release everything this owns. Must be idempotent: the host calls it, and a Drop backstop may call it again.

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.

§

impl<T> Instrument for T

§

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

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

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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