Abstract
Vector Quantization (VQ) is a fundamental component of modern generative architectures, including VQ-VAEs and Latent Diffusion Models (LDMs). However, these models frequently suffer from "codebook collapse," where a significant portion of the discrete latent space remains unutilized. This paper introduces Online Clustered Codebook (CVQ-VAE), a method designed to eliminate dead vectors by treating codebook learning as an online clustering problem. By dynamically reinitializing unused codevectors using running averages of encoded features, CVQ-VAE achieves 100% codebook utilization and demonstrates superior performance in image reconstruction and generation tasks.
1. Introduction
Vector Quantization-Variational Autoencoders (VQ-VAEs) have revolutionized generative modeling by enabling the representation of continuous data through a discrete "vocabulary" or codebook. This discretization is essential for downstream tasks like autoregressive modeling or diffusion. Despite their success, VQ-VAEs are plagued by codebook collapse—a phenomenon where the majority of codevectors are never selected during training. Because the quantization step is non-differentiable, vectors that are not initially chosen receive no gradient updates, becoming "dead" and effectively wasting the model's capacity.
Previous attempts to mitigate this, such as Exponential Moving Averages (EMA) or stochastic quantization, have provided partial relief but often fail to maintain high utilization as codebook sizes scale. This paper presents CVQ-VAE, a robust solution that ensures every vector in the codebook contributes to the data representation.
2. Methodology
The core innovation of CVQ-VAE is the conceptualization of codebook learning as a dynamic, online clustering task, inspired by algorithms like k-means++.
2.1 Dynamic Reinitialization
CVQ-VAE monitors the usage of codevectors throughout training. When a vector is identified as "dead" (unused for a specific duration), the model "teleports" it to a new location in the feature space. Instead of a random placement, the vector is reinitialized at the location of an encoded feature that is currently being underrepresented, effectively turning the dead vector into a useful anchor for existing data.
2.2 Stable Running Averages
To avoid the noise inherent in individual mini-batches, CVQ-VAE maintains running averages of encoded features across training iterations. These averages provide a stable, global view of the data distribution. By using these stable averages as anchors for reinitialization rather than raw batch features, the method ensures that the codebook updates are robust and representative of the overall dataset.
2.3 Contrastive Regularization
To prevent the codebook from collapsing into a few dense clusters, the authors incorporate a contrastive loss. This loss encourages sparsity and forces codevectors to be well-distributed across the latent space. This ensures that different vectors capture distinct features, maximizing the information density of the discrete representation.
3. Experimental Results
The authors evaluated CVQ-VAE across diverse benchmarks, ranging from simple datasets like MNIST and CIFAR10 to high-resolution datasets like FFHQ and ImageNet.
3.1 Reconstruction Performance
In reconstruction tasks, CVQ-VAE consistently outperformed standard VQ-VAE and VQGAN architectures. On the CIFAR10 dataset, CVQ-VAE reduced the relative Frechet Inception Distance (rFID) from 39.67 to 24.73. When integrated into the VQGAN framework, it surpassed original baselines and even more complex variants like ViT-VQGAN on ImageNet reconstruction, demonstrating that 100% codebook utilization directly translates to higher fidelity.
3.2 Generative Quality in Diffusion Models
The method's impact is particularly evident in Latent Diffusion Models (LDM). By replacing the standard quantizer with the CVQ-VAE module, the researchers observed a significant improvement in generative quality. On ImageNet, the FID score improved from 10.56 to 6.87. The resulting images exhibited sharper textures and fewer structural artifacts, particularly in complex scenes where traditional codebooks often struggle to capture fine-grained details.
4. Discussion and Key Insights
- The Power of Full Utilization: The most significant finding is that achieving 100% codebook usage is not just a theoretical goal but a practical necessity for maximizing model performance. CVQ-VAE consistently reaches this threshold across various architectures.
- Online vs. Offline Updates: The paper highlights that online updates—leveraging running averages—are significantly more stable than offline reinitialization methods. This stability is crucial for convergence in large-scale training scenarios.
- Representational Accuracy: Interestingly, the authors found that traditional metrics like "codebook perplexity" do not always correlate with image quality. CVQ-VAE focuses on making the codebook representative of the actual data distribution, which yields better visual results even if perplexity scores are lower than those found in competing literature.
5. Conclusion and Future Work
CVQ-VAE provides a simple, "plug-and-play" solution to the long-standing problem of codebook collapse. By ensuring 100% utilization through online clustering and stable reinitialization, it unlocks the full potential of vector-quantized models. While currently focused on computer vision, the principles of online clustered codebooks hold promise for other domains, such as discrete audio synthesis and cross-modal representation learning. Future research may also focus on optimizing the decay hyperparameter ($\gamma$) to further reduce the need for dataset-specific tuning.
Summary updated