pub struct SafetensorsFile { /* private fields */ }Expand description
A memory-mapped safetensors file ready for tensor extraction.
This struct owns the mmap and parsed header. Individual tensors can be
loaded into Metal buffers on demand via load_tensor
or all at once via load_all_tensors.
Implementations§
Source§impl SafetensorsFile
impl SafetensorsFile
Sourcepub fn open(path: &Path) -> Result<Self>
pub fn open(path: &Path) -> Result<Self>
Open and memory-map a safetensors file.
The file is mapped read-only. No tensor data is copied until
load_tensor or load_all_tensors is called.
§Errors
MlxError::IoErrorif the file cannot be opened or mapped.
Sourcepub fn tensor_names(&self) -> Result<Vec<String>>
pub fn tensor_names(&self) -> Result<Vec<String>>
List all tensor names in the file.
Sourcepub fn load_tensor(
&self,
name: &str,
device: &MlxDevice,
) -> Result<(DType, Vec<usize>, MlxBuffer)>
pub fn load_tensor( &self, name: &str, device: &MlxDevice, ) -> Result<(DType, Vec<usize>, MlxBuffer)>
Load a single named tensor into a Metal buffer.
Returns the dtype, shape, and a Metal buffer containing the raw bytes.
§Errors
MlxError::SafetensorsErrorif the tensor name is not found.MlxError::UnsupportedDtypeif the tensor’s dtype is not supported.MlxError::BufferAllocationErrorif Metal allocation fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SafetensorsFile
impl RefUnwindSafe for SafetensorsFile
impl Send for SafetensorsFile
impl Sync for SafetensorsFile
impl Unpin for SafetensorsFile
impl UnsafeUnpin for SafetensorsFile
impl UnwindSafe for SafetensorsFile
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