pub struct ModelLoader { /* private fields */ }Expand description
Weight loader for safetensors format
Implementations§
Source§impl ModelLoader
impl ModelLoader
Sourcepub fn new<P: AsRef<Path>>(path: P) -> ModelResult<Self>
pub fn new<P: AsRef<Path>>(path: P) -> ModelResult<Self>
Load a safetensors file from disk
Sourcepub fn from_bytes(data: Vec<u8>) -> ModelResult<Self>
pub fn from_bytes(data: Vec<u8>) -> ModelResult<Self>
Load a safetensors from bytes
Sourcepub fn list_tensors(&self) -> Vec<String>
pub fn list_tensors(&self) -> Vec<String>
List all available tensor names in the file
Sourcepub fn tensor_info(&self, name: &str) -> Option<TensorInfo>
pub fn tensor_info(&self, name: &str) -> Option<TensorInfo>
Get metadata about a specific tensor
Sourcepub fn load_array1(&self, name: &str) -> ModelResult<Array1<f32>>
pub fn load_array1(&self, name: &str) -> ModelResult<Array1<f32>>
Load a 1D tensor (Array1
Sourcepub fn load_array2(&self, name: &str) -> ModelResult<Array2<f32>>
pub fn load_array2(&self, name: &str) -> ModelResult<Array2<f32>>
Load a 2D tensor (Array2
Sourcepub fn load_array(&self, name: &str) -> ModelResult<ArrayD<f32>>
pub fn load_array(&self, name: &str) -> ModelResult<ArrayD<f32>>
Load a tensor of arbitrary dimension
Sourcepub fn load_array3(&self, name: &str) -> ModelResult<Vec<Vec<Vec<f32>>>>
pub fn load_array3(&self, name: &str) -> ModelResult<Vec<Vec<Vec<f32>>>>
Load a 3D tensor as Vec<Vec<Vec
This is useful for convolution weights [out_channels, in_channels, kernel_size]
Sourcepub fn has_tensor(&self, name: &str) -> bool
pub fn has_tensor(&self, name: &str) -> bool
Check if a tensor exists
Sourcepub fn load_all(&self) -> ModelResult<HashMap<String, ArrayD<f32>>>
pub fn load_all(&self) -> ModelResult<HashMap<String, ArrayD<f32>>>
Load all tensors into a HashMap
Sourcepub fn print_summary(&self)
pub fn print_summary(&self)
Print a summary of all tensors in the file
This is useful for inspecting checkpoint files and understanding their structure
Sourcepub fn get_size_stats(&self) -> HashMap<String, usize>
pub fn get_size_stats(&self) -> HashMap<String, usize>
Get statistics about tensor sizes
Auto Trait Implementations§
impl Freeze for ModelLoader
impl RefUnwindSafe for ModelLoader
impl Send for ModelLoader
impl Sync for ModelLoader
impl Unpin for ModelLoader
impl UnwindSafe for ModelLoader
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