vector-quantize-pytorch 1.6.32__tar.gz → 1.7.1__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.6.32 → vector_quantize_pytorch-1.7.1}/PKG-INFO +1 -1
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/setup.py +1 -1
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch/residual_vq.py +15 -1
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch/vector_quantize_pytorch.py +4 -1
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch.egg-info/PKG-INFO +1 -1
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/LICENSE +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/README.md +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/setup.cfg +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch/__init__.py +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch/random_projection_quantizer.py +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch.egg-info/SOURCES.txt +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch.egg-info/dependency_links.txt +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch.egg-info/requires.txt +0 -0
- {vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch.egg-info/top_level.txt +0 -0
|
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|
|
3
3
|
setup(
|
|
4
4
|
name = 'vector_quantize_pytorch',
|
|
5
5
|
packages = find_packages(),
|
|
6
|
-
version = '1.
|
|
6
|
+
version = '1.7.1',
|
|
7
7
|
license='MIT',
|
|
8
8
|
description = 'Vector Quantization - Pytorch',
|
|
9
9
|
long_description_content_type = 'text/markdown',
|
|
@@ -28,7 +28,9 @@ class ResidualVQ(nn.Module):
|
|
|
28
28
|
def __init__(
|
|
29
29
|
self,
|
|
30
30
|
*,
|
|
31
|
+
dim,
|
|
31
32
|
num_quantizers,
|
|
33
|
+
codebook_dim = None,
|
|
32
34
|
shared_codebook = False,
|
|
33
35
|
heads = 1,
|
|
34
36
|
quantize_dropout = False,
|
|
@@ -39,11 +41,17 @@ class ResidualVQ(nn.Module):
|
|
|
39
41
|
):
|
|
40
42
|
super().__init__()
|
|
41
43
|
assert heads == 1, 'residual vq is not compatible with multi-headed codes'
|
|
44
|
+
codebook_dim = default(codebook_dim, dim)
|
|
45
|
+
codebook_input_dim = codebook_dim * heads
|
|
46
|
+
|
|
47
|
+
requires_projection = codebook_input_dim != dim
|
|
48
|
+
self.project_in = nn.Linear(dim, codebook_input_dim) if requires_projection else nn.Identity()
|
|
49
|
+
self.project_out = nn.Linear(codebook_input_dim, dim) if requires_projection else nn.Identity()
|
|
42
50
|
|
|
43
51
|
self.num_quantizers = num_quantizers
|
|
44
52
|
|
|
45
53
|
self.accept_image_fmap = accept_image_fmap
|
|
46
|
-
self.layers = nn.ModuleList([VectorQuantize(accept_image_fmap = accept_image_fmap, **kwargs) for _ in range(num_quantizers)])
|
|
54
|
+
self.layers = nn.ModuleList([VectorQuantize(dim = codebook_dim, codebook_dim = codebook_dim, accept_image_fmap = accept_image_fmap, **kwargs) for _ in range(num_quantizers)])
|
|
47
55
|
|
|
48
56
|
self.quantize_dropout = quantize_dropout and num_quantizers > 1
|
|
49
57
|
|
|
@@ -114,6 +122,8 @@ class ResidualVQ(nn.Module):
|
|
|
114
122
|
):
|
|
115
123
|
num_quant, quant_dropout_multiple_of, return_loss, device = self.num_quantizers, self.quantize_dropout_multiple_of, exists(indices), x.device
|
|
116
124
|
|
|
125
|
+
x = self.project_in(x)
|
|
126
|
+
|
|
117
127
|
assert not (self.accept_image_fmap and exists(indices))
|
|
118
128
|
|
|
119
129
|
quantized_out = 0.
|
|
@@ -169,6 +179,10 @@ class ResidualVQ(nn.Module):
|
|
|
169
179
|
all_indices.append(embed_indices)
|
|
170
180
|
all_losses.append(loss)
|
|
171
181
|
|
|
182
|
+
# project out, if needed
|
|
183
|
+
|
|
184
|
+
quantized_out = self.project_out(quantized_out)
|
|
185
|
+
|
|
172
186
|
# whether to early return the cross entropy loss
|
|
173
187
|
|
|
174
188
|
if return_loss:
|
|
@@ -710,7 +710,7 @@ class VectorQuantize(nn.Module):
|
|
|
710
710
|
sample_codebook_temp = 1.,
|
|
711
711
|
straight_through = False,
|
|
712
712
|
reinmax = False, # using reinmax for improved straight-through, assuming straight through helps at all
|
|
713
|
-
sync_codebook =
|
|
713
|
+
sync_codebook = None,
|
|
714
714
|
sync_affine_param = False,
|
|
715
715
|
ema_update = True,
|
|
716
716
|
learnable_codebook = False,
|
|
@@ -760,6 +760,9 @@ class VectorQuantize(nn.Module):
|
|
|
760
760
|
straight_through = straight_through
|
|
761
761
|
)
|
|
762
762
|
|
|
763
|
+
if not exists(sync_codebook):
|
|
764
|
+
sync_codebook = distributed.is_initialized() and distributed.get_world_size() > 1
|
|
765
|
+
|
|
763
766
|
codebook_kwargs = dict(
|
|
764
767
|
dim = codebook_dim,
|
|
765
768
|
num_codebooks = heads if separate_codebook_per_head else 1,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{vector_quantize_pytorch-1.6.32 → vector_quantize_pytorch-1.7.1}/vector_quantize_pytorch/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|