Struct safetensors::tensor::SafeTensors
source · pub struct SafeTensors<'data> { /* private fields */ }
Expand description
A structure owning some metadata to lookup tensors on a shared data
byte-buffer (not owned).
Implementations§
source§impl<'data> SafeTensors<'data>
impl<'data> SafeTensors<'data>
sourcepub fn read_metadata<'in_data>(
buffer: &'in_data [u8]
) -> Result<(usize, Metadata), SafeTensorError>where
'in_data: 'data,
pub fn read_metadata<'in_data>( buffer: &'in_data [u8] ) -> Result<(usize, Metadata), SafeTensorError>where 'in_data: 'data,
Given a byte-buffer representing the whole safetensor file parses the header, and returns the size of the header + the parsed data.
sourcepub fn deserialize<'in_data>(
buffer: &'in_data [u8]
) -> Result<Self, SafeTensorError>where
'in_data: 'data,
pub fn deserialize<'in_data>( buffer: &'in_data [u8] ) -> Result<Self, SafeTensorError>where 'in_data: 'data,
Given a byte-buffer representing the whole safetensor file parses it and returns the Deserialized form (No Tensor allocation).
sourcepub fn tensors(&self) -> Vec<(String, TensorView<'_>)>
pub fn tensors(&self) -> Vec<(String, TensorView<'_>)>
Allow the user to iterate over tensors within the SafeTensors. The tensors returned are merely views and the data is not owned by this structure.
sourcepub fn tensor(
&self,
tensor_name: &str
) -> Result<TensorView<'_>, SafeTensorError>
pub fn tensor( &self, tensor_name: &str ) -> Result<TensorView<'_>, SafeTensorError>
Allow the user to get a specific tensor within the SafeTensors. The tensor returned is merely a view and the data is not owned by this structure.