Skip to main content

Module codebook

Module codebook 

Source
Expand description

Immutable quantization lookup table with Python-parity training.

A Codebook owns 2^bit_width sorted, strictly-ascending f32 entries — one representative value per quantized index. It mirrors tinyquant_cpu.codec.codebook.Codebook field-for-field and produces byte-identical output on the full training + quantize + dequantize pipeline for the same inputs.

The algorithmic contract is fixed by docs/design/rust/numerical-semantics.md §Quantization and §Codebook training. Changing anything here requires regenerating the frozen fixtures under tests/fixtures/codebook/ and tests/fixtures/quantize/ via cargo xtask fixtures refresh-all.

Under feature = "simd" the quantize / dequantize methods route through [crate::codec::simd_api], which is the single source of truth for dispatch selection. No unsafe intrinsics are invoked directly from this file, but the file-level #![allow(unsafe_code)] is retained so that future SIMD specialisation (Phase 22) can add direct intrinsic paths here without re-plumbing the lint surface.

Structs§

Codebook
Immutable lookup table mapping quantized u8 indices to f32 values.