vector-quantize-pytorch
Vector Quantization - Pytorch
What it is and what it does
Vector-quantize-pytorch provides PyTorch implementations of vector quantization techniques originally from DeepMind's TensorFlow codebase. It includes the core VectorQuantize layer for single-stage quantization and ResidualVQ for multi-stage hierarchical quantization, both using exponential moving averages to update learned codebooks. The library also offers variants like GroupedResidualVQ and supports modern techniques such as DiVeQ gradient-based updates, kmeans initialization, rotation-trick gradient estimation, and strategies to combat dead codebook entries.
The package is designed for researchers and practitioners building generative models that require discrete latent representations—particularly image and audio generation systems. It handles the forward pass mapping continuous vectors to nearest codebook entries and provides configurable loss terms and gradient computation methods. Dependencies on einops, einx, and torch-einops-utils suggest heavy use of tensor reshaping and Einstein notation for flexible multi-dimensional operations.
Use it for:
- Building VQ-VAE models for image compression and generation with discrete latent codes
- Implementing audio codecs that use residual quantization across multiple stages
- Constructing RQ-VAE architectures with shared codebooks and stochastic sampling for image synthesis
- Experimenting with grouped quantization to reduce codebook overhead while maintaining reconstruction quality
- Training models with kmeans-initialized codebooks to improve early convergence and codebook utilization
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements vector quantization layers for PyTorch, enabling discrete codebook-based compression of continuous embeddings used in generative models.
Yes. The package is actively maintained, has no known vulnerabilities, carries a permissive MIT License, and offers low install friction. It is well-suited for anyone implementing vector quantization in PyTorch, particularly for generative modeling. The Beta status suggests research-grade rather than production-hardened, so verify compatibility with your specific PyTorch and Python versions before relying on it in production.
Install
vector-quantize-pytorch on PyPI
pip
pip install vector-quantize-pytorchuv
uv add vector-quantize-pytorchpoetry
poetry add vector-quantize-pytorchInstalling vector-quantize-pytorch
Before you install
Low install friction with a pure Python wheel and four runtime dependencies (einops, einx, torch-einops-utils, torch). Package is actively maintained with recent release and no known vulnerabilities.
License in practice
MIT License permits unrestricted use, modification, and distribution with only attribution required, suitable for both open-source and commercial projects.
Quickstart
pip install vector-quantize-pytorch
import torch
from vector_quantize_pytorch import VectorQuantize
vq = VectorQuantize(
dim = 256,
codebook_size = 512,
decay = 0.8,
commitment_weight = 1.
)
x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = vq(x)
Verify before relying
- Performance characteristics (speed, memory usage) compared to other quantization implementations
- Compatibility with specific PyTorch versions beyond the stated Python 3.9+ requirement
- Production-readiness status beyond the Beta development classifier
Package facts
| License | MIT License Copyright (c) 2020 Phil Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — einops, einx, torch-einops-utils, torch |
| Maintenance | actively maintained — 12 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,830,185/month — #3,511 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: vector_quantize_pytorch-1.31.1-py3-none-any.whl
Keywords: artificial intelligence, deep learning, pytorch, quantization
Tags
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to…
permissive · top 100 on PyPI
huggingface-hubClient library and CLI tool for downloading,…
permissive · top 100 on PyPI
langchainLangChain provides a framework for building…
permissive · top 1,000 on PyPI
hf-xethf-xet provides chunk-based deduplication and…
permissive · top 1,000 on PyPI
tokenizersTokenizers converts raw text into token…
permissive · top 1,000 on PyPI
transformersTransformers provides a unified framework for…
permissive · top 1,000 on PyPI
vit-pytorchProvides PyTorch implementations of Vision…
permissive · top 15,000 on PyPI
rotary-embedding-torchImplements rotary positional embeddings for…
permissive · top 15,000 on PyPI
compressed-tensorsProvides a unified format for storing and…
permissive · top 5,000 on PyPI
diffqDiffQ performs differentiable quantization of…
noncommercial · top 15,000 on PyPI
axial-positional-embeddingProvides axial positional embeddings for…
permissive · top 15,000 on PyPI
CoLT5-attentionImplements conditionally routed efficient…
permissive · top 15,000 on PyPI
hyper-connectionsImplements multiple residual streams in neural…
permissive · top 15,000 on PyPI
optimum-quantoA PyTorch quantization backend that reduces…
permissive · top 15,000 on PyPI
ai-edge-quantizerQuantizes LiteRT models to reduce size and…
permissive · top 15,000 on PyPI
pytorchcvProvides a collection of pretrained computer…
unclear · top 15,000 on PyPI