pub struct DeferredTensor {
pub path: PathBuf,
pub offset: u64,
pub shape: Vec<usize>,
pub dtype: WeightDtype,
}Expand description
Where a skipped tensor lives, so a consumer can read it in place.
Fields§
§path: PathBufShard file containing the tensor.
offset: u64ABSOLUTE byte offset of the tensor’s first element in that file
(safetensors header length + the tensor’s data_offsets[0]).
shape: Vec<usize>§dtype: WeightDtypeImplementations§
Source§impl DeferredTensor
impl DeferredTensor
Sourcepub fn byte_size(&self) -> usize
pub fn byte_size(&self) -> usize
The tensor’s on-disk footprint.
Only the fixed-width dtypes a safetensors header can carry reach here,
so numel * byte_size is exact — the block-based GGUF dtypes
(WeightDtype::PackedQ2_0 and the K-quants) report 0 bytes/element
and are never deferred by either rule.
Sourcepub fn read_host_bytes(&self) -> Result<Vec<u8>>
pub fn read_host_bytes(&self) -> Result<Vec<u8>>
Read the whole tensor’s raw bytes into host memory.
The consumer for a deferred tensor is usually a row cache that faults single rows off NVMe; this is the other shape of consumer — a loader that needs the tensor ONCE, at bind time, to derive the buffer it will actually upload.
🪤 read_exact rather than read_to_end: a short read means the shard
is truncated or the offset is wrong, and both must be an error here
rather than a shorter tensor whose element count is rejected later with
a message pointing at the wrong thing. Seek-then-read rather than
pread, because WeightStore builds on Windows too.
Trait Implementations§
Source§impl Clone for DeferredTensor
impl Clone for DeferredTensor
Source§fn clone(&self) -> DeferredTensor
fn clone(&self) -> DeferredTensor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more