vector-quantize-pytorch 1.12.4__tar.gz → 1.12.6__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.12.4 → vector_quantize_pytorch-1.12.6}/PKG-INFO +1 -1
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/README.md +1 -1
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/setup.py +1 -1
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/residual_fsq.py +5 -2
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch.egg-info/PKG-INFO +2 -2
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/LICENSE +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/setup.cfg +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/__init__.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/finite_scalar_quantization.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/lookup_free_quantization.py +2 -2
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/random_projection_quantizer.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/residual_lfq.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/residual_vq.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch/vector_quantize_pytorch.py +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch.egg-info/SOURCES.txt +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch.egg-info/dependency_links.txt +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch.egg-info/requires.txt +0 -0
- {vector_quantize_pytorch-1.12.4 → vector_quantize_pytorch-1.12.6}/vector_quantize_pytorch.egg-info/top_level.txt +0 -0
|
@@ -345,7 +345,7 @@ quantizer = LFQ(
|
|
|
345
345
|
|
|
346
346
|
image_feats = torch.randn(1, 16, 32, 32)
|
|
347
347
|
|
|
348
|
-
quantized, indices, entropy_aux_loss = quantizer(image_feats)
|
|
348
|
+
quantized, indices, entropy_aux_loss = quantizer(image_feats, inv_temperature=100.) # you may want to experiment with temperature
|
|
349
349
|
|
|
350
350
|
# (1, 16, 32, 32), (1, 32, 32), (1,)
|
|
351
351
|
|
|
@@ -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.12.
|
|
6
|
+
version = '1.12.6',
|
|
7
7
|
license='MIT',
|
|
8
8
|
description = 'Vector Quantization - Pytorch',
|
|
9
9
|
long_description_content_type = 'text/markdown',
|
|
@@ -19,6 +19,9 @@ from einops import rearrange, repeat, reduce, pack, unpack
|
|
|
19
19
|
def exists(val):
|
|
20
20
|
return val is not None
|
|
21
21
|
|
|
22
|
+
def first(l):
|
|
23
|
+
return l[0]
|
|
24
|
+
|
|
22
25
|
def default(val, d):
|
|
23
26
|
return val if exists(val) else d
|
|
24
27
|
|
|
@@ -59,7 +62,7 @@ class ResidualFSQ(Module):
|
|
|
59
62
|
scales = []
|
|
60
63
|
|
|
61
64
|
for ind in range(num_quantizers):
|
|
62
|
-
scales.append(levels_tensor ** -ind)
|
|
65
|
+
scales.append((levels_tensor - 1) ** -ind)
|
|
63
66
|
|
|
64
67
|
fsq = FSQ(
|
|
65
68
|
levels = levels,
|
|
@@ -146,7 +149,7 @@ class ResidualFSQ(Module):
|
|
|
146
149
|
x = self.project_in(x)
|
|
147
150
|
|
|
148
151
|
quantized_out = 0.
|
|
149
|
-
residual = x
|
|
152
|
+
residual = first(self.layers).bound(x)
|
|
150
153
|
|
|
151
154
|
all_indices = []
|
|
152
155
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -215,13 +215,13 @@ class LFQ(Module):
|
|
|
215
215
|
|
|
216
216
|
prob = (-distance * inv_temperature).softmax(dim = -1)
|
|
217
217
|
|
|
218
|
-
per_sample_entropy = entropy(prob).mean()
|
|
219
|
-
|
|
220
218
|
# account for mask
|
|
221
219
|
|
|
222
220
|
if exists(mask):
|
|
223
221
|
prob = prob[mask]
|
|
224
222
|
|
|
223
|
+
per_sample_entropy = entropy(prob).mean()
|
|
224
|
+
|
|
225
225
|
# distribution over all available tokens in the batch
|
|
226
226
|
|
|
227
227
|
avg_prob = reduce(prob, '... c d -> c d', 'mean')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|