arXiv:2610.07786cs.LGOct 2026

Manuscript Offprint

arXiv:2610.07786

Extending Pathwise Gradients to Discrete Random Variables via Finite-Order Relaxation

Donghan He, Luhuan Wu

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Pathwise gradients are preferred for continuous random variables because they are unbiased, low variance, and work with a single sample. For discrete variables, pathwise gradients cannot generally be exact for every differentiable function. We propose a general framework for constructing Finite-order exact pathwise gradient estimators (Fini) for discrete variables, which are unbiased for all polynomials up to degree D. Among all admissible solutions, our estimator is the unique least-norm solution and has minimum weight variance. For common discrete distributions such as the Poisson, our construction yields native, closed-form estimators tailored to each distribution, implementable in a few lines of code. They preserve exact discrete forward samples without continuous relaxation, temperature tuning, or augmented representations. At matched polynomial exactness, they avoid the excess weight variance of non-native representations. We also bound bias for smooth downstream functions, showing how accuracy beyond polynomials depends on the first unmatched derivative and the sampling distribution. In experiments our low-order estimators match or outperform tuned baselines across linear, nonlinear and hierarchical latent-variable models, while out-speeding competitors in every runtime benchmark.

1 INTRODUCTION

For Monte Carlo (MC) gradient estimation in continuous random variables, the pathwise gradient estimator is the recommended default for its unbiasedness, typically low variance, and implementation simplicity (Mohamed et al., 2020). Pathwise gradients measure sensitivity among sample paths, combining how a realized sample changes with the distribution's parameters with how the downstream function changes with the sample. Thus it requires differentiability of both the sample path and the downstream function. However, discrete variables, commonly used in neural sequence models and deep generative models (Ranganath et al., 2015; Vafaii et al., 2024; Li et al., 2024), do not generally admit a pathwise estimator that is unbiased for all differentiable functions. This leaves a gap for MC gradient estimation in discrete distributions.

Existing gradient estimators for discrete variables navigate a bias–variance–computation tradeoff. Score-function estimators are unbiased but often have high variance; reducing it may require more samples or carefully designed control variates, adding computational or implementation cost (Ranganath et al., 2014; Mohamed et al., 2020). Measure-valued derivatives (MVD) and discrete General One-sample gradients can reduce variance through additional downstream evaluations, which become expensive in high-dimensional models (Pflug, 1989; Rosca et al., 2019; Cong et al., 2019). Biased alternatives instead approximate the backward pass, trading exactness for inexpensive gradients. Straight-through (ST) estimators preserve the hard sample but substitute a surrogate backward derivative, introducing bias (Bengio et al., 2013). For categorical variables, the Gumbel–Softmax trick (Jang et al., 2017; Maddison et al., 2017) instead replaces the hard sample with a differentiable continuous approximation controlled by temperature, allowing gradients through the relaxed sample. Lowering the temperature improves bias but can increase gradient variance, making it an additional hyperparameter to tune. Beyond categorical variables, researchers use the Gumbel–Softmax trick to approximate gradients for discrete variable such as Poisson (Li et al., 2024); however, these methods

Our extended pathwise gradient prescribes exactness hierarchy up to D

Figure

Continuous Pathwise Gradient is exact for all differentiable f

Figure

w*: optimal solution

w: another solution

r: excess component

Listing 1: Poisson Fini-2 and Fini-3 in torch.

1 ... 2 rate = eta.exp() 3 z_hard = Poisson(rate).sample() 4 5 # order 2: 6 w = 0.5 * (z_hard + rate) 7 # order 3: 8 # w = (5rate/12 9 # + (8rate+1)z_hard/(12rate) 10 # - z_hard**2/(12*rate)) 11 12 z = z_hard + w.detach() * (eta - eta.detach()) 13 ...

Figure 1: Finite-order pathwise gradients. Left: pathwise gradients are unbiased for all differentiable functions - this is too rigid for discrete variables, so we relax the unbiasedness requirement to low-order polynomials; Center: generally, there are many solutions to the finite-order unbiasedness requirement; we use the least-norm principle to select the order-D unbiased solution, avoiding excess weight variance; Right: as an example, Fini-2 and 3 for Poisson reduce to a few lines of code.

need to approximate one-dimensional variables with K-dimensional categorical variables, and inherit the temperature parameter, both adding computational overhead.

Recently, Liu et al. (2023) interpret categorical ST estimators as a first-order numerical method and propose a second-order ST method, ReinMax. ReinMax is unbiased for degree-2 polynomials, whereas first-order ST is unbiased for linear functions. This improvement enables ReinMax to outmatch both biased and unbiased methods consistently on various benchmarks. Nonetheless, applying ReinMax to other discrete variables again requires approximation, which can lead to statistical and computational overheads. Can we adapt pathwise gradients to discrete variables beyond categoricals by relaxing the unbiasedness requirement in a principled way?

We introduce a general recipe, Fini, that applies to a range of discrete variables: As shown in Fig. 1, we require the pathwise estimator to be unbiased for low-degree polynomials rather than for every differentiable function; this weaker requirement admits many solutions, so we select the least-norm solution. This leads to several mathematical, statistical, and computational benefits, shown below.

References (29)