fix: message shape/size/ndim read the real JAX broadcast shape (jax 0.11 compat) - #1513
Merged
Merged
Conversation
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
This was referenced Aug 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_arraysto return a tuple instead of a list (NumPy 2 alignment).MessageInterface.shapetype-tested the container withisinstance(..., list), so on 0.11 the JAX branch stopped matching, fell through to.shapeon a tuple, and every jnp-backed message construction raisedAttributeError— the fourtest_jax_tracelog-partition failures blocking theautonervesjax cap widen.Why not the one-line
isinstancewidenThe JAX branch returned a hard-wired
()shape, which is a live numerical bug on jax 0.10 today: for batched JAX messages,_broadcast_natural_parametersmatched theshape[1:] == self.shapebranch, inserted a spurious axis, andlogpdfreturned an(n, n)matrix of wrong values where NumPy returns the correct(n,)vector.size/ndimhad no JAX branch at all and raisedAttributeErrorfor any jnp-backed message on both jax versions. Widening theisinstancewould ship all of that unchanged.Instead,
shapenow returns the real broadcast shape read off the container's first element (correct for both the list and tuple forms), andsize/ndimderive 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/ndimrepair 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_numpyasserts NumPy/JAX parity ofshape/size/ndimand oflogpdfvalues 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):main, unfixedautofit_workspace_test/scripts/jax_assertions/: 9/10 pass in all four version-by-fix cells; only the pre-existingpriors_xp_dispatch.pyfloat32-tolerance failure, identical everywhere.test_autogalaxy1103 passed andtest_autolens532 passed, identical under jax 0.10.2 and 0.11.1;test_autonerves157 passed under 0.11.1.🤖 Generated with Claude Code
https://claude.ai/code/session_01EauVX6vD9k1N4PXaEf2wvo
Generated by Claude Code