Skip to content

fix: message shape/size/ndim read the real JAX broadcast shape (jax 0.11 compat) - #1513

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/message-log-partition-tuple-shape
Aug 22, 2026
Merged

fix: message shape/size/ndim read the real JAX broadcast shape (jax 0.11 compat)#1513
Jammy2211 merged 1 commit into
mainfrom
feature/message-log-partition-tuple-shape

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Implements the fix specified in #1510 (merge this before the PyAutoNerves cap widen; the issue stays open until both legs land).

Root cause

jax 0.11 changed jnp.broadcast_arrays to return a tuple instead of a list (NumPy 2 alignment). MessageInterface.shape type-tested the container with isinstance(..., list), so on 0.11 the JAX branch stopped matching, fell through to .shape on a tuple, and every jnp-backed message construction raised AttributeError — the four test_jax_trace log-partition failures blocking the autonerves jax cap widen.

Why not the one-line isinstance widen

The JAX branch returned a hard-wired () shape, which is a live numerical bug on jax 0.10 today: for batched JAX messages, _broadcast_natural_parameters matched the shape[1:] == self.shape branch, inserted a spurious axis, and logpdf returned an (n, n) matrix of wrong values where NumPy returns the correct (n,) vector. size/ndim had no JAX branch at all and raised AttributeError for any jnp-backed message on both jax versions. Widening the isinstance would ship all of that unchanged.

Instead, shape now returns the real broadcast shape read off the container's first element (correct for both the list and tuple forms), and size/ndim derive from it.

Reviewer note: this changes numerical output for batched JAX-backed messages — from the incorrect broadcast-matrix result to the NumPy-matching vector. That is the intended correction. The size/ndim repair goes beyond the 0.11 regression (they were equally broken on 0.10) and is included deliberately: it is the same three-property cluster reading the same container, covered by the new test.

Regression test

test_message_shape_and_logpdf_match_numpy asserts NumPy/JAX parity of shape/size/ndim and of logpdf values and shape, scalar and batched, over Normal/Beta/Gamma. Mutation-checked: against the old () sentinel it fails 6 ways on jax 0.10 alone, so the sentinel cannot return silently.

Verification

Two Python 3.12 venvs (jax/jaxlib 0.10.2 and 0.11.1), [optional] extras installed (blackjax, nautilus-sampler — without them 18 tests silently skip):

tree jax 0.10.2 jax 0.11.1
main, unfixed 2024 passed, 3 skipped 4 failed, 2020 passed, 3 skipped
this branch 2030 passed, 3 skipped 2030 passed, 3 skipped
  • autofit_workspace_test/scripts/jax_assertions/: 9/10 pass in all four version-by-fix cells; only the pre-existing priors_xp_dispatch.py float32-tolerance failure, identical everywhere.
  • Downstream, against this branch: test_autogalaxy 1103 passed and test_autolens 532 passed, identical under jax 0.10.2 and 0.11.1; test_autonerves 157 passed under 0.11.1.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EauVX6vD9k1N4PXaEf2wvo


Generated by Claude Code

jax 0.11 changed jnp.broadcast_arrays to return a tuple instead of a list
(NumPy 2 alignment), so the isinstance(..., list) JAX branch in
MessageInterface.shape stopped matching and fell through to .shape on a
tuple — every jnp-backed message construction raised AttributeError.

Rather than widening the isinstance to (list, tuple), which would preserve
the () shape sentinel, shape now returns the real broadcast shape read off
the container's first element, and size/ndim derive from it instead of
attribute-accessing the container (they raised AttributeError for any
JAX-backed message on jax 0.10 too). The sentinel was itself a live bug:
_broadcast_natural_parameters matched the shape[1:] branch for batched JAX
messages, inserted a spurious axis, and logpdf returned an (n, n) matrix of
wrong values where NumPy returns the correct (n,) vector.

The new parity test asserts NumPy/JAX equality of shape/size/ndim and of
batched logpdf values and shape over Normal/Beta/Gamma — it fails 6 ways
against the sentinel on jax 0.10 alone, so the () sentinel cannot come back
silently.

Verified: full suite 2030 passed on jax 0.10.2 and 0.11.1 (Python 3.12,
[optional] extras installed); the ten autofit_workspace_test jax_assertions
scripts unchanged (9/10 pass on both versions, the priors_xp_dispatch
float32-tolerance failure is pre-existing and identical in every cell).

Co-Authored-By: Claude <[email protected]>
Claude-Session: https://claude.ai/code/session_01EauVX6vD9k1N4PXaEf2wvo
@Jammy2211
Jammy2211 merged commit df07aee into main Aug 22, 2026
4 checks passed
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.

2 participants