DiVeQ: Differentiable Vector Quantization Using the Reparameterization Trick
Mohammad Hassan Vali, Tom Bäckström, Arno Solin
TL;DR
Vector quantization in neural networks is non-differentiable due to hard nearest-neighbor assignments, hindering end-to-end training. The authors introduce DiVeQ, a differentiable surrogate using directional reparameterization that preserves hard forward quantization while enabling gradient flow, and SF-DiVeQ, which quantizes along line segments between codewords to improve codebook utilization. Across VQ-VAE and VQGAN tasks on multiple image datasets, DiVeQ and SF-DiVeQ consistently surpass prior approaches (e.g., STE, EMA, RT, ST-GS, NSVQ) in reconstruction quality and generation fidelity, without auxiliary losses or temperature schedules. SF-DiVeQ additionally avoids codebook misalignment and eliminates heuristic codebook replacement, acting as a robust, drop-in differentiable quantization option for compression and generative models. These methods offer practical gains for end-to-end training of discrete latent models and broaden the applicability of differentiable quantization techniques in deep learning.
Abstract
Vector quantization is common in deep models, yet its hard assignments block gradients and hinder end-to-end training. We propose DiVeQ, which treats quantization as adding an error vector that mimics the quantization distortion, keeping the forward pass hard while letting gradients flow. We also present a space-filling variant (SF-DiVeQ) that assigns to a curve constructed by the lines connecting codewords, resulting in less quantization error and full codebook usage. Both methods train end-to-end without requiring auxiliary losses or temperature schedules. On VQ-VAE compression and VQGAN generation across various data sets, they improve reconstruction and sample quality over alternative quantization approaches.
