Skip to main content

HfTranslatingLoader

Struct HfTranslatingLoader 

Source
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:

  1. Tries the requested key verbatim (in case it’s already-HF or the file was named GGUF-style).
  2. Tries gguf_to_hf_name to translate the GGUF key → HF key.
  3. Returns the underlying loader’s error otherwise.

Implementations§

Source§

impl<L: WeightLoader> HfTranslatingLoader<L>

Source

pub fn new(inner: L) -> Self

Source

pub fn into_inner(self) -> L

Source

pub fn inner(&self) -> &L

Source

pub fn inner_mut(&mut self) -> &mut L

Trait Implementations§

Source§

impl<L: WeightLoader> WeightLoader for HfTranslatingLoader<L>

Source§

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

Format id (safetensors, gguf, or a custom registration).
Source§

fn len(&self) -> usize

Number of distinct weights in the file.
Source§

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

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

Take packed K-quant bytes when supported; default returns None.
Source§

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>

Names that haven’t been taken yet — useful for “did the model use every weight?” hygiene checks.
Source§

fn is_empty(&self) -> bool

Source§

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

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.