# lucidrains/vector-quantize-pytorch

Vector (and Scalar) Quantization, in Pytorch

Repository: https://github.com/lucidrains/vector-quantize-pytorch
Canonical: https://ross.abutalabs.com/products/vector-quantize-pytorch
Language: Python
License: MIT
License Family: permissive
Topics: artificial-intelligence, deep-learning, pytorch, vector-quantization, scalar-quantization
Last push: 2026-08-02T17:58:00+00:00

## Health v2 (maintenance only)
Score: 83/100 (v2, computed 2026-09-03T02:39:23.370411+00:00)
- activity 95, release rhythm 58, longevity 100
- inputs: {"age_days": 2276, "days_push": 31, "days_rel": 202, "gap_med": 1, "n_releases_24m": 84}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 3996, forks 337 (observed 2026-08-28T04:08:31.908356+00:00)

## What it is
A PyTorch library implementing vector and scalar quantization, including Residual VQ and techniques like DiVeQ codebook updates. It originated from DeepMind's TensorFlow implementation and is used in models like VQ-VAE and RQ-VAE for compressing data into discrete codes.

## Use cases
- quantize neural network embeddings into discrete codes
- build a VQ-VAE for image generation
- implement residual vector quantization for audio codecs
- train codebooks with exponential moving averages in PyTorch
- compress high-resolution images with RQ-VAE
- apply scalar quantization to model latents

## When to choose
- you need ready-made vector quantization layers in PyTorch
- you are building VQ-VAE, RQ-VAE, or audio/image tokenizers
- you want EMA or gradient-based codebook updates without writing them yourself

## When to avoid
- you need quantization for model compression/inference speedup (that's a different kind of quantization)
- you work outside PyTorch
- you need a full VQ-VAE model rather than quantization building blocks

## Facets
- artifact type: library
- maturity: active
- function: machine-learning, deep-learning, serialization
- domain: deep-learning, machine-learning, artificial-intelligence
- platform: python
- tags: pytorch, vector-quantization, scalar-quantization, vq-vae, residual-vq, codebook-learning

## Member repositories
- lucidrains/vector-quantize-pytorch (main) score 83

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:08:31.908356+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T18:24:11.116447+00:00, confidence not recorded.
  - readme: https://github.com/lucidrains/vector-quantize-pytorch (fetched 2026-08-28T04:08:31.908356+00:00, sha 7ba6c017bb64)
- Data as of 2026-08-30T08:39:29.467469+00:00.
