Skip to main content

WeightBytes

Enum WeightBytes 

Source
pub enum WeightBytes {
    Owned(Vec<u8>),
    Mapped {
        mmap: Arc<Mmap>,
        range: Range<usize>,
    },
    Shared {
        buf: Arc<Vec<u8>>,
        range: Range<usize>,
    },
}
Expand description

Backing storage for a quantized weight matrix’s raw bytes: either an owned buffer (synthetic/test weights, or any tensor that had to be copied for some other reason) or a zero-copy view into a shared memory-mapped GGUF file. This is the fix for the “loader read everything into a fresh Vec” inefficiency: a real checkpoint’s resident memory should be the mmap itself, not a second copy of it, which is how llama.cpp’s mmap-based loader both avoid doubling a multi-hundred-gigabyte checkpoint’s memory footprint.

Variants§

§

Owned(Vec<u8>)

§

Mapped

Fields

§mmap: Arc<Mmap>
§range: Range<usize>
§

Shared

A sub-range of a shared, lease-style buffer (e.g. one matrix inside an ferrox_core::expert_store::ExpertLease’s combined gate/up/down bytes). Holding the Arc here is exactly what makes the store’s lease pinning structural: as long as any WeightMatrix built over these bytes is alive, the cache entry’s strong count stays >1 and eviction cannot reuse it.

Fields

§buf: Arc<Vec<u8>>
§range: Range<usize>

Implementations§

Source§

impl WeightBytes

Source

pub fn as_slice(&self) -> &[u8]

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn map_id(&self) -> Option<MapId>

The identity a repack cache may key on, or None for bytes that must never be cached by address.

This replaces an address_is_stable() -> bool, and the boolean was the bug: a yes/no answer cannot say whether the mapping that made the address meaningful is still alive, so the cache went on trusting an address after the mapping behind it was gone. See MapId for the ABA that produces and how the Weak closes it.

Shared stays None, and for a different reason that a Weak would NOT fix: it is a lease over an expert store’s recycled buffer, so the allocation stays alive and keeps its address while its CONTENTS are replaced by another expert’s. Identity is stable there and still means nothing. That produced fluent garbage on OLMoE with expert streaming on, while the raw weight bytes compared equal, because the corruption was in the CACHE and not in the weights.

Owned stays None too: a freed Vec’s address is reused, and nothing holds a handle that could witness the free.

Source

pub fn is_mapped(&self) -> bool

True if this is a zero-copy mmap view rather than an owned heap allocation – useful for tests/diagnostics asserting that the loader actually took the zero-copy path.

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.

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

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.