DeepMind's hierarchical image codec, rebuilt for PyTorch tinkerers
A faithful PyTorch port of VQ-VAE-2 that bundles a pretrained FFHQ checkpoint so you can experiment without training a codebook from scratch.

What it does Implements the VQ-VAE-2 architecture in PyTorch for generating 256px images through hierarchical vector quantization. The pipeline splits work across two stages: first a VQ-VAE encodes images into discrete top- and bottom-level codes, then a PixelSNAIL autoregressive model learns to generate those codes. The author provides a pretrained checkpoint on the FFHQ face dataset so you can skip straight to stage two or inspect reconstructions.
The interesting bit The project treats image generation as a compression problem with two timezones—stage one builds a discrete codebook, stage two predicts entries from it. Intermediate codes are cached in LMDB between stages, keeping the pipeline modular and avoiding repeated re-encoding of the dataset.
Key highlights
- Ships with a pretrained VQ-VAE checkpoint trained on FFHQ (
vqvae_560.pt) - Supports distributed training across multiple GPUs for the VQ-VAE stage
- Splits generation into top and bottom hierarchical priors at 256px resolution
- Stores intermediate discrete codes in LMDB for efficient stage-two training
- Pure PyTorch implementation with minimal dependencies
Caveats
- The bundled PixelSNAIL model is intentionally smaller than the paper’s spec; the author notes this is due to GPU memory constraints
- Only 256px resolution is currently supported
- The sample shown is explicitly labeled as a training sample, not a novel generation
Verdict Useful if you want a practical PyTorch implementation of VQ-VAE-2 with pretrained weights for faces. Look elsewhere if you need the original paper’s full model capacity out of the box.
Frequently asked
- What is rosinality/vq-vae-2-pytorch?
- A faithful PyTorch port of VQ-VAE-2 that bundles a pretrained FFHQ checkpoint so you can experiment without training a codebook from scratch.
- Is vq-vae-2-pytorch open source?
- Yes — rosinality/vq-vae-2-pytorch is an open-source project tracked on heatdrop.
- What language is vq-vae-2-pytorch written in?
- rosinality/vq-vae-2-pytorch is primarily written in Python.
- How popular is vq-vae-2-pytorch?
- rosinality/vq-vae-2-pytorch has 1.8k stars on GitHub.
- Where can I find vq-vae-2-pytorch?
- rosinality/vq-vae-2-pytorch is on GitHub at https://github.com/rosinality/vq-vae-2-pytorch.