pub struct HfTranslatingLoader<L: WeightLoader> { /* private fields */ }Expand description
Adapter that lets a HF-safetensors-backed WeightLoader satisfy
requests phrased in GGUF-style names (blk.N.attn_q.weight etc.).
Builders like [Qwen35Weights::from_loader] address tensors using
the GGUF / llama.cpp convention; the underlying safetensors file
stores them under HF / PyTorch names (model.layers.N.self_attn.q_proj.weight).
This wrapper:
- Tries the requested key verbatim (in case it’s already-HF or the file was named GGUF-style).
- Tries
gguf_to_hf_nameto translate the GGUF key → HF key. - Returns the underlying loader’s error otherwise.
Implementations§
Source§impl<L: WeightLoader> HfTranslatingLoader<L>
impl<L: WeightLoader> HfTranslatingLoader<L>
Trait Implementations§
Source§impl<L: WeightLoader> WeightLoader for HfTranslatingLoader<L>
impl<L: WeightLoader> WeightLoader for HfTranslatingLoader<L>
Source§fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
fn take(&mut self, key: &str) -> Result<(Vec<f32>, Vec<usize>)>
Take the named tensor as
(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>)>
Same as
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 take_packed(&mut self, key: &str) -> Result<Option<PackedWeightTensor>>
fn take_packed(&mut self, key: &str) -> Result<Option<PackedWeightTensor>>
Take packed K-quant bytes when supported; default returns
None.Source§fn tensor_bytes_borrowed(&self, key: &str) -> Option<&[u8]>
fn tensor_bytes_borrowed(&self, key: &str) -> Option<&[u8]>
Borrow packed bytes without marking taken (GGUF mmap path).
Source§fn remaining_keys(&self) -> Vec<String>
fn remaining_keys(&self) -> Vec<String>
Names that haven’t been taken yet — useful for “did the
model use every weight?” hygiene checks.
fn is_empty(&self) -> bool
Source§fn arch_hint(&self) -> Option<&str>
fn arch_hint(&self) -> Option<&str>
Architecture name from the underlying file (
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<L> Freeze for HfTranslatingLoader<L>where
L: Freeze,
impl<L> RefUnwindSafe for HfTranslatingLoader<L>where
L: RefUnwindSafe,
impl<L> Send for HfTranslatingLoader<L>
impl<L> Sync for HfTranslatingLoader<L>where
L: Sync,
impl<L> Unpin for HfTranslatingLoader<L>where
L: Unpin,
impl<L> UnsafeUnpin for HfTranslatingLoader<L>where
L: UnsafeUnpin,
impl<L> UnwindSafe for HfTranslatingLoader<L>where
L: UnwindSafe,
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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