Skip to main content

AprV2Writer

Struct AprV2Writer 

Source
pub struct AprV2Writer { /* private fields */ }
Expand description

APR v2 format writer

Implementations§

Source§

impl AprV2Writer

Source

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.

Source

pub fn add_tensor( &mut self, name: impl Into<String>, dtype: TensorDType, shape: Vec<usize>, data: Vec<u8>, )

Add tensor to the file

Source

pub fn add_f32_tensor( &mut self, name: impl Into<String>, shape: Vec<usize>, data: &[f32], )

Add f32 tensor

Source

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.

Source

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

Source

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

Source

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.

Source

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

Source

pub fn with_lz4_compression(&mut self) -> &mut Self

Set LZ4 compression flag

Source

pub fn with_sharding( &mut self, shard_count: usize, shard_index: usize, ) -> &mut Self

Set sharding info

Source

pub fn write(&mut self) -> Result<Vec<u8>, V2FormatError>

Write to bytes

§Errors

Returns error if serialization fails.

Source

pub fn write_to<W: Write>( &mut self, writer: &mut W, ) -> Result<(), V2FormatError>

Write to a Write impl

§Errors

Returns error if write fails.

Trait Implementations§

Source§

impl Debug for AprV2Writer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V