You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VQ-VAEs are traditionally trained with the straight-through estimator (STE). During the backwards pass, the gradient flows _around_ the VQ layer rather than _through_ it. The <ahref="https://arxiv.org/abs/2410.06424">rotation trick paper</a> proposes to transform the gradient _through_ the VQ layer so the relative angle and magnitude between the input vector and quantized output are encoded into the gradient. You can enable or disable this feature with ```rotation_trick=True/False``` in the ```VectorQuantize``` class.
128
+
129
+
```python
130
+
from vector_quantize_pytorch import VectorQuantize
131
+
132
+
vq_layer = VectorQuantize(
133
+
dim=256,
134
+
codebook_size=256,
135
+
rotation_trick=True, # Set to False to use the STE gradient estimator or True to use the rotation trick.
136
+
)
137
+
```
138
+
125
139
## Increasing codebook usage
126
140
127
141
This repository will contain a few techniques from various papers to combat "dead" codebook entries, which is a common problem when using vector quantizers.
reinmax=False, # using reinmax for improved straight-through, assuming straight through helps at all
815
816
sync_codebook=None,
816
817
sync_affine_param=False,
@@ -821,7 +822,7 @@ def __init__(
821
822
manual_in_place_optimizer_update=False,
822
823
affine_param=False,
823
824
affine_param_batch_decay=0.99,
824
-
affine_param_codebook_decay=0.9,
825
+
affine_param_codebook_decay=0.9,
825
826
sync_update_v=0., # the v that controls optimistic vs pessimistic update for synchronous update rule (21) https://minyoungg.github.io/vqtorch/assets/draft_050523.pdf
0 commit comments