vector-quantize-pytorch 1.19.0__tar.gz → 1.19.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/PKG-INFO +1 -35
  2. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/README.md +0 -34
  3. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/pyproject.toml +1 -1
  4. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/residual_fsq.py +2 -2
  5. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/residual_vq.py +3 -3
  6. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/.github/workflows/build.yml +0 -0
  7. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/.github/workflows/python-publish.yml +0 -0
  8. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/.github/workflows/test.yml +0 -0
  9. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/.gitignore +0 -0
  10. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/LICENSE +0 -0
  11. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/examples/autoencoder.py +0 -0
  12. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/examples/autoencoder_fsq.py +0 -0
  13. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/examples/autoencoder_lfq.py +0 -0
  14. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/images/fsq.png +0 -0
  15. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/images/lfq.png +0 -0
  16. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/images/vq.png +0 -0
  17. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/ruff.toml +0 -0
  18. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/tests/test_latent_quantization.py +0 -0
  19. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/tests/test_readme.py +0 -0
  20. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/__init__.py +0 -0
  21. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/finite_scalar_quantization.py +0 -0
  22. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/latent_quantization.py +0 -0
  23. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/lookup_free_quantization.py +0 -0
  24. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/random_projection_quantizer.py +0 -0
  25. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/residual_lfq.py +0 -0
  26. {vector_quantize_pytorch-1.19.0 → vector_quantize_pytorch-1.19.2}/vector_quantize_pytorch/vector_quantize_pytorch.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: vector-quantize-pytorch
3
- Version: 1.19.0
3
+ Version: 1.19.2
4
4
  Summary: Vector Quantization - Pytorch
5
5
  Project-URL: Homepage, https://pypi.org/project/vector-quantize-pytorch/
6
6
  Project-URL: Repository, https://github.com/lucidrains/vector-quantizer-pytorch
@@ -144,29 +144,6 @@ quantized, indices, commit_loss = residual_vq(x)
144
144
  # (1, 1024, 256), (2, 1, 1024, 8), (2, 1, 8)
145
145
  ```
146
146
 
147
-
148
- <a href="https://arxiv.org/abs/2305.05065">This paper</a> out of Google Deepmind claims that residual vector quantization can induce hierarchical semantic ids for building a recommender system. In their scheme, they use increasing number of codes across depth for it to work. This repository supports that scheme as so
149
-
150
- ```python
151
- import torch
152
- from vector_quantize_pytorch import ResidualVQ
153
-
154
- residual_vq = ResidualVQ(
155
- dim = 2,
156
- codebook_size = (5, 128, 256), # from top most hierarchy to lowest, 5 codes, 128 codes, then 256 codes
157
- )
158
-
159
- x = torch.randn(2, 2, 2)
160
-
161
- residual_vq.train()
162
-
163
- quantized, indices, commit_loss = residual_vq(x, freeze_codebook = True)
164
-
165
- quantized_out = residual_vq.get_output_from_indices(indices)
166
-
167
- assert torch.allclose(quantized, quantized_out, atol = 1e-5)
168
- ```
169
-
170
147
  ## Initialization
171
148
 
172
149
  The SoundStream paper proposes that the codebook should be initialized by the kmeans centroids of the first batch. You can easily turn on this feature with one flag `kmeans_init = True`, for either `VectorQuantize` or `ResidualVQ` class
@@ -781,14 +758,3 @@ assert loss.item() >= 0
781
758
  url = {https://api.semanticscholar.org/CorpusID:273229218}
782
759
  }
783
760
  ```
784
-
785
- ```bibtex
786
- @article{Rajput2023RecommenderSW,
787
- title = {Recommender Systems with Generative Retrieval},
788
- author = {Shashank Rajput and Nikhil Mehta and Anima Singh and Raghunandan H. Keshavan and Trung Hieu Vu and Lukasz Heldt and Lichan Hong and Yi Tay and Vinh Q. Tran and Jonah Samost and Maciej Kula and Ed H. Chi and Maheswaran Sathiamoorthy},
789
- journal = {ArXiv},
790
- year = {2023},
791
- volume = {abs/2305.05065},
792
- url = {https://api.semanticscholar.org/CorpusID:258564854}
793
- }
794
- ```
@@ -100,29 +100,6 @@ quantized, indices, commit_loss = residual_vq(x)
100
100
  # (1, 1024, 256), (2, 1, 1024, 8), (2, 1, 8)
101
101
  ```
102
102
 
103
-
104
- <a href="https://arxiv.org/abs/2305.05065">This paper</a> out of Google Deepmind claims that residual vector quantization can induce hierarchical semantic ids for building a recommender system. In their scheme, they use increasing number of codes across depth for it to work. This repository supports that scheme as so
105
-
106
- ```python
107
- import torch
108
- from vector_quantize_pytorch import ResidualVQ
109
-
110
- residual_vq = ResidualVQ(
111
- dim = 2,
112
- codebook_size = (5, 128, 256), # from top most hierarchy to lowest, 5 codes, 128 codes, then 256 codes
113
- )
114
-
115
- x = torch.randn(2, 2, 2)
116
-
117
- residual_vq.train()
118
-
119
- quantized, indices, commit_loss = residual_vq(x, freeze_codebook = True)
120
-
121
- quantized_out = residual_vq.get_output_from_indices(indices)
122
-
123
- assert torch.allclose(quantized, quantized_out, atol = 1e-5)
124
- ```
125
-
126
103
  ## Initialization
127
104
 
128
105
  The SoundStream paper proposes that the codebook should be initialized by the kmeans centroids of the first batch. You can easily turn on this feature with one flag `kmeans_init = True`, for either `VectorQuantize` or `ResidualVQ` class
@@ -737,14 +714,3 @@ assert loss.item() >= 0
737
714
  url = {https://api.semanticscholar.org/CorpusID:273229218}
738
715
  }
739
716
  ```
740
-
741
- ```bibtex
742
- @article{Rajput2023RecommenderSW,
743
- title = {Recommender Systems with Generative Retrieval},
744
- author = {Shashank Rajput and Nikhil Mehta and Anima Singh and Raghunandan H. Keshavan and Trung Hieu Vu and Lukasz Heldt and Lichan Hong and Yi Tay and Vinh Q. Tran and Jonah Samost and Maciej Kula and Ed H. Chi and Maheswaran Sathiamoorthy},
745
- journal = {ArXiv},
746
- year = {2023},
747
- volume = {abs/2305.05065},
748
- url = {https://api.semanticscholar.org/CorpusID:258564854}
749
- }
750
- ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vector-quantize-pytorch"
3
- version = "1.19.0"
3
+ version = "1.19.2"
4
4
  description = "Vector Quantization - Pytorch"
5
5
  authors = [
6
6
  { name = "Phil Wang", email = "lucidrains@gmail.com" }
@@ -36,8 +36,8 @@ def round_up_multiple(num, mult):
36
36
  def is_distributed():
37
37
  return dist.is_initialized() and dist.get_world_size() > 1
38
38
 
39
- def get_maybe_sync_seed(max_size = 10_000):
40
- rand_int = torch.randint(0, max_size, ())
39
+ def get_maybe_sync_seed(device, max_size = 10_000):
40
+ rand_int = torch.randint(0, max_size, (), device = device)
41
41
 
42
42
  if is_distributed():
43
43
  dist.all_reduce(rand_int)
@@ -160,11 +160,11 @@ class ResidualVQ(Module):
160
160
 
161
161
  codebook_sizes = cast_tuple(codebook_size, num_quantizers)
162
162
 
163
- num_quantizers = len(codebook_sizes)
164
- self.num_quantizers = num_quantizers
165
-
163
+ num_quantizers = default(num_quantizers, len(codebook_sizes))
166
164
  assert len(codebook_sizes) == num_quantizers
167
165
 
166
+ self.num_quantizers = num_quantizers
167
+
168
168
  self.codebook_sizes = codebook_sizes
169
169
  self.uniform_codebook_size = len(unique(codebook_sizes)) == 1
170
170