Masked Vector Quantization

Surya Nepal · DOI

TL;DR

This paper introduces Masked Vector Quantization (MVQ), a novel approach to generative modeling that significantly improves efficiency and representation capacity. MVQ achieves this by learning to mask secondary latent codes, allowing for more compact representations and faster generation, particularly at higher compression rates.

What Problem Does This Paper Address?

Generative models that use discrete latent representations have shown great promise in capturing complex data distributions. However, achieving high-quality results often requires a large number of discrete tokens per instance and a vast number of codebook entries. This leads to computationally expensive training and slow sampling times during inference, hindering their practical application, especially in domains like video generation or real-time applications. The paper aims to address this trade-off between representation capacity, sample quality, and computational efficiency.

Methods

The core innovation is the Masked Vector Quantization (MVQ) framework, which builds upon existing Vector Quantization (VQ) techniques. MVQ introduces a secondary code vector alongside the primary one. The key idea is to learn mask configurations for this secondary code vector.

To efficiently learn these masks, the authors propose Multiple Hypotheses Dropout (MH-Dropout). During training, a small number of random masks are sampled for the secondary code vector. A winner-takes-all approach is then used, where only the mask that leads to the best reconstruction quality influences the gradient updates. This allows the model to explore multiple hypotheses for the secondary representation without the prohibitive cost of evaluating all possible masks.

The MVQ architecture uses a primary encoder to generate a primary code vector e and a secondary encoder to generate a secondary code vector e'. A mask m is then applied to e' to create a masked secondary code vector c = e' ⊙ m. The final representation ŷ is formed by combining the primary code e with a non-linear transformation of the masked secondary code f(c).

Datasets

The paper evaluates MVQ on several standard image datasets:

  • FashionMNIST (28x28)
  • CIFAR10 (32x32)
  • CelebA (64x64)
  • ImageNet (64x64)

Key Insights and Ideas

  • Masking unlocks representational capacity: By learning to mask secondary code vectors, MVQ can encode more information per token, effectively increasing the representational capacity of each codebook entry.
  • MH-Dropout is key to efficiency: The MH-Dropout mechanism cleverly approximates the optimal mask by sampling a few hypotheses, making the training feasible and enabling significant speed-ups during inference.
  • Improved compression: MVQ demonstrates superior performance (lower FID) at higher compression rates (fewer tokens per instance and smaller codebooks) compared to existing VQ architectures.
  • Transferable and interpretable features: The masked secondary code vectors learn interpretable characteristics (e.g., age, hair color, glasses) that can be smoothly combined and transferred between different primary codes, suggesting a form of unsupervised disentanglement.
  • Trade-off management: MVQ allows for a more favorable trade-off between reconstruction quality and sampling speed, enabling faster generation without a drastic drop in quality.

Key Results

  • FID Reduction: MVQ achieved FID reductions of up to 82% at 2 tokens per instance and 57% at 5 tokens on medium-resolution datasets.
  • Speed-up: MVQ offers significant speed-ups in token sampling during inference, with theoretical gains of 7-45x at higher down-sampling factors. For example, increasing the down-sampling factor from 16 to 64 for 64x64 images yielded a 7x speed-up on a consumer GPU and 45x on a CPU.
  • Competitive Performance: MVQGAN trained with only 2 tokens per image was competitive with VQGAN using 17 tokens on CelebA64.
  • Improved Quality at Lower Compression: MVQ consistently improved FID, perceptual loss, and F-score across various datasets and down-sampling factors, especially when token lengths and codebook entries were reduced.

Limitations and Future Work

  • Dataset Dependence: The interpretability and transferability of learned features are dataset-dependent.
  • Diversity Decrease: The paper notes that the diversity of masked configurations for the same code vector decreases as the number of tokens per image increases.
  • Future Work: The authors suggest that MVQ's ability to learn transferable representations could be further explored for applications like style transfer or controllable generation. The framework's efficiency also makes it suitable for domains requiring low inference times.

Summary updated

BibTeX
@inproceedings{nepal2023masked,
  author = {Surya Nepal},
  title = {{Masked Vector Quantization}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=ezgCdnzApo},
}
Figure