pub struct WeightMap { /* private fields */ }Expand description
Map of tensor name → (f32 data, shape).
Implementations§
Source§impl WeightMap
impl WeightMap
Sourcepub fn from_weight_loader(loader: &mut dyn WeightLoader) -> Result<Self>
pub fn from_weight_loader(loader: &mut dyn WeightLoader) -> Result<Self>
Drain every tensor from any WeightLoader (safetensors or GGUF).
Sourcepub fn from_weight_loader_dequant_all(
loader: &mut dyn WeightLoader,
) -> Result<Self>
pub fn from_weight_loader_dequant_all( loader: &mut dyn WeightLoader, ) -> Result<Self>
Force-dequantize every tensor (including K-quants) into F32 and
drop it in the map. Use when a family runner doesn’t have a
packed-matmul lowering yet but still wants to load GGUFs whose
trunk weights are K-quant. Trades memory (4× larger than the
packed bytes) for correctness — every tensor goes through
WeightLoader::take(...) which dequantizes on the fly.
Sourcepub fn drain_loader(
loader: &mut dyn WeightLoader,
policy: WeightDrainPolicy,
) -> Result<(Self, Vec<NamedPackedWeight>)>
pub fn drain_loader( loader: &mut dyn WeightLoader, policy: WeightDrainPolicy, ) -> Result<(Self, Vec<NamedPackedWeight>)>
Drain with policy; returns packed K-quants separately when the loader supports take_packed.
Sourcepub fn from_resolved_path(path: &Path) -> Result<Self>
pub fn from_resolved_path(path: &Path) -> Result<Self>
Resolve a file or weights directory, then load (safetensors or GGUF).
Sourcepub fn from_resolved_safetensors_only(path: &Path, runner: &str) -> Result<Self>
pub fn from_resolved_safetensors_only(path: &Path, runner: &str) -> Result<Self>
Resolve path; reject .gguf with a hint naming the right runner.
Sourcepub fn from_file(path: &str) -> Result<Self>
pub fn from_file(path: &str) -> Result<Self>
Load weights from a safetensors file. Auto-converts bf16/f16 to f32.
Sourcepub fn from_file_excluding(
path: &str,
exclude: &HashSet<String>,
) -> Result<Self>
pub fn from_file_excluding( path: &str, exclude: &HashSet<String>, ) -> Result<Self>
Load weights, skipping tensor names present in exclude (saves RAM when
bf16/NVFP4 linears are loaded separately for GPU upload).
Sourcepub fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
pub fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
Take a tensor by name (removes from map). Returns (data, shape).
Sourcepub fn take_transposed(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
pub fn take_transposed(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
Take and transpose a 2D weight: [out, in] → [in, out] for row-major matmul.
pub fn is_empty(&self) -> bool
Sourcepub fn from_tensors(tensors: HashMap<String, (Vec<f32>, Vec<usize>)>) -> Self
pub fn from_tensors(tensors: HashMap<String, (Vec<f32>, Vec<usize>)>) -> Self
Create from pre-built HashMap (for testing without safetensors files).
Sourcepub fn snapshot_from_path(path: &str) -> Result<F32WeightSnapshot>
pub fn snapshot_from_path(path: &str) -> Result<F32WeightSnapshot>
Drain all tensors into a snapshot map (for runners that rebuild graphs per shape).
Sourcepub fn from_safetensors_dir_selected(
dir: &Path,
want: &HashSet<String>,
) -> Result<Self>
pub fn from_safetensors_dir_selected( dir: &Path, want: &HashSet<String>, ) -> Result<Self>
Load only tensors whose names appear in want (HF sharded checkpoints).
Sourcepub fn from_safetensors_dir(dir: &Path) -> Result<Self>
pub fn from_safetensors_dir(dir: &Path) -> Result<Self>
Load and merge every *.safetensors file in dir (e.g. HF text_encoder/).
Sourcepub fn remap_keys<F>(&mut self, f: F)
pub fn remap_keys<F>(&mut self, f: F)
Rename keys in-place (e.g. strip model. HuggingFace prefix).
Trait Implementations§
Source§impl WeightLoader for WeightMap
impl WeightLoader for WeightMap
Source§fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
(f32_data, shape). Removes from the
loader so callers can detect “weights I never used.”Source§fn take_transposed(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
fn take_transposed(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
take but transposed (last two dims swapped). Most
safetensors weights are stored row-major-of-PyTorch
convention, which RLX’s IR consumes column-major; this helper
is the convention-bridge.Source§fn remaining_keys(&self) -> Vec<String>
fn remaining_keys(&self) -> Vec<String>
fn is_empty(&self) -> bool
Source§fn take_packed(&mut self, key: &str) -> Result<Option<PackedWeightTensor>>
fn take_packed(&mut self, key: &str) -> Result<Option<PackedWeightTensor>>
None.Source§fn tensor_bytes_borrowed(&self, key: &str) -> Option<&[u8]>
fn tensor_bytes_borrowed(&self, key: &str) -> Option<&[u8]>
Source§fn arch_hint(&self) -> Option<&str>
fn arch_hint(&self) -> Option<&str>
general.architecture
for GGUF, None for safetensors). Drain-style consumers use this
to pick an arch-specific reverse name mapping when the canonical
HF name depends on the model family (e.g. Gemma 2’s 4 norms per
layer don’t share the Llama 2-norm reverse alias).Auto Trait Implementations§
impl Freeze for WeightMap
impl RefUnwindSafe for WeightMap
impl Send for WeightMap
impl Sync for WeightMap
impl Unpin for WeightMap
impl UnsafeUnpin for WeightMap
impl UnwindSafe for WeightMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more