pub struct TensorReader<'a> { /* private fields */ }Expand description
A lazy view over one tensor’s raw bytes inside a ModelSource.
The byte slice borrows from the source (e.g. an mmap region) — no copy is
made until TensorReader::load_data is called. Format adapters that
decode on open (e.g. GGUF quantization) use TensorReader::owned.
Implementations§
Source§impl<'a> TensorReader<'a>
impl<'a> TensorReader<'a>
Sourcepub fn new(
name: String,
shape: Vec<usize>,
dtype: TensorDtype,
data: &'a [u8],
) -> Self
pub fn new( name: String, shape: Vec<usize>, dtype: TensorDtype, data: &'a [u8], ) -> Self
Creates a reader from raw parts. data must be
shape.iter().product::<usize>() * dtype.size() little-endian bytes.
Sourcepub fn owned(name: String, shape: Vec<usize>, data: Vec<u8>) -> Self
pub fn owned(name: String, shape: Vec<usize>, data: Vec<u8>) -> Self
Creates a reader over owned (already-decoded) f32 bytes.
Sourcepub fn owned_with_dtype(
name: String,
shape: Vec<usize>,
dtype: TensorDtype,
data: Vec<u8>,
) -> Self
pub fn owned_with_dtype( name: String, shape: Vec<usize>, dtype: TensorDtype, data: Vec<u8>, ) -> Self
Creates a reader over owned bytes of an explicit dtype (used when a passthrough tensor had to be row-reordered on load).
Sourcepub fn dtype(&self) -> TensorDtype
pub fn dtype(&self) -> TensorDtype
On-disk dtype.
Sourcepub fn num_elements(&self) -> usize
pub fn num_elements(&self) -> usize
Number of elements.
Sourcepub fn load_data(&self) -> Result<TensorData>
pub fn load_data(&self) -> Result<TensorData>
Converts the raw bytes to f32 TensorData. Integer and boolean tensors
are cast to f32 so weight loaders never abort on buffer dtypes such as
I64 position_ids.
Sourcepub fn load_to_tensor<B: Backend, const D: usize>(
&self,
device: &Device<B>,
) -> Result<Tensor<B, D>>
pub fn load_to_tensor<B: Backend, const D: usize>( &self, device: &Device<B>, ) -> Result<Tensor<B, D>>
Loads the tensor onto a backend device as an f32 tensor of rank D.
Sourcepub fn load_int_tensor<B: Backend, const D: usize>(
&self,
device: &Device<B>,
) -> Result<Tensor<B, D, Int>>
pub fn load_int_tensor<B: Backend, const D: usize>( &self, device: &Device<B>, ) -> Result<Tensor<B, D, Int>>
Loads raw unsigned-byte data onto a backend device as an i32 tensor
of rank D (values 0..=255). Only valid for U8 tensors; used to
feed packed quantized weights to GPU-side dequantization.