Restructuring Vector Quantization with the Rotation Trick

Christopher Fifty, Ronald G. Junkins, Dennis Duan, Aniketh Iyengar, Jerry W. Liu +3 more
10/8/2024
cs.LGcs.CV

Official code: cfifty/rotation_trick (173 stars, last commit 2025-04-01). 1 more implementation below.

Abstract

Vector Quantized Variational AutoEncoders (VQ-VAEs) are designed to compress a continuous input to a discrete latent space and reconstruct it with minimal distortion. They operate by maintaining a set of vectors -- often referred to as the codebook -- and quantizing each encoder output to the nearest vector in the codebook. However, as vector quantization is non-differentiable, the gradient to the encoder flows around the vector quantization layer rather than through it in a straight-through approximation. This approximation may be undesirable as all information from the vector quantization operation is lost. In this work, we propose a way to propagate gradients through the vector quantization layer of VQ-VAEs. We smoothly transform each encoder output into its corresponding codebook vector via a rotation and rescaling linear transformation that is treated as a constant during backpropagation. As a result, the relative magnitude and angle between encoder output and codebook vector becomes encoded into the gradient as it propagates through the vector quantization layer and back to the encoder. Across 11 different VQ-VAE training paradigms, we find this restructuring improves reconstruction metrics, codebook utilization, and quantization error. Our code is available at https://github.com/cfifty/rotation_trick.

View on arXivView PDF

Code Implementations(2)

17310Shell, PythonOct 8, 20241 years ago
PyTorchMIT

Vector (and Scalar) Quantization, in Pytorch

3,980333PythonJun 9, 20206 months agoMIT
artificial-intelligencedeep-learningpytorchscalar-quantizationvector-quantization

Similar Papers

Cite this paper

@article{fifty2024restructuring,
  title  = {Restructuring Vector Quantization with the Rotation Trick},
  author = {Christopher Fifty and Ronald G. Junkins and Dennis Duan and Aniketh Iyengar and Jerry W. Liu and Ehsan Amid and Sebastian Thrun and Christopher Ré},
  year   = {2024},
  eprint = {2410.06424},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2410.06424v2},
  journal = {ICLR 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2410.06424.svg)](https://codeofpaper.com/paper/2410.06424)

Discussion