Skip to content

Commit

Permalink
revert uneeded fix #120
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed May 5, 2024
1 parent 6dbb3ed commit 4a643eb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "vector-quantize-pytorch"
version = "1.14.11"
version = "1.14.12"
description = "Vector Quantization - Pytorch"
authors = [
{ name = "Phil Wang", email = "[email protected]" }
Expand Down
11 changes: 2 additions & 9 deletions vector_quantize_pytorch/lookup_free_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,6 @@ def log(t, eps = 1e-5):
def entropy(prob):
return (-prob * log(prob)).sum(dim=-1)

# distance

def euclidean_distance_squared(x, y):
x2 = reduce(x ** 2, '... n d -> ... n 1', 'sum')
y2 = reduce(y ** 2, 'n d -> n', 'sum')
xy = einsum('... i d, j d -> ... i j', x, y) * -2
return x2 + xy + y2

# class

class LFQ(Module):
Expand Down Expand Up @@ -226,7 +218,8 @@ def forward(
# entropy aux loss

if self.training:
distance = euclidean_distance_squared(original_input, self.codebook)
# the same as euclidean distance up to a constant
distance = -2 * einsum('... i d, j d -> ... i j', original_input, self.codebook)

prob = (-distance * inv_temperature).softmax(dim = -1)

Expand Down

0 comments on commit 4a643eb

Please sign in to comment.