pub enum Storage {
F32(Vec<f32>),
F16(Vec<u16>),
BF16(Vec<u16>),
I8(Vec<i8>),
I32(Vec<i32>),
Quantized {
dtype: DType,
bytes: Vec<u8>,
},
}Expand description
An owned CPU buffer of tensor elements.
Variants§
F32(Vec<f32>)
F16(Vec<u16>)
Raw IEEE 754 binary16 bits. Stored as u16 rather than a float type
because Rust’s f32/f64 are the only floats with hardware and
library support; every element must go through
crate::half::f16_to_f32 to be computed on.
BF16(Vec<u16>)
Raw bfloat16 bits, likewise u16; see crate::half::bf16_to_f32.
I8(Vec<i8>)
I32(Vec<i32>)
Quantized
Any block-quantized format (DType::Q4_0, DType::Q4_1,
DType::Q5_0, DType::Q5_1, DType::Q8_0): raw on-disk block
bytes plus the tag saying how to decode them. Never indexed
elementwise directly — see DType::is_quantized and
[crate::quant].
Implementations§
Source§impl Storage
impl Storage
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of logical elements this storage holds.
For quantized storage this is derived from the byte length (every
byte belongs to some block, and every block decodes to exactly
DType::block_size elements) rather than tracked separately,
which is only sound because Self::new_quantized is the sole
constructor and it guarantees the byte length is a whole number of
blocks.
pub fn is_empty(&self) -> bool
Sourcepub fn new_quantized(
dtype: DType,
bytes: Vec<u8>,
elem_count: usize,
) -> Result<Self>
pub fn new_quantized( dtype: DType, bytes: Vec<u8>, elem_count: usize, ) -> Result<Self>
Builds quantized storage for elem_count elements of dtype from
raw block bytes.
Rejects two distinct failure modes with distinct errors, both
already defined by kopitiam-core for exactly this purpose:
elem_countis not a whole number of blocks (e.g. 33 elements of a 32-wide format) ->Error::PartialQuantizedBlock. This is not a rounding question — there is no valid byte layout for a partial block, so it is rejected before ever looking atbytes.bytesdoes not contain exactly the number of bytes thatelem_countblocks require ->Error::StorageTooSmall. This catches truncated reads and mismatched shape/data pairs at construction time instead of an out-of-bounds panic on first use.