Skip to content

run: blackjax with too few JAX devices runs its chains vectorized (#506) - #507

Merged
jdeast merged 1 commit into
masterfrom
fix/blackjax-device-count
Oct 28, 2026
Merged

jdeast merged 1 commit into
masterfrom
fix/blackjax-device-count

Conversation

@jdeast

@jdeast jdeast commented Oct 28, 2026

Copy link
Copy Markdown
Owner

Fixes #506.

Cause

The nightly failure was not an upstream release. The locked Python 3.13 shard failed with the same error. pymc runs blackjax's chain_method: parallel through jax.pmap, one chain per device, without checking the device count. Importing pymc.sampling.jax forces 100 host devices through XLA_FLAGS, but that only works if the JAX backend has not started. When an earlier test file on the same xdist worker has already touched JAX, the process has one device. Two chains then crash with cannot select an axis to squeeze out ... shape=(2, 2). The failure depends on which file runs first on a worker, which is why PR #505's own CI passed.

The failure reproduces on the locked JAX 0.11.2 in a plain script. Calling jax.devices() before importing pymc gives one device, and parallel crashes while vectorized samples. Without that call there are 100 devices and parallel works.

Change

  • run.py: when blackjax would get fewer devices than chains, warn and run the chains vectorized. numpyro is left alone because its MCMC already warns and runs the chains sequentially.
  • tests/test_flat_logit_raw.py: blackjax samples vectorized, so the test no longer depends on which file ran first on its worker.
  • New tests/test_blackjax_chain_method.py covers the helper.
  • samplers.md documents the switch.

The new tests and the four-backend flat-raw test pass locally in a session that starts JAX before they run.

🤖 Generated with Claude Code

pymc maps blackjax's chain_method: parallel onto jax.pmap, one chain per
device, with no device check. Importing pymc.sampling.jax forces 100 host
devices, but only if the JAX backend has not started; once anything in the
process has touched JAX there is one device and two chains crash with
"cannot select an axis to squeeze out". The nightly hit this through an
earlier test file on the same xdist worker (the locked 3.13 shard failed
identically, so no upstream release was involved).

run.py now warns and switches blackjax to vectorized when the devices are
fewer than the chains. numpyro is left alone: its MCMC already warns and
runs the chains sequentially. The flat-raw test samples blackjax
vectorized so it no longer depends on which file ran first on its worker.

Fixes #506

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jdeast
jdeast merged commit d216e0e into master Oct 28, 2026
20 checks passed
@jdeast
jdeast deleted the fix/blackjax-device-count branch October 28, 2026 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nightly: suite fails against freshly resolved dependencies

1 participant