Finite Scalar Quantization: VQ-VAE Made Simple

Fabian Mentzer, David Minnen, Eirikur Agustsson, Michael Tschannen

TL;DR

Vector Quantization (VQ) is a powerful but finicky component of modern generative models like VQ-VAEs. This paper introduces Finite Scalar Quantization (FSQ), a surprisingly simple alternative that replaces complex codebook learning with basic rounding on a fixed grid. FSQ eliminates the need for auxiliary losses and "training tricks" while achieving 100% codebook utilization and competitive performance across image generation and computer vision tasks.

What Problem Does This Paper Address?

In the world of discrete representation learning (think VQ-VAE, MaskGIT, or DALL-E), the goal is to turn continuous data like images into a sequence of discrete "tokens" or codewords. Traditionally, this is done via Vector Quantization (VQ): the model maintains a "codebook" of vectors and maps every input to its nearest neighbor in that book.

However, VQ is notoriously difficult to optimize. It suffers from codebook collapse, where the model only uses a small fraction of the available codewords, leaving the rest "dead." To fix this, researchers have developed a mountain of "dark magic" heuristics: commitment losses, exponential moving averages (EMA), codebook reseeding, and entropy penalties. These add complexity and require significant hyperparameter tuning. The authors of this paper ask: Can we get the benefits of discrete tokens without the headache of VQ?

Methods: Finite Scalar Quantization

The authors propose Finite Scalar Quantization (FSQ). Instead of searching for the nearest neighbor in a high-dimensional learned codebook, FSQ simplifies the process entirely.

Comparison of FSQ and VQ architectures

As shown above, FSQ works by:

  1. Projecting the encoder output to a very low number of dimensions (typically $d < 10$).
  2. Bounding the values of each dimension to a specific range.
  3. Rounding each dimension to one of $L$ fixed integer values.

The "codebook" in FSQ is implicit—it is simply the Cartesian product of the allowed values in each dimension. For example, if you have 3 dimensions and each can take 3 values (-1, 0, 1), you have a fixed grid of $3^3 = 27$ possible codewords.

To train the model, they use the Straight-Through Estimator (STE), which simply treats the non-differentiable rounding operation as an identity function during the backward pass.

FSQ vs VQ comparison table and rounding function

Crucially, because the grid is fixed and the encoder is forced to map inputs to it to minimize reconstruction loss, FSQ requires zero auxiliary losses. As highlighted in the comparison table, FSQ strips away the commitment losses, EMA tricks, and explicit codebook parameters that make VQ so cumbersome.

Key Insights and Ideas

  • Fixed Grids > Learned Codebooks: By using a fixed, predefined grid, FSQ sidesteps the optimization issues of VQ. The encoder "learns" to move representations to the right slots on the grid, rather than the codebook "learning" to find the representations.
  • 100% Utilization by Design: While VQ models often use less than 50% of their codebook as the size increases, FSQ maintains nearly 100% utilization even for very large codebooks (up to $2^{16}$ codes).
  • Scaling Advantage: FSQ actually performs better as the codebook size increases. In contrast, VQ performance often plateaus or degrades at high codebook sizes because the optimization becomes too unstable.
  • Low-Dimensional Latents: FSQ works best in very low dimensions (e.g., $d=5$ or $d=8$), whereas VQ typically requires high-dimensional vectors ($d \geq 512$). This makes the projection layers in FSQ-based models significantly smaller and more parameter-efficient.

Key Results

The authors validated FSQ across several diverse and demanding benchmarks, including ImageNet (for reconstruction and generation via MaskGIT), NYU Depth v2 (depth estimation), COCO (panoptic segmentation), and ImageNet Colorization.

  • Image Generation: In a head-to-head with MaskGIT, FSQ achieved a Sampling FID of 4.53 on ImageNet-256, nearly identical to VQ's 4.51, but with much simpler training.
  • Vision Tasks: On the UViM benchmark, FSQ performed competitively with VQ across depth estimation, colorization, and panoptic segmentation.
  • Robustness: The authors showed that VQ relies heavily on "codebook splitting" to avoid jagged, poor-quality results in depth estimation. FSQ produced smooth, high-quality results without any such tricks.
  • Parameter Efficiency: Because FSQ doesn't store an explicit codebook and uses lower-dimensional projections, it reduces the parameter count compared to VQ models with the same codebook size.

Limitations and Future Work

While FSQ removes many hyperparameters, users still need to decide how many levels ($L$) to assign to each dimension to reach a target codebook size. The authors provide a table of recommended configurations, but it remains a design choice. Additionally, FSQ is fundamentally tied to low-dimensional projections. While this works for the tasks tested, it is unclear if certain applications might strictly require the high-dimensional latent space that VQ provides.

In summary, FSQ is a "less is more" breakthrough. It proves that by simplifying the quantization process to its bare essentials, we can build generative models that are easier to train, more robust, and just as powerful as their more complex predecessors.

Summary updated

BibTeX
@inproceedings{mentzer2024finite,
  author = {Fabian Mentzer and David Minnen and Eirikur Agustsson and Michael Tschannen},
  title = {{Finite Scalar Quantization: VQ-VAE Made Simple}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=8ishA3LxN8},
}
Figure