NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

DiVeQ: Differentiable Vector Quantization Using the Reparameterization Trick

Mohammad Hassan Vali, Tom Bäckström, Arno Solin

Vector Quantization (VQ) is a cornerstone of modern generative AI, powering everything from high-fidelity image compressors (like VQ-VAE) to state-of-the-art speech codecs. However, VQ suffers from a fundamental mathematical flaw: mapping a continuous value to a discrete codeword is a non-differentiable operation. This creates a "gradient block" that makes training these models notoriously difficult.

In their ICLR 2026 paper, Mohammad Hassan Vali and colleagues introduce DiVeQ, a clever method to bypass this block. By leveraging the reparameterization trick—the same mathematical magic that made Variational Autoencoders (VAEs) possible—DiVeQ allows gradients to flow freely without sacrificing the hard discrete assignments necessary for quantization.

The Problem: The Gradient Block

In a standard VQ layer, an encoder produces a continuous vector, which is then "snapped" to the nearest representative vector (codeword) in a codebook. Because the argmin operation used to find this nearest neighbor is "flat" (its derivative is zero almost everywhere), gradients cannot pass back to the encoder during the backward pass of training.

To fix this, researchers typically rely on the Straight-Through Estimator (STE). STE is essentially a "white lie" where the network pretends the gradient is 1 during the backward pass. While STE works in practice, it is mathematically biased. It often requires complex auxiliary losses, temperature schedules, and heuristic "codebook reset" tricks to prevent the model from ignoring half its codewords—a common failure mode known as codebook collapse.

The Solution: DiVeQ and SF-DiVeQ

The authors propose two main innovations to solve the non-differentiability of VQ operations:

  1. DiVeQ (Differentiable Vector Quantization): Instead of simply snapping a continuous vector to a codeword, DiVeQ treats quantization as the addition of an error vector: $z_q = z + \text{error}$. Using the reparameterization trick, the authors define a simulated error vector whose direction is aligned with the nearest codeword and whose magnitude matches the actual quantization distortion. This keeps the forward pass "hard" (discrete) but provides a mathematically sound, differentiable path for gradients to flow backward.
Comparison of standard VQ (left) with blocked gradients, and DiVeQ (right) which allows gradients to flow using a simulated error vector.
  1. SF-DiVeQ (Space-Filling DiVeQ): Building on the concept of "Space-Filling VQ," this variant quantizes inputs to a continuous curve made of line segments connecting codewords. This "dithering" approach ensures that the entire codebook is utilized, significantly reducing the gap between the latent representations and the codebook vectors.

Additionally, for methods prone to collapse, the authors introduce an importance-sampling-based replacement strategy that swaps unused codewords with popular ones, leading to faster and more stable training.

Key Insights and Geometric Consistency

A major "aha" moment in this research is the realization that you do not have to soften the forward pass (as seen in techniques like Gumbel-Softmax) to obtain gradients. By carefully modeling the direction of the quantization error, DiVeQ provides the encoder with a "compass" showing it how to move the latent vectors to reach better codewords.

Unlike previous noise-substitution methods that add random noise in all directions, DiVeQ ensures the simulated error is geometrically consistent with the nearest-neighbor operation.

Visualization of the simulated error distribution around a target codeword, demonstrating geometric consistency with a controlled noise variance.

Furthermore, a major cause of poor performance in VQ models is "internal codebook covariate shift"—where the encoder's output distribution drifts away from the codebook. SF-DiVeQ naturally pulls codewords into the high-density regions of the latent space, effectively self-correcting this drift without the need for extra loss terms.

Empirical Results

The researchers evaluated DiVeQ across three distinct domains, consistently outperforming standard methods like STE and Exponential Moving Average (EMA):

  • Image Compression (VQ-VAE): Evaluated on datasets like AFHQ, CelebA-HQ, FFHQ, and LSUN. SF-DiVeQ achieved the lowest LPIPS (perceptual loss) and highest SSIM/PSNR across almost all bitrates.
  • Image Generation (VQGAN): The proposed methods achieved significantly lower FID scores (measuring image realism). For example, on CelebA-HQ (9-bit), SF-DiVeQ hit an FID of 5.21, compared to STE’s 5.57 and NSVQ’s disastrous 70.4.
  • Speech Coding (DAC): On the CSTR VCTK dataset, the methods yielded higher PESQ (speech quality) and STOI (intelligibility) scores, proving the approach is robust across different data modalities.

Perhaps most importantly, these methods act as "drop-in" replacements. They do not require hyperparameter tuning for auxiliary losses, making them highly accessible for engineers.

Limitations and Future Work

While highly effective, the authors note a few areas for further exploration. SF-DiVeQ performs best with a "custom" initialization (training without VQ for a few epochs first) to let the latent space stabilize before the space-filling curve is constructed. Additionally, while the method isn't hyper-sensitive to the noise variance ($\sigma^2$), it still introduces a parameter that needs to be kept sufficiently small. Future work may involve applying these differentiable tricks to even more complex structures, such as hierarchical VQ or large-scale language model tokenizers.

Paper Citation: Mohammad Hassan Vali, Tom Bäckström, & Arno Solin. "DiVeQ: Differentiable Vector Quantization Using the Reparameterization Trick." Published as a conference paper at ICLR 2026.

Summary updated

BibTeX
@inproceedings{vali2026diveq,
  author = {Mohammad Hassan Vali and Tom Bäckström and Arno Solin},
  title = {{DiVeQ: Differentiable Vector Quantization Using the Reparameterization Trick}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=KRVnpTbx7R},
}
Figure