skillfed

vector-quantize-pytorch

Vector Quantization - Pytorch

vector-quantize-pytorch v1.31.1 1.8M downloads/30d#3,511 on PyPI3,995
Permissive 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) Active released

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-pytorch

uv

uv add vector-quantize-pytorch

poetry

poetry add vector-quantize-pytorch

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.6Topic :: Scientific/Engineering :: Artificial Intelligence

Tags

vector quantization pytorchvq-vae implementationcodebook quantizationdiscrete embedding compressionresidual vector quantizationneural codebook learningquantized latent space
generative-modelsneural-compression

More Artificial Intelligence packages

Further reading