vector-quantize-pytorch 1.27.0__tar.gz → 1.27.4__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.
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/PKG-INFO +1 -1
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/pyproject.toml +1 -1
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/residual_vq.py +28 -14
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.github/workflows/build.yml +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.github/workflows/python-publish.yml +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.github/workflows/test.yml +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.gitignore +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/LICENSE +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/README.md +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_fsq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_lfq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_sim_vq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/images/fsq.png +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/images/lfq.png +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/images/simvq.png +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/images/vq.png +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/ruff.toml +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/tests/test_beam.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/tests/test_latent_quantization.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/tests/test_lfq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/tests/test_readme.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/__init__.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/binary_mapper.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/finite_scalar_quantization.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/latent_quantization.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/lookup_free_quantization.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/random_projection_quantizer.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/residual_fsq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/residual_lfq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/residual_sim_vq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/sim_vq.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/utils.py +0 -0
- {vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/vector_quantize_pytorch.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: vector-quantize-pytorch
|
|
3
|
-
Version: 1.27.
|
|
3
|
+
Version: 1.27.4
|
|
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
|
|
@@ -6,9 +6,10 @@ from functools import partial, cache
|
|
|
6
6
|
from itertools import zip_longest
|
|
7
7
|
|
|
8
8
|
import torch
|
|
9
|
-
from torch import nn, Tensor, arange, cat
|
|
10
|
-
from torch.nn import Module, ModuleList
|
|
11
9
|
import torch.nn.functional as F
|
|
10
|
+
from torch import nn, Tensor, tensor, arange, cat
|
|
11
|
+
from torch.nn import Module, ModuleList
|
|
12
|
+
|
|
12
13
|
import torch.distributed as dist
|
|
13
14
|
from vector_quantize_pytorch.vector_quantize_pytorch import VectorQuantize
|
|
14
15
|
|
|
@@ -172,6 +173,7 @@ class ResidualVQ(Module):
|
|
|
172
173
|
mlp_kwargs: dict = dict(),
|
|
173
174
|
beam_size = None,
|
|
174
175
|
eval_beam_size = None,
|
|
176
|
+
beam_score_quantizer_weights: list[float] | None = None,
|
|
175
177
|
**vq_kwargs
|
|
176
178
|
):
|
|
177
179
|
super().__init__()
|
|
@@ -236,6 +238,13 @@ class ResidualVQ(Module):
|
|
|
236
238
|
self.beam_size = default(beam_size, eval_beam_size)
|
|
237
239
|
self.eval_beam_size = eval_beam_size
|
|
238
240
|
|
|
241
|
+
# able to assign a different weight for the scoring at each quantizer layer
|
|
242
|
+
|
|
243
|
+
beam_score_quantizer_weights = default(beam_score_quantizer_weights, [1.] * num_quantizers)
|
|
244
|
+
assert len(beam_score_quantizer_weights) == num_quantizers
|
|
245
|
+
|
|
246
|
+
self.register_buffer('beam_score_weights', tensor(beam_score_quantizer_weights), persistent = False)
|
|
247
|
+
|
|
239
248
|
# setting up the MLPs for implicit neural codebooks
|
|
240
249
|
|
|
241
250
|
self.mlps = None
|
|
@@ -427,6 +436,8 @@ class ResidualVQ(Module):
|
|
|
427
436
|
|
|
428
437
|
for quantizer_index, (vq, maybe_mlp) in enumerate(zip(self.layers, maybe_code_transforms)):
|
|
429
438
|
|
|
439
|
+
is_last_step = (quantizer_index == (len(self.layers) - 1)) if not should_quantize_dropout else quantizer_index == rand_quantize_dropout_index
|
|
440
|
+
|
|
430
441
|
if should_quantize_dropout and quantizer_index > rand_quantize_dropout_index:
|
|
431
442
|
all_indices = pad_at_dim(all_indices, (0, 1), value = -1, dim = -1)
|
|
432
443
|
all_losses = pad_at_dim(all_losses, (0, 1), value = 0, dim = -1)
|
|
@@ -470,7 +481,8 @@ class ResidualVQ(Module):
|
|
|
470
481
|
|
|
471
482
|
if is_beam_search:
|
|
472
483
|
|
|
473
|
-
|
|
484
|
+
score_weight = self.beam_score_weights[quantizer_index]
|
|
485
|
+
search_scores = einx.add('... j, ... j k -> ... (j k)', search_scores, -loss * score_weight)
|
|
474
486
|
|
|
475
487
|
residual = rearrange(residual, '... j d -> ... j 1 d')
|
|
476
488
|
quantized_out = rearrange(quantized_out, '... j d -> ... j 1 d')
|
|
@@ -506,8 +518,10 @@ class ResidualVQ(Module):
|
|
|
506
518
|
|
|
507
519
|
# handle sort and selection of highest beam size
|
|
508
520
|
|
|
509
|
-
if
|
|
510
|
-
|
|
521
|
+
layer_beam_size = beam_size if not is_last_step else 1
|
|
522
|
+
|
|
523
|
+
if search_scores.shape[-1] > layer_beam_size:
|
|
524
|
+
search_scores, select_indices = search_scores.topk(layer_beam_size, dim = -1)
|
|
511
525
|
|
|
512
526
|
residual = batch_select(residual, select_indices, '* k d')
|
|
513
527
|
quantized_out = batch_select(quantized_out, select_indices, '* k d')
|
|
@@ -526,12 +540,6 @@ class ResidualVQ(Module):
|
|
|
526
540
|
# handle beam search
|
|
527
541
|
|
|
528
542
|
if is_beam_search:
|
|
529
|
-
top_index = search_scores.argmax(dim = -1, keepdim = True)
|
|
530
|
-
|
|
531
|
-
quantized_out = batch_select(quantized_out, top_index, '* k d')
|
|
532
|
-
all_indices = batch_select(all_indices, top_index, '* k l')
|
|
533
|
-
all_losses = batch_select(all_losses, top_index, '* k l')
|
|
534
|
-
all_residuals = batch_select(all_residuals, top_index, '* k l d')
|
|
535
543
|
|
|
536
544
|
quantized_out, all_indices, all_losses, all_residuals = [t[..., 0, :] for t in (quantized_out, all_indices, all_losses, all_residuals)]
|
|
537
545
|
|
|
@@ -545,13 +553,19 @@ class ResidualVQ(Module):
|
|
|
545
553
|
|
|
546
554
|
# handle updating ema
|
|
547
555
|
|
|
548
|
-
if self.
|
|
556
|
+
if self.training:
|
|
549
557
|
for vq, layer_input, indices in zip(self.layers, all_residuals.unbind(dim = -2), all_indices.unbind(dim = -1)): # in the case of quantize dropout, zip will terminate with the shorter sequence, which should be all_residuals
|
|
550
|
-
|
|
558
|
+
|
|
559
|
+
if self.vq_is_ema_updating:
|
|
560
|
+
vq.update_ema_indices(layer_input, indices, mask = mask)
|
|
561
|
+
|
|
562
|
+
batch_samples = layer_input[mask] if exists(mask) else layer_input
|
|
563
|
+
vq.expire_codes_(batch_samples)
|
|
551
564
|
|
|
552
565
|
# if shared codebook, update ema only at end
|
|
553
566
|
|
|
554
|
-
if self.training and self.shared_codebook
|
|
567
|
+
if self.training and self.shared_codebook:
|
|
568
|
+
|
|
555
569
|
shared_layer = first(self.layers)
|
|
556
570
|
shared_layer._codebook.update_ema()
|
|
557
571
|
shared_layer.update_in_place_optimizer()
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.github/workflows/build.yml
RENAMED
|
File without changes
|
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/.github/workflows/test.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_fsq.py
RENAMED
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_lfq.py
RENAMED
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/examples/autoencoder_sim_vq.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/tests/test_latent_quantization.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/sim_vq.py
RENAMED
|
File without changes
|
{vector_quantize_pytorch-1.27.0 → vector_quantize_pytorch-1.27.4}/vector_quantize_pytorch/utils.py
RENAMED
|
File without changes
|
|
File without changes
|