← Back to blogs

Visual Tokenizers: From Vector Quantization to Binary Spherical Codes

VQ-VAE, lookup-free quantization, and binary spherical quantization

The quantizer at the bottleneck of a visual tokenizer has gone through three designs in under a decade, each removing a degree of freedom from the last and asking a different mechanism to keep the resulting codebook from collapsing onto a handful of codes. VQ-VAE (Oord et al. 2017) opened the line: a nearest-neighbour lookup into a learned table of KK vectors, trained with a reconstruction loss whose gradient is carried past the non-differentiable arg⁡min\arg\min by the straight-through estimator (STE) (Bengio et al. 2013), a vector-quantization loss that moves the table toward the encoder's outputs, and a commitment loss that holds the encoder's outputs near the table (full treatment, including the ELBO reading and the EMA codebook update, in Vector Quantization and Discrete Representations and VQ-VAE: Discrete Latent Codes). VQGAN (Esser et al. 2021) kept the lookup and added a perceptual and an adversarial loss on top of the pixel loss, the training setup every later tokenizer in this chapter reuses. DALL-E's discrete variational autoencoder (dVAE) (Ramesh et al. 2021), a branch outside that training setup that keeps no perceptual or adversarial loss and maximizes the relaxed evidence lower bound alone, with a logit-Laplace reconstruction likelihood (Section 2.1, Appendices A.2 and A.3), replaces VQ-VAE's straight-through route with a Gumbel-softmax relaxation (Jang et al. 2017) of the KK-way assignment, relies on the Kullback-Leibler term of its evidence lower bound against a uniform prior over the K=8192K = 8192 codes, raised to a weight of 6.6, to keep the codebook in use (Section 2.1), and takes its tokens as the arg⁡max\arg\max of the encoder logits with no Gumbel noise added (Section 2.2); the two routes are compared in VQ-VAE's Hard Assignment vs. dVAE's Gumbel-Softmax Relaxation. The practical trouble with a learned codebook is scale: reconstruction keeps improving as KK grows, but generation quality on top of it degrades, and a large codebook spends a correspondingly large number of embedding parameters that mostly sit unused, the dead-code collapse that VQGAN-LC's smart initialization and use-aware resets (discussed in Vector Quantization and Discrete Representations) are built to fight.

MAGVIT-v2's lookup-free quantization (LFQ) (Yu et al. 2024) answers by removing the lookup rather than scaling it: the codebook's embedding dimension is reduced to zero, so quantization becomes a per-dimension sign against an implicit codebook of {−1,1}L\{-1,1\}^L that stores no parameters and costs no distance computation, and an explicit entropy penalty, adapted from an entropy-based clustering objective and from a codebook-utilization loss in MaskGIT (Chang et al. 2022), substitutes for the vector-quantization and commitment losses a learned codebook needs. The trade is that nothing bounds how far a quantized code can sit from the latent that produced it, since the latent itself is never normalized.

Binary spherical quantization (BSQ) (Zhao et al. 2025) keeps LFQ's per-dimension sign but first projects the latent onto the unit hypersphere, so the implicit codebook becomes the 2L2^L corners of a hypercube inscribed in that sphere rather than an unconstrained hypercube. The projection bounds the distance between a latent and its code by a constant depending only on LL, which the paper argues removes the need for a commitment loss, and it reuses LFQ's entropy penalty unchanged, evaluated on the normalized latent. Both LFQ and BSQ report reconstruction quality primarily as reconstruction FID (rFID) rather than the generation FID used to score a downstream generative prior, because the tokenizer and the prior are trained in two separate stages and a reconstruction-only metric isolates the tokenizer's own contribution.

References

Bengio, Yoshua, Nicholas Léonard, and Aaron Courville. 2013. "Estimating or Propagating Gradients Through Stochastic Neurons for Conditional Computation." arXiv. https://arxiv.org/abs/1308.3432.
Chang, Huiwen, Han Zhang, Lu Jiang, Ce Liu, and William T. Freeman. 2022. "MaskGIT: Masked Generative Image Transformer." IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), February. https://doi.org/10.48550/arXiv.2202.04200.
Esser, Patrick, Robin Rombach, and Björn Ommer. 2021. "Taming Transformers for High-Resolution Image Synthesis." Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, 12873-83.
Jang, Eric, Shixiang Gu, and Ben Poole. 2017. Categorical Reparameterization with Gumbel-Softmax. https://doi.org/10.48550/arXiv.1611.01144.
Oord, Aaron van den, Oriol Vinyals, and Koray Kavukcuoglu. 2017. "Neural Discrete Representation Learning." Advances in Neural Information Processing Systems, May. https://doi.org/10.48550/arXiv.1711.00937.
Ramesh, Aditya, Mikhail Pavlov, Gabriel Goh, et al. 2021. "Zero-Shot Text-to-Image Generation." International Conference on Machine Learning (ICML), February. https://doi.org/10.48550/arXiv.2102.12092.
Yu, Lijun, José Lezama, Nitesh B. Gundavarapu, et al. 2024. "Language Model Beats Diffusion - Tokenizer Is Key to Visual Generation." International Conference on Learning Representations (ICLR). https://arxiv.org/abs/2310.05737.
Zhao, Yue, Yuanjun Xiong, and Philipp Krähenbühl. 2025. "Image and Video Tokenization with Binary Spherical Quantization." International Conference on Learning Representations (ICLR). https://arxiv.org/abs/2406.07548.