Skip to main content

Crate fib_quant

Crate fib_quant 

Source
Expand description

Experimental paper-core FibQuant math crate.

This crate implements the normalize, deterministic rotation, spherical-Beta block source, radial-angular codebook, Lloyd-Max refinement, and fixed-rate codec path described in FibQuant: Universal Vector Quantization for Random-Access KV-Cache Compression.

The 0.1.0-alpha.1 surface is deliberately narrow. It is not a production KV-cache compressor, not a benchmark reproduction package, and not integrated with any parent workspace memory crate. Profiles are validated against explicit alpha resource limits before allocation-heavy paths run.

use fib_quant::{FibQuantProfileV1, FibQuantizer};

let mut profile = FibQuantProfileV1::paper_default(8, 2, 8, 7)?;
profile.training_samples = 128;
profile.lloyd_restarts = 1;
profile.lloyd_iterations = 2;
let quantizer = FibQuantizer::new(profile)?;
let input = vec![0.25, -0.5, 0.75, 1.0, -1.25, 0.5, 0.125, -0.875];
let code = quantizer.encode(&input)?;
let decoded = quantizer.decode(&code)?;
assert_eq!(decoded.len(), input.len());

Re-exports§

pub use codebook::build_initial_codebook;
pub use codebook::FibCodebookV1;
pub use codec::FibCodeV1;
pub use codec::FibQuantizer;
pub use directions::fibonacci_sphere_3d;
pub use directions::fibonacci_spiral_2d;
pub use directions::roberts_kronecker;
pub use error::FibQuantError;
pub use error::Result;
pub use lloyd::LloydRepairEventV1;
pub use lloyd::LloydReportV1;
pub use profile::DirectionMethod;
pub use profile::EmptyCellPolicy;
pub use profile::FibQuantProfileV1;
pub use profile::NormFormat;
pub use profile::RadiusMethod;
pub use profile::SourceMode;
pub use profile::MAX_AMBIENT_DIM;
pub use profile::MAX_BLOCK_DIM;
pub use profile::MAX_CODEBOOK_SIZE;
pub use profile::MAX_CODEBOOK_VALUES;
pub use profile::MAX_PACKED_INDEX_BITS;
pub use profile::MAX_ROTATION_MATRIX_VALUES;
pub use profile::MAX_TRAINING_SAMPLES;
pub use receipt::FibQuantCompressionReceiptV1;
pub use rotation::StoredRotation;
pub use rotation::ROTATION_ALGORITHM_VERSION;
pub use rotation::ROTATION_SCHEMA;
pub use spherical_beta::beta_d_k;
pub use spherical_beta::radius_quantile;
pub use spherical_beta::radius_quantile_k2_closed_form;
pub use spherical_beta::sample_reference_projection;
pub use spherical_beta::sample_spherical_beta;

Modules§

beta_inv
bitpack
codebook
codec
digest
directions
error
kv
KV-cache compression contracts and CPU reference paths.
lloyd
metrics
profile
receipt
rotation
spherical_beta