Top AI Repos — open-source AI, indexed and scored
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Top AI Repos tracks AI repositories on GitHub and answers two different questions about each one: is it moving right now, and would you bet a product on it.
Vector (and Scalar) Quantization, in Pytorch
| Date | Stars |
|---|---|
| 2026-07-24 | 3987 |
| 2026-07-25 | 3987 |
| 2026-07-28 | 3987 |
| 2026-07-30 | 3987 |
| 2026-08-09 | 3996 |
| 2026-08-17 | 3996 |
| 2026-08-19 | 3995 |
| 2026-08-21 | 3994 |
| 2026-08-22 | 3995 |
| 2026-08-23 | 3996 |
| 2026-08-28 | 3998 |
| 2026-08-31 | 3997 |
| 2026-09-01 | 3997 |
| 2026-09-02 | 3998 |
| 2026-09-03 | 3999 |
| 2026-09-04 | 4000 |
| 2026-09-08 | 4001 |
| 2026-09-10 | 4002 |
| 2026-09-14 | 4003 |
| 2026-09-16 | 4005 |
| 2026-09-20 | 4006 |
Today
+1 stars today
This week
+4 stars this week
This month
+12 stars this month
Momentum
8.0
growth rate 0.10%/day
<img src="./images/vq.png" width="500px"></img>
## Vector Quantization - Pytorch
A vector quantization library originally transcribed from Deepmind's tensorflow implementation, made conveniently into a package. It uses exponential moving averages to update the dictionary.
VQ has been successfully used by Deepmind and OpenAI for high quality generation of images (VQ-VAE-2) and music (Jukebox).
## Install
```bash
$ pip install vector-quantize-pytorch
```
## Usage
```python
import torch
from vector_quantize_pytorch import VectorQuantize
vq = VectorQuantize(
dim = 256,
codebook_size = 512, # codebook size
decay = 0.8, # the exponential moving average decay, lower means the dictionary will change faster
commitment_weight = 1. # the weight on the commitment loss
)
x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = vq(x) # (1, 1024, 256), (1, 1024), (1)
```
## Residual VQ
This <a href="https://arxiv.org/abs/2107.03312">paper</a> proposes to use multiple vector quantizers to recursively quantize the residuals of the waveform. You can use this with the `ResidualVQ` class and one extra initialization parameter.
```python
import torch
from vector_quantize_pytorch import ResidualVQ
residual_vq = ResidualVQ(
dim = 256,
num_quantizers = 8, # specify number of quantizers
codebook_size = 1024, # codebook size
)
x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = residual_vq(x)
print(quantized.shape, indices.shape, commit_loss.shape)
# (1, 1024, 256), (1, 1024, 8), (1, 8)
# if you need all the codes across the quantization layers, just pass return_all_codes = True
quantized, indices, commit_loss, all_codes = residual_vq(x, return_all_codes = True)
# (8, 1, 1024, 256)
```
Alternatively, instead of exponential moving averages, you can update the codebooks using the <a href="https://openreview.net/forum?id=KRVnpTbx7R">DiVeQ technique</a>, which updates the codebooks by gradients without requiring any auxiliary losses. You can enable this feature by passing ```diveq = True``` in the ```ResidualVQ``` class.
```python
import torch
from vector_quantize_pytorch import ResidualVQ
residual_vq = ResidualVQ(
dim = 256,
num_quantizers = 8, # specify number of quantizers
codebook_size = 1024, # codebook size
diveq = True # use DiVeQ technique to update the codebooks
)
```
Furthermore, <a href="https://arxiv.org/abs/2203.01941">this paper</a> uses Residual-VQ to construct the RQ-VAE, for generating high resolution images with more compressed codes.
They make two modifications. The first is to share the codebook across all quantizers. The second is to stochastically sample the codes rather than always taking the closest match. You can use both of these features with two extra keyword arguments.
```python
import torch
from vector_quantize_pytorch import ResidualVQ
residual_vq = ResidualVQ(
dim = 256,
num_quantizers = 8,
codebook_size = 1024,
stochastic_sample_codes = True,
sample_codebook_temp = 0.1, # temperature for stochastically sampling codes, 0 would be equivalent to non-stochastic
shared_codebook = True # whether to share the codebooks for all quantizers or not
)
x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = residual_vq(x)
# (1, 1024, 256), (1, 1024, 8), (1, 8)
```
<a href="https://arxiv.org/abs/2305.02765">A recent paper</a> further proposes to do residual VQ on groups of the feature dimension, showing equivalent results to Encodec while using far fewer codebooks. You can use it by importing `GroupedResidualVQ`
```python
import torch
from vector_quantize_pytorch import GroupedResidualVQ
residual_vq = GroupedResidualVQ(
dim = 256,
num_quantizers = 8, # specify number of quantizers
groups = 2,
codebook_size = 1024, # codebook size
)
x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = residual_vq(x)
# (1, 1024, Excerpt of 33,599 characters
Read on GitHubPhil Wang · United States
443
sekstini
14
14
8
Kashif Rasul · Germany
4
3
Karim Farid · Germany
3
2
2
Mohammad Vali · Aalto University
2
Wassim (Wes) Bouaziz · Mistral AI
2
Lucas Newman · United States
2
2
Doyup Lee · United States
1
David W. Romero · NVIDIA · United States
1
Leng Yue · 39 AI · United States
1
Yuchao Zhang · Speechify
1
Matthew Wilson · United States
1
1
1
Would you bet a product on this? Bounded 0–100 and slow moving.
matched fp:333d9cbdde9d1e6c, topic:deep-learning, topic:pytorch