pub struct SafetensorsReader { /* private fields */ }Expand description
Safe streaming safetensors reader that parses headers once and seeks to load
individual tensors or 3D dimension-0 slices on demand using zero unsafe code.
Implementations§
Source§impl SafetensorsReader
impl SafetensorsReader
Sourcepub fn open(dir: &Path) -> Result<Self>
pub fn open(dir: &Path) -> Result<Self>
Open a local single-file or sharded safetensors checkpoint directory.
§Errors
Returns LittleBitError::CheckpointNotFound if no safetensors checkpoint exists in dir,
or I/O/header parsing errors.
Sourcepub fn tensor_names(&self) -> impl Iterator<Item = &str>
pub fn tensor_names(&self) -> impl Iterator<Item = &str>
Iterate over all tensor keys across all shards in deterministic lexicographical order.
Sourcepub fn tensor_info(&self, name: &str) -> Option<&TensorLocation>
pub fn tensor_info(&self, name: &str) -> Option<&TensorLocation>
Return location & shape metadata for name without reading tensor bytes from disk.
Sourcepub fn load_tensor(&mut self, name: &str, device: &Device) -> Result<Tensor>
pub fn load_tensor(&mut self, name: &str, device: &Device) -> Result<Tensor>
Read and materialize a single tensor name onto device.
§Errors
Returns LittleBitError::MissingTensor if absent or I/O/decoding errors.
Sourcepub fn load_tensor_slice_dim0(
&mut self,
name: &str,
index: usize,
device: &Device,
) -> Result<Tensor>
pub fn load_tensor_slice_dim0( &mut self, name: &str, index: usize, device: &Device, ) -> Result<Tensor>
Stream only tensor[index] along dimension 0 without reading the rest of the tensor
into memory (enabling single-expert loading from fused 3D MoE weights).
§Errors
Returns an error if name is missing, rank < 2, index is out of bounds, or reading fails.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SafetensorsReader
impl RefUnwindSafe for SafetensorsReader
impl Send for SafetensorsReader
impl Sync for SafetensorsReader
impl Unpin for SafetensorsReader
impl UnsafeUnpin for SafetensorsReader
impl UnwindSafe for SafetensorsReader
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T, U> Imply<T> for U
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> ⓘ
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> ⓘ
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