lucidrains / vector-quantize-pytorch

Vector (and Scalar) Quantization, in Pytorch
MIT License
2.41k stars 196 forks source link

[feature] Finite Scalar Quantization: VQ-VAE Made Simple #72

Closed kashif closed 11 months ago

kashif commented 11 months ago

Abstract:

We propose to replace vector quantization (VQ) in the latent representation of VQ-VAEs with a simple scheme termed finite scalar quantization (FSQ), where we project the VAE representation down to a few dimensions (typically less than 10). Each dimension is quantized to a small set of fixed values, leading to an (implicit) codebook given by the product of these sets. By appropriately choosing the number of dimensions and values each dimension can take, we obtain the same codebook size as in VQ. On top of such discrete representations, we can train the same models that have been trained on VQ-VAE representations. For example, autoregressive and masked transformer models for image generation, multimodal generation, and dense prediction computer vision tasks. Concretely, we employ FSQ with MaskGIT for image generation, and with UViM for depth estimation, colorization, and panoptic segmentation. Despite the much simpler design of FSQ, we obtain competitive performance in all these tasks. We emphasize that FSQ does not suffer from codebook collapse and does not need the complex machinery employed in VQ (commitment losses, codebook reseeding, code splitting, entropy penalties, etc.) to learn expressive discrete representations.

See paper https://arxiv.org/abs/2309.15505

Will read over it and see how to add it

lucidrains commented 11 months ago

@kashif nice! you are really on top of the vector quantization literature 😄

yea, i can probably add this as a separate file

lucidrains commented 11 months ago

@kashif i'm guessing because this is a deepmind work, no code will be available

kashif commented 11 months ago

oh i just saw the appendix.. the code in jax is there... nice!

lucidrains commented 11 months ago

@kashif woohoo! see if chatgpt can translate it to pytorch 😆

lucidrains commented 11 months ago

if not, that's ok, i'll just do it tomorrow morning, seems very straightforward

kashif commented 11 months ago

fixed by #74