Skip to content

Commit

Permalink
commit loss weighting for sim vq
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidrains committed Nov 12, 2024
1 parent 919a1b8 commit ce4a4fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 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.20.7"
version = "1.20.8"
description = "Vector Quantization - Pytorch"
authors = [
{ name = "Phil Wang", email = "lucidrains@gmail.com" }
Expand Down
7 changes: 6 additions & 1 deletion vector_quantize_pytorch/sim_vq.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
accept_image_fmap = False,
rotation_trick = True, # works even better with rotation trick turned on, with no straight through and the commit loss from input to quantize
input_to_quantize_commit_loss_weight = 0.25,
commitment_weight = 1.,
frozen_codebook_dim = None # frozen codebook dim could have different dimensions than projection
):
super().__init__()
Expand Down Expand Up @@ -74,6 +75,10 @@ def __init__(

self.input_to_quantize_commit_loss_weight = input_to_quantize_commit_loss_weight

# total commitment loss weight

self.commitment_weight = commitment_weight

@property
def codebook(self):
return self.code_transform(self.frozen_codebook)
Expand Down Expand Up @@ -132,7 +137,7 @@ def forward(

indices = inverse_pack(indices, 'b *')

return quantized, indices, commit_loss
return quantized, indices, commit_loss * self.commitment_weight

# main

Expand Down

0 comments on commit ce4a4fc

Please sign in to comment.