SafetensorsLoader

Struct SafetensorsLoader 

Source
pub struct SafetensorsLoader {
    pub ep_rank: usize,
    pub ep_world_size: usize,
    pub num_experts: usize,
    pub peak_memory_multiplier: Option<f64>,
    pub skip_activation_scales: bool,
    pub skip_mtp: bool,
}
Expand description

Loads weights from safetensors files using mmap.

Fields§

§ep_rank: usize

EP rank (0-based). Only used when ep_world_size > 1.

§ep_world_size: usize

EP world size. When > 1, remote expert tensors are skipped.

§num_experts: usize

Total number of MoE experts in the model (for EP partitioning).

§peak_memory_multiplier: Option<f64>

Override for the peak memory multiplier in the pre-flight OOM check. Set from QuantFormat::peak_memory_multiplier() in the caller. When None, the pre-flight uses its own heuristic (1.3x NVFP4 / 1.5x FP8).

§skip_activation_scales: bool

Skip the W4A4 *.input_scale activation scales at load.

ModelOpt NVFP4 checkpoints ship one 0-dim F32 scalar per quantized projection. On a 512-expert model that is ~74k four-byte allocations, each taking a full allocation granule — GBs of padding for values Atlas never reads, because it serves w4a16 (BF16 activations) and the NVFP4 loader already treats the key as optional.

OPT-IN: step3p7 reads this key on its own path, so it must stay off unless the model’s loader is known not to need it.

§skip_mtp: bool

Skip mtp.* tensors at load.

For models whose loader deliberately does not build an MTP head, uploading its weights is pure waste — on Qwen3.8-Flash-Next that is a 1.49 GB expert shard plus the MTP backbone, held resident while the KV cache goes without.

OPT-IN: a model that DOES build an MTP head must keep them, so this is set only where load_mtp_weights is known to return None.

Implementations§

Source§

impl SafetensorsLoader

Source

pub fn new() -> Self

Create a loader with no expert parallelism (loads all tensors).

Source

pub fn with_ep(ep_rank: usize, ep_world_size: usize, num_experts: usize) -> Self

Create a loader with EP-aware filtering.

Source

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

Check if a tensor should be skipped under EP. Skips *.experts.{E}.* tensors where E is not in local range. MTP head experts are never skipped (small, fully replicated).

🪤 The MTP exemption keys on a leading mtp. — a DeepSeek-style name. GLM-5.3 puts its MTP head at model.language_model.layers.45.* with no mtp. prefix, so that layer’s routed experts ARE sharded on GLM. Fine while the MTP head is out of scope; revisit before enabling it.

pub so residency can be PROVEN against a real checkpoint index without collectives (see spark-model/tests/glm53_ep_residency.rs).

Trait Implementations§

Source§

impl Default for SafetensorsLoader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl WeightLoader for SafetensorsLoader

Source§

fn load( &self, model_dir: &Path, gpu: &dyn GpuBackend, oom_reserve_bytes: usize, ) -> Result<WeightStore>

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