fix: jax 0.11.1 compatibility, release v0.5.4 - #235
Merged
Conversation
JAX 0.11.1 removed `core.CallPrimitive` and completed the Jaxpr/ClosedJaxpr merge started in 0.11.0, breaking `import brainstate` and silently disabling a validation check in the IR tooling. - _compatible_import: `CallPrimitive` is gone from both `jax.extend.core` and `jax._src.core` on 0.11.1, so the unconditional import made `import brainstate` fail outright. Fall back to a thin `Primitive` subclass applying `register_call_primitive_rules()` at construction, keeping the public `CallPrimitive` name and its constructor behavior. 0.11.0 still ships the original class and keeps using it. - transform/_ir_processing: 0.11.1 dropped `Jaxpr._num_consts`, so an input is a constvar only when a constant value is attached. `eqns_to_closed_jaxpr()` validated `len(consts)` against `jaxpr.constvars` read off an intermediate open jaxpr, which is now always empty -- rejecting valid consts and silently accepting mismatched ones. Factor binder resolution into `_resolve_jaxpr_vars()` and validate against the resolved constvars; the returned `ClosedJaxpr(jaxpr, consts)` restores the split on every version. The boundary is 0.11.1, not 0.11.0, which still tracked the count separately. - interop: `lazy_import()` caught only ImportError, so an installed-but-broken optional framework (flax<=0.12.8 under 0.11.1) surfaced as an opaque traceback through its internals. Raise `InteropError` naming the package, the underlying error, and the installed jax version instead. - CI: add a pinned jax==0.11.0 matrix entry; the unpinned entry now covers 0.11.1. The jax>=0.8.0 floor is unchanged. flax remains incompatible with jax 0.11.1 upstream (0.12.8 is the latest and still fails); its interop tests now skip cleanly instead of erroring. Verified: 5303 passed / 0 failed on jax 0.11.1; 5342 passed / 0 failed on 0.11.0; IR + interop 211 passed on 0.10.0.
Contributor
Reviewer's GuideRestores compatibility with JAX 0.11.1, fixes a const/var validation hole in IR processing, hardens optional-framework import error handling, adjusts CI to exercise 0.11.1, and cuts release v0.5.4. Sequence diagram for lazy_import error handling in interopsequenceDiagram
participant User
participant lazy_import
participant importlib
participant MissingDependencyError
participant InteropError
User->>lazy_import: lazy_import(module_name)
lazy_import->>importlib: import_module(module_name)
alt import raises ImportError
importlib-->>lazy_import: ImportError
lazy_import->>MissingDependencyError: raise MissingDependencyError(top, hint)
else import raises other Exception
importlib-->>lazy_import: Exception
lazy_import->>InteropError: raise InteropError(message)
else import succeeds
importlib-->>lazy_import: module
lazy_import-->>User: module
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new
_resolve_jaxpr_varshelper currently returns a baretuple; consider tightening the return type annotation toTuple[List[Var], List[Var], List[Var]](and importingTuple) to make downstream usage clearer and more type-checker-friendly. - In
_conversion_test._importorskip, catching allExceptionand immediately skipping can make debugging unexpected errors harder; you might want to special-case known interop issues (e.g.,AttributeErrorfrom flax) or at least log the underlying exception somewhere before skipping.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new `_resolve_jaxpr_vars` helper currently returns a bare `tuple`; consider tightening the return type annotation to `Tuple[List[Var], List[Var], List[Var]]` (and importing `Tuple`) to make downstream usage clearer and more type-checker-friendly.
- In `_conversion_test._importorskip`, catching all `Exception` and immediately skipping can make debugging unexpected errors harder; you might want to special-case known interop issues (e.g., `AttributeError` from flax) or at least log the underlying exception somewhere before skipping.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Summary
JAX 0.11.1 removed
core.CallPrimitiveand completed theJaxpr/ClosedJaxprmerge begun in 0.11.0. Together these brokeimport brainstateoutright and silently disabled a validation check in the IR tooling. This PR restores compatibility and cuts release v0.5.4.Fixes
_compatible_import—import brainstatefailed on 0.11.1CallPrimitiveis gone from bothjax.extend.coreandjax._src.core, replaced bycreate_call_primitive()/register_call_primitive_rules(). It was imported unconditionally onjax>=0.10, so every 0.11.1 install failed at import time. The import is now attempted first, falling back to a thinPrimitivesubclass that appliesregister_call_primitive_rules()at construction — preserving the publicCallPrimitivename and its constructor behavior. JAX 0.11.0 still ships the original class and continues to use it.transform/_ir_processing— silent validation hole0.11.1 dropped
Jaxpr._num_consts, so an input counts as a constvar only when a constant value is attached.eqns_to_closed_jaxpr()validatedlen(consts)againstjaxpr.constvarsread back off an intermediate open jaxpr — now always empty. That both rejected validconstsand, more seriously, silently accepted mismatched ones, defeating the check entirely.Binder resolution is factored into
_resolve_jaxpr_vars()so validation runs against the resolvedconstvars; the returnedClosedJaxpr(jaxpr, consts)restores theconstvars/invarssplit identically on all supported versions.The boundary is 0.11.1, not 0.11.0 — 0.11.0 still tracked the constvar count independently of attached values. Confirmed against the 0.11.0 sdist rather than inferred.
interop— opaque failure for installed-but-broken optional depslazy_import()caught onlyImportError, so a framework that is present yet fails to import surfaced as a traceback through its own internals. It now raisesInteropErrornaming the package, the underlying error, and the installed JAX version.MissingDependencyErrorstill signals a genuinely absent package.Known issue: flax
flaxis not yet compatible with JAX 0.11.1. The latest release (0.12.8) fails to import under it (jax.experimental.hijax.MutableHiTypeno longer exists). This is upstream with no brainstate-side fix;flaxinterop is unavailable on 0.11.1 until they ship a compatible release.equinoxinterop is unaffected. The affected tests now skip cleanly instead of producing 38 collection errors. Pinjax==0.11.0ifflaxinterop is required.CI
Added a pinned
jax==0.11.0matrix entry (one per supported minor, plus unpinned latest, which now exercises 0.11.1). Thejax>=0.8.0floor is unchanged — no packaging constraint needed changing.Verification
The 39-test delta between 0.11.1 and 0.11.0 is exactly the
flaxinterop suite — which also confirms the new skip helper does not over-skip whenflaxworks.Summary by Sourcery
Restore compatibility with JAX 0.11.1 while hardening IR validation and optional framework interoperability.
Bug Fixes:
Enhancements:
CI:
Documentation:
Tests:
Chores: