pub struct AprV2Writer { /* private fields */ }Expand description
APR v2 format writer
Implementations§
Source§impl AprV2Writer
impl AprV2Writer
Sourcepub fn new(metadata: AprV2Metadata) -> Self
pub fn new(metadata: AprV2Metadata) -> Self
Create new writer
LAYOUT-002: All new APR files are created with LAYOUT_ROW_MAJOR flag set. This ensures realizar can safely assume row-major layout for all tensors.
Sourcepub fn add_tensor(
&mut self,
name: impl Into<String>,
dtype: TensorDType,
shape: Vec<usize>,
data: Vec<u8>,
)
pub fn add_tensor( &mut self, name: impl Into<String>, dtype: TensorDType, shape: Vec<usize>, data: Vec<u8>, )
Add tensor to the file
Sourcepub fn add_f32_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: &[f32],
)
pub fn add_f32_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )
Add f32 tensor
Sourcepub fn add_f16_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: &[f32],
)
pub fn add_f16_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )
Add f16 tensor (converts f32 → f16, 2 bytes per value)
This provides true 2x compression over f32 storage with minimal precision loss for inference workloads. Uses IEEE 754 half-precision format.
Sourcepub fn add_q8_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: &[f32],
)
pub fn add_q8_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )
Add Q8 tensor (8-bit symmetric quantization)
Format: [scale: f32 (4 bytes)] + [quantized: i8 × n] Total size: 4 + n bytes (vs 4n for f32) Compression ratio: ~4x
Sourcepub fn add_q4_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
data: &[f32],
)
pub fn add_q4_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )
Add Q4 tensor (4-bit symmetric quantization, block-wise)
Format: For each block of 32 values: [block_scale: f16 (2 bytes)] + [packed nibbles: 16 bytes]
Total size per block: 18 bytes (vs 128 bytes for f32) Compression ratio: ~7x
Sourcepub fn add_q4k_raw_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
raw_data: Vec<u8>,
)
pub fn add_q4k_raw_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, raw_data: Vec<u8>, )
Add raw Q4_K tensor (GGUF-compatible super-block format)
This stores GGUF Q4_K data directly without re-quantization. Q4_K format: 256-element super-blocks with nested 32-element sub-blocks Each super-block: d (f16, 2B) + dmin (f16, 2B) + scales (12B) + qs (128B) = 144 bytes Effective bits per weight: ~4.5
Use this when importing from GGUF to preserve exact quantization.
Sourcepub fn add_q6k_raw_tensor(
&mut self,
name: impl Into<String>,
shape: Vec<usize>,
raw_data: Vec<u8>,
)
pub fn add_q6k_raw_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, raw_data: Vec<u8>, )
Add raw Q6_K tensor (GGUF-compatible super-block format)
This stores GGUF Q6_K data directly without re-quantization. Q6_K format: 256-element super-blocks Each super-block: ql (128B) + qh (64B) + scales (16B) + d (f16, 2B) = 210 bytes Effective bits per weight: ~6.5
Sourcepub fn with_lz4_compression(&mut self) -> &mut Self
pub fn with_lz4_compression(&mut self) -> &mut Self
Set LZ4 compression flag
Sourcepub fn with_sharding(
&mut self,
shard_count: usize,
shard_index: usize,
) -> &mut Self
pub fn with_sharding( &mut self, shard_count: usize, shard_index: usize, ) -> &mut Self
Set sharding info
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AprV2Writer
impl RefUnwindSafe for AprV2Writer
impl Send for AprV2Writer
impl Sync for AprV2Writer
impl Unpin for AprV2Writer
impl UnwindSafe for AprV2Writer
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
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