Skip to main content

Module fsq

Module fsq 

Source
Expand description

Finite Scalar Quantization (FSQ) — the codebook-free discrete token structure from “Finite Scalar Quantization: VQ-VAE Made Simple” (Mentzer et al., 2023). Each latent dimension is independently rounded to one of L evenly-spaced levels spanning a bounded range [lo, hi]; the implicit codebook is the Cartesian product of the per-dim level grids, so no codebook needs to be stored or learned. This is pure quantizer math — real and buildable now. The neural encoder that produces the (bounded) latents is a separate, NeedsWeights concern.

Per-dimension level counts may differ (e.g. [8, 5, 5, 5]), matching the FSQ convention. On-grid values (lo + k·step) round-trip exactly; off-grid values snap to the nearest level. Zero-heap: caller supplies the level table and all buffers.

Functions§

fsq_dequantize
Reconstruct latent components from FSQ level indices: out[d] = lo + tokens[d]·step_d.
fsq_quantize
Quantize each component of input to its per-dimension level grid, writing level indices.