jax
jax copied to clipboard
jax.vmap produces different results from eager for a function involving jnp.round, jnp.inner, jax.lax.collapse, jnp.vecdot, and jnp.remainder
Description
jax.vmap with batch size 1 produces results that differ from eager execution by up to 0.000732. The eager output, JIT output, and JIT determinism checks all pass — only vmap disagrees.
Minimal Reproducer
import jax
import jax.numpy as jnp
key = jax.random.PRNGKey(940156)
key, k1 = jax.random.split(key)
t1 = jax.random.normal(k1, (12, 6))
key, k2 = jax.random.split(key)
t2 = jax.random.normal(k2, (6, 8))
def f(t1, t2):
a = jnp.round(t1)
b = jnp.atleast_1d(jnp.inner(a, t1))
c = jax.lax.collapse(b, 0, 2)
d = jnp.atleast_1d(jnp.vecdot(c, c))
e = jnp.einsum('ij,jk->ik', t1, t2)
return jnp.remainder(d, jnp.maximum(jnp.abs(e), 0.1))
eager = f(t1, t2)
vmap_out = jax.vmap(f)(t1[None], t2[None])[0]
print('eager:', eager[:3])
print('vmap: ', vmap_out[:3])
print('max_diff:', jnp.abs(eager - vmap_out).max()) # 0.000732
Expected vs Actual
- eager: finite, correct values
- jit: matches eager ✅
- vmap batch-1: differs by up to
0.000732❌
System info (python version, jaxlib version, accelerator, etc.)
jax: 0.10.1 jaxlib: 0.10.1 numpy: 2.4.6 python: 3.12.13 device: cpu
Hello - in general this kind of thing is expected: with floating point math, different ways of expressing the "same" operation will not in general lead to bitwise-equivalent results. This is not true just for JAX, but for any system that uses floating point arithmetic.