`lax.scan` with `bool_` carry and dynamic scatter index silently produces wrong results under `vmap` on TPU
Author: matomaticalCreated May 27, 2026Updated Sep 29, 2026
LabelsbugXLATPUtype:Bug
Description
jax.lax.scan with a bool_ carry array silently produces incorrect results on TPU when the scan body scatters at an index that varies across a vmap batch. The bug worsens with batch size, kicking in around batch ~1500.
Minimal reproducer:
import jax
import jax.numpy as jnp
def scan_scatter_bool(indices):
def body(arr, idx):
return arr.at[idx].set(True), None
arr, _ = jax.lax.scan(body, jnp.zeros(5, dtype=jnp.bool_), indices)
return arr.sum()
# Each element gets a rotated permutation of [0,1,2,3,4].
# Every element sets all 5 positions, so the correct answer is always 5.
xs = jnp.arange(10000)
all_indices = jax.vmap(lambda x: (jnp.arange(5) + x) % 5)(xs)
results = jax.vmap(scan_scatter_bool)(all_indices)
print(f"mean={float(results.mean()):.2f}, wrong={int((results != 5).sum())}/10000")
# Observed output on TPU: mean=1.49, wrong=9591/10000All four of the following are required:
lax.scancarry hasdtype=jnp.bool_. Using int32 carry but identical logic (.set(1)instead of.set(True)) works correctly.- Scatter index varies across the
vmapbatch (even a simple rotation like(arange + x) % n). Using constant indices across the batch works. - TPU backend with
libtpu >= 0.0.13. Switching to CPU backend, it works. - Batch size > ~1500. Small batches are fine.
System info (python version, jaxlib version, accelerator, etc.)
Example environment info (one of several environments tested, see below):
>>> import jax; jax.print_environment_info()
jax: 0.10.1
jaxlib: 0.10.1
numpy: 2.4.6
python: 3.14.3 (main, Feb 3 2026, 22:52:18) [Clang 21.1.4 ]
device info: TPU v4-1, 1 local devices"
process_count: 1
platform: uname_result(system='Linux', node='t1v-n-ab15a7e0-w-0', release='5.19.0-1022-gcp', version='#24~22.04.1-Ubuntu SMP Sun Apr 23 09:51:08 UTC 2023', machine='x86_64')This appears to be a regression since libtpu 0.0.13. The jax/jaxlib version appears to be irrelevant.
| jax | jaxlib | libtpu | Bug? |
|---|---|---|---|
| 0.5.3 | 0.5.3 | 0.0.11.4 | no |
| 0.5.3 | 0.5.3 | 0.0.12 | no |
| 0.5.3 | 0.5.3 | 0.0.13 | yes |
| 0.5.3 | 0.5.3 | 0.0.14 | yes |
| 0.6.0 | 0.6.0 | 0.0.12 | no |
| 0.6.0 | 0.6.0 | 0.0.13 | yes |
| 0.6.0 | 0.6.0 | 0.0.14–0.0.17 | yes |
| 0.6.1 | 0.6.1 | 0.0.15 | yes |
| 0.6.2 | 0.6.2 | 0.0.17 | yes |
| 0.10.0 | 0.10.0 | 0.0.40 | yes |
| 0.10.0 | 0.10.0 | CPU | no |
Source: jax-ml/jax