jax
jax copied to clipboard
jax.scipy.stats.laplace.cdf gives NaN gradients in the tails (unselected branch overflows)
Description
Description
laplace.cdf computes both branches of a lax.select unconditionally. When |x - loc| / scale exceeds
the exponential overflow threshold (~88 in float32, ~709 in float64) the unselected branch is inf; the
forward value is still correct, but the derivatives with respect to x, loc and scale are NaN
instead of 0. In float32 this happens for inputs as ordinary as x=0, loc=10, scale=0.1.
Steps to reproduce
import jax
from jax.scipy.stats import laplace
print(jax.grad(lambda x: laplace.cdf(x, 10.0, 0.1))(0.0)) # nan, expected 0.0
Expected
Finite gradients (0 far in the tails), as the forward value is finite.
System info (python version, jaxlib version, accelerator, etc.)
Environment
JAX / jaxlib 0.11.2 (the latest release, CPU) and 0.10.1, Python 3.12, Ubuntu 24.04, x86_64
#38651