Skip to main content

Store

Struct Store 

Source
pub struct Store { /* private fields */ }
Expand description

Every tensor of the bundle. On Unix tensors.bin is memory-mapped read-only: a tensor’s pages are read when it is first touched and stay reclaimable page cache, so loading a multi-GB bundle costs no heap and a runtime that uploads its weights and drops the store never holds them twice. Elsewhere (or if mapping fails) the file is read into a u64 buffer. Either way the 64-byte-aligned offsets tensors.txt records are aligned in memory (mappings are page-aligned), so the typed views below are sound. Don’t rewrite a bundle’s tensors.bin while a runtime has it loaded: exporters write new directories.

Implementations§

Source§

impl Store

Source

pub fn load(dir: &Path) -> Result<Self, Error>

Source

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

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Source

pub fn entry(&self, name: &str) -> Result<&Entry, Error>

Source

pub fn shape(&self, name: &str) -> Result<&[usize], Error>

Source

pub fn expect( &self, name: &str, dtype: DType, elems: usize, ) -> Result<&Entry, Error>

name’s entry, checked to be dtype with elems elements.

Source

pub fn bytes(&self, name: &str) -> Result<&[u8], Error>

Any tensor’s raw bytes.

Source

pub fn f32(&self, name: &str) -> Result<&[f32], Error>

Source

pub fn bf16(&self, name: &str) -> Result<&[u16], Error>

bf16 as raw bits.

Source

pub fn u8(&self, name: &str) -> Result<&[u8], Error>

Source

pub fn i32(&self, name: &str) -> Result<&[i32], Error>

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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