pub struct SafeTensorsSource { /* private fields */ }Expand description
WeightSource backed by a .safetensors file.
The JSON header is parsed once at construction time; subsequent calls to
load_tensor seek directly to each tensor’s
data region and convert it to f32.
Implementations§
Source§impl SafeTensorsSource
impl SafeTensorsSource
Sourcepub fn open(path: &Path) -> ModelResult<Self>
pub fn open(path: &Path) -> ModelResult<Self>
Open a .safetensors file and parse its JSON header.
The binary layout is:
[0..8] header_size — u64 LE: length of the JSON string
[8..8+header_size] JSON header — tensor metadata
[8+header_size..] raw data — tensor bytes, BF16/F16/F32Trait Implementations§
Source§impl WeightSource for SafeTensorsSource
impl WeightSource for SafeTensorsSource
Source§fn tensor_names(&self) -> Vec<String>
fn tensor_names(&self) -> Vec<String>
Return the names of all tensors available in this source.
Source§fn load_tensor(&mut self, name: &str) -> ModelResult<Vec<f32>>
fn load_tensor(&mut self, name: &str) -> ModelResult<Vec<f32>>
Source§fn contains(&self, name: &str) -> bool
fn contains(&self, name: &str) -> bool
Return
true if the source contains a tensor with the given name.Source§fn total_bytes_estimate(&self) -> u64
fn total_bytes_estimate(&self) -> u64
Return a rough estimate of the total number of bytes occupied by all
tensor data in the underlying file (used for progress reporting).
Auto Trait Implementations§
impl Freeze for SafeTensorsSource
impl RefUnwindSafe for SafeTensorsSource
impl Send for SafeTensorsSource
impl Sync for SafeTensorsSource
impl Unpin for SafeTensorsSource
impl UnsafeUnpin for SafeTensorsSource
impl UnwindSafe for SafeTensorsSource
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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