Skip to main content
Back

ANU Beats ReinMax With Two Gradient Estimators That Train Discrete AI Models Better

Two new gradient estimators fix ReinMax's variance problem, improving discrete VAE training across the board with a clean bias-variance tradeoff

Pro

Paper, Full Access
  • New estimators: ReinMax-Rao and ReinMax-CV reduce the high variance of the ReinMax gradient estimator for discrete latent variables.
  • Core fix: ReinMax's variance comes from a term that depends on the random discrete sample; both new methods reduce this via Rao-Blackwellization and control variates.
  • Results: Both estimators outperform ReinMax on discrete VAE training across most latent space configurations on MNIST.
  • Tradeoff: ReinMax-Rao wins at large latent spaces; ReinMax-CV balances bias and variance at intermediate sizes; both are ~3x slower than ReinMax.
  • Theory bonus: The paper reframes ReinMax through the trapezoidal rule, proving Heun's method is optimal within the second-order Runge-Kutta family.
  • Code: Implementation to be released upon paper acceptance; based on the original ReinMax codebase.

Training neural networks with discrete choices baked in -- think codebooks in image generators, token selectors in language models, or symbolic bottlenecks in structured models -- runs into a fundamental wall: backpropagation needs smooth, continuous gradients, but discrete sampling is a hard, non-differentiable operation. The workaround is to use a gradient estimator: a mathematical trick that approximates what the gradient would be if the discrete step were differentiable. Getting this approximation right is the difference between a model that trains well and one that stalls.

A new paper from the Australian National University, "Beyond ReinMax: Low-Variance Gradient Estimators for Discrete Latent Variables", takes aim at a specific weakness in the current state-of-the-art estimator and proposes two fixes that consistently outperform it on discrete variational autoencoders (VAEs).

The gradient estimator family tree

To understand what is new here, you need to know the landscape. Backpropagation is limited to computing gradients for continuous variables, and this limitation poses challenges for problems involving discrete latent variables. The dominant family of solutions is called Straight-Through (ST) estimators. The original ST estimator, introduced by Bengio et al. in 2013, is a blunt instrument: during the backward pass, it pretends the discrete sampling step was just the identity function, passing gradients through unchanged. This is fast and low-variance, but introduces significant bias.

Over the years, the community has layered on improvements:

  • Straight-Through Gumbel-Softmax (STGS): Uses the Gumbel-Softmax trick -- a way to smoothly relax a discrete categorical sample into a continuous approximation -- to get a less biased gradient. Tuning the temperature parameter trades off bias against variance.
  • Gumbel-Rao: Applies the Rao-Blackwell theorem (a classical statistics result that says: if you can average out randomness, your estimator gets lower variance without changing its expected value) to STGS by marginalizing over the Gumbel noise conditional on the sampled category.
  • ReinMax: Demonstrates that the Straight-Through heuristic works as a first-order approximation of the gradient, then proposes ReinMax, which achieves second-order accuracy by integrating Heun's method, a second-order numerical method for solving ODEs. ReinMax does not require Hessian or other second-order derivatives, thus having negligible computation overhead.

ReinMax was a genuine step forward -- lower bias than anything before it, at essentially no extra compute cost. But it came with a catch.

The variance problem hiding in ReinMax

ReinMax can be viewed from a numerical ODE perspective as incorporating an approximation via Heun's method to reduce bias, but at the cost of high variance. Concretely, the paper shows that ReinMax can be decomposed into two Straight-Through estimators: one evaluated at the original parameters, and one evaluated at a shifted parameter that depends on the random discrete sample D. That second term is the culprit -- because it depends on the random variable, it fluctuates wildly across samples.

To verify this, the authors ran a simple diagnostic: they replaced the random D in that term with the deterministic argmax of the distribution. The result (called ReinMax-Argmax) had variance nearly as low as plain Straight-Through -- confirming the source of the problem. The standard deviation of ReinMax across 1024 gradient samples was 7.40, versus 2.73 for Straight-Through and 2.87 for ReinMax-Argmax. Of course, ReinMax-Argmax is useless in practice because swapping in the deterministic argmax destroys the unbiasedness of the estimator. But it proves the diagnosis is correct.

Two estimators, two strategies

The paper introduces two new estimators that reduce ReinMax's variance without simply collapsing back to the biased Straight-Through baseline.

ReinMax-Rao is the simpler of the two. The key insight is that the Straight-Through estimator and the Gumbel-Rao estimator are both approximations of the same true gradient, so they should be highly correlated. The authors swap the high-variance ST term inside ReinMax for the lower-variance Gumbel-Rao estimator, evaluated at the same shifted parameters. This reduces variance substantially, at the cost of a modest increase in bias. Conceptually, it is applying the Rao-Blackwell trick one level deeper than before -- inside ReinMax rather than inside STGS.

ReinMax-CV goes further by using a control variate to correct the bias introduced by the Rao approximation. A control variate is a correlated quantity whose expected value you know (or can estimate cheaply), which you subtract and add back to reduce variance without changing the mean. Here, the Straight-Through Gumbel-Softmax estimator serves as the control variate for the high-variance ST term, and the Gumbel-Rao estimator is used to estimate its expectation. The result sits between ReinMax and ReinMax-Rao on the bias-variance spectrum: lower variance than ReinMax, lower bias than ReinMax-Rao.

In pseudocode, the core idea looks like this:

# ReinMax decomposes as:
# grad = 2 * ST(D, theta_D) - 0.5 * ST(D, theta)
# where theta_D depends on the random sample D (high variance term)
# ReinMax-Rao: swap the high-variance ST(D, theta_D) for Gumbel-Rao
grad_rao = 2 * gumbel_rao(D, theta_D) - 0.5 * ST(D, theta)
# ReinMax-CV: use STGS as a control variate for ST(D, theta_D)
# eta is a tunable coefficient, GR estimates E[STGS]
grad_cv = (ST(D, theta_D) - eta * STGS(G, theta_D) + eta * GR(G, theta_D)) \
          - 0.5 * ST(D, theta)

A cleaner theoretical lens

Beyond the two new estimators, the paper makes a conceptual contribution: it offers a simpler way to understand why ReinMax works. The original ReinMax paper derived the estimator through the lens of numerical ODE methods -- specifically Heun's method, a second-order Runge-Kutta solver. The authors here show that the same math is more naturally understood as the trapezoidal rule for numerical integration: you want to approximate the integral of a gradient function over an interval, and the trapezoidal rule (averaging the values at both endpoints) is the most accurate thing you can do with only those two evaluations.

This reframing also explains why ReinMax is optimal within its class. The authors generalize ReinMax to the entire family of second-order Runge-Kutta methods (parameterized by a weighting coefficient beta) and show empirically that beta = 0.5 -- which recovers the original ReinMax -- is always best. From the trapezoidal rule perspective, this is obvious: any other value of beta shifts the endpoints of the approximating line off the actual curve, making the approximation worse. Higher-order methods like Simpson's rule would require evaluating the gradient at non-integer (non-one-hot) inputs, which is conceptually invalid for discrete models, or computing Hessians, which is computationally prohibitive.

Benchmark results

The experiments follow the standard protocol for this line of work: train discrete VAEs on MNIST with latent spaces of varying sizes (from 8x4 up to 64x8 categorical dimensions), and measure the Evidence Lower Bound (ELBO) -- the standard training objective for VAEs, where lower is better. The baselines include ST, STGS, Gumbel-Rao, GST-1.0, and ReinMax.

The ReinMax-Rao and ReinMax-CV estimators incorporate Rao-Blackwellisation and control variate techniques into ReinMax to reduce its variance, and demonstrate superior performance on training variational autoencoders with discrete latent spaces. The pattern in the results is telling:

  • ReinMax-Rao wins on the largest latent spaces (16x12 and 64x8), where variance is the dominant problem.
  • ReinMax-CV wins on intermediate settings, balancing bias and variance.
  • Both new estimators beat ReinMax on most configurations in both train and test ELBO.
  • The improvement is most pronounced at scale -- consistent with the theory that high-variance estimators hurt more as the problem gets harder.

The paper also notes an important caveat: the Gumbel-Rao Monte Carlo approximation (used in both new estimators) requires K=100 samples to estimate the conditional expectation, making ReinMax-Rao and ReinMax-CV roughly three times slower than ReinMax per step. This is a real cost to factor in.

When to use which estimator

The paper's results sketch a practical decision guide:

  • If your discrete latent space is small and simple, plain ReinMax or even STGS may be sufficient -- low-bias estimators tend to win in low-dimensional settings.
  • If your latent space is large and high-dimensional (many categories, many latent dimensions), ReinMax-Rao is the strongest choice -- variance dominates in these regimes and the Rao-Blackwell reduction pays off.
  • If you want a middle ground with better bias control than ReinMax-Rao, ReinMax-CV is the pick.
  • If speed is critical, stick with ReinMax -- the 3x slowdown from the Monte Carlo approximation is not always worth it.

Code will be made available upon acceptance of the paper. The work directly applies to any architecture that uses discrete categorical sampling in its forward pass: ReinMax-style models, discrete VAEs, models with learned discrete codebooks, and structured prediction models with categorical decisions. Backpropagation in VQ-VAE proceeds via the straight-through estimator, whereby gradients for the quantized representation are copied to the pre-quantized latent -- making better ST-family estimators directly relevant to that entire class of models as well.

The broader message is that the bias-variance tradeoff in gradient estimation is not a solved problem. ReinMax pushed the frontier on bias; this paper pushes back on variance. The trapezoidal rule interpretation suggests that going further in either direction requires fundamentally new tools -- either accepting non-one-hot evaluations or paying the cost of second-order information. For now, ReinMax-Rao and ReinMax-CV represent the practical optimum of what is achievable within the existing computational budget.