vector-quantize-pytorch 1.22.3__tar.gz → 1.22.5__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 (32) hide show
  1. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/PKG-INFO +1 -1
  2. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/pyproject.toml +1 -1
  3. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/vector_quantize_pytorch.py +29 -7
  4. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/.github/workflows/build.yml +0 -0
  5. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/.github/workflows/python-publish.yml +0 -0
  6. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/.github/workflows/test.yml +0 -0
  7. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/.gitignore +0 -0
  8. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/LICENSE +0 -0
  9. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/README.md +0 -0
  10. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/examples/autoencoder.py +0 -0
  11. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/examples/autoencoder_fsq.py +0 -0
  12. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/examples/autoencoder_lfq.py +0 -0
  13. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/examples/autoencoder_sim_vq.py +0 -0
  14. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/images/fsq.png +0 -0
  15. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/images/lfq.png +0 -0
  16. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/images/simvq.png +0 -0
  17. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/images/vq.png +0 -0
  18. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/ruff.toml +0 -0
  19. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/tests/test_latent_quantization.py +0 -0
  20. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/tests/test_lfq.py +0 -0
  21. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/tests/test_readme.py +0 -0
  22. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/__init__.py +0 -0
  23. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/finite_scalar_quantization.py +0 -0
  24. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/latent_quantization.py +0 -0
  25. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/lookup_free_quantization.py +0 -0
  26. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/random_projection_quantizer.py +0 -0
  27. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/residual_fsq.py +0 -0
  28. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/residual_lfq.py +0 -0
  29. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/residual_sim_vq.py +0 -0
  30. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/residual_vq.py +0 -0
  31. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/sim_vq.py +0 -0
  32. {vector_quantize_pytorch-1.22.3 → vector_quantize_pytorch-1.22.5}/vector_quantize_pytorch/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: vector-quantize-pytorch
3
- Version: 1.22.3
3
+ Version: 1.22.5
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "vector-quantize-pytorch"
3
- version = "1.22.3"
3
+ version = "1.22.5"
4
4
  description = "Vector Quantization - Pytorch"
5
5
  authors = [
6
6
  { name = "Phil Wang", email = "lucidrains@gmail.com" }
@@ -138,11 +138,15 @@ def sample_multinomial(total_count, probs):
138
138
  remainder = probs.new_ones(())
139
139
  sample = torch.empty_like(probs, dtype = torch.long)
140
140
 
141
- for i, p in enumerate(probs):
142
- s = torch.binomial(total_count, p / remainder)
141
+ num_probs = len(probs)
142
+
143
+ for i, prob in enumerate(probs):
144
+ is_last = i == (num_probs - 1)
145
+
146
+ s = torch.binomial(total_count, prob / remainder) if not is_last else total_count
143
147
  sample[i] = s
144
148
  total_count -= s
145
- remainder -= p
149
+ remainder -= prob
146
150
 
147
151
  assert total_count == 0, f'invalid total count {total_count}'
148
152
 
@@ -559,9 +563,18 @@ class EuclideanCodebook(Module):
559
563
 
560
564
  else:
561
565
  if exists(codebook_transform_fn):
562
- quantize = einx.get_at('h b n [c] d, h b n -> h b n d', transformed_embed, embed_ind)
566
+ # quantize = einx.get_at('h b n [c] d, h b n -> h b n d', transformed_embed, embed_ind)
567
+
568
+ repeated_embed_ind = repeat(embed_ind, 'h b n -> h b n 1 d', d = transformed_embed.shape[-1])
569
+ quantize = transformed_embed.gather(-2, repeated_embed_ind)
570
+ quantize = rearrange(quantize, 'h b n 1 d -> h b n d')
571
+
563
572
  else:
564
- quantize = einx.get_at('h [c] d, h b n -> h b n d', embed, embed_ind)
573
+ # quantize = einx.get_at('h [c] d, h b n -> h b n d', embed, embed_ind)
574
+
575
+ repeated_embed = repeat(embed, 'h c d -> h b c d', b = embed_ind.shape[1])
576
+ repeated_embed_ind = repeat(embed_ind, 'h b n -> h b n d', d = embed.shape[-1])
577
+ quantize = repeated_embed.gather(-2, repeated_embed_ind)
565
578
 
566
579
  if self.training and self.ema_update and not freeze_codebook:
567
580
 
@@ -767,9 +780,18 @@ class CosineSimCodebook(Module):
767
780
 
768
781
  else:
769
782
  if exists(codebook_transform_fn):
770
- quantize = einx.get_at('h b n [c] d, h b n -> h b n d', transformed_embed, embed_ind)
783
+ # quantize = einx.get_at('h b n [c] d, h b n -> h b n d', transformed_embed, embed_ind)
784
+
785
+ repeated_embed_ind = repeat(embed_ind, 'h b n -> h b n 1 d', d = transformed_embed.shape[-1])
786
+ quantize = transformed_embed.gather(-2, repeated_embed_ind)
787
+ quantize = rearrange(quantize, 'h b n 1 d -> h b n d')
788
+
771
789
  else:
772
- quantize = einx.get_at('h [c] d, h b n -> h b n d', embed, embed_ind)
790
+ # quantize = einx.get_at('h [c] d, h b n -> h b n d', embed, embed_ind)
791
+
792
+ repeated_embed = repeat(embed, 'h c d -> h b c d', b = embed_ind.shape[1])
793
+ repeated_embed_ind = repeat(embed_ind, 'h b n -> h b n d', d = embed.shape[-1])
794
+ quantize = repeated_embed.gather(-2, repeated_embed_ind)
773
795
 
774
796
  if self.training and self.ema_update and not freeze_codebook:
775
797
  if exists(mask):