-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Fix NNX tests #21884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix NNX tests #21884
Conversation
Summary of ChangesHello @divyashreepathihalli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses critical test failures in the Keras NNX integration tests by updating core dependencies, Flax and JAX, to their latest versions. The primary fix involves adapting to changes in Flax's Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses test failures in NNX integration by updating JAX and Flax dependencies and registering NnxVariable as a custom JAX PyTree node. This ensures Keras-specific attributes are preserved during NNX operations. The changes are well-reasoned. I have two suggestions for improvement: one to update an outdated comment in requirements.txt, and another to enhance the robustness of the new __setattr__ fallback mechanism in keras/src/backend/jax/core.py to prevent potential state inconsistencies.
| jax[cpu]==0.8.1 | ||
| flax==0.12.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21884 +/- ##
===========================================
- Coverage 82.57% 61.46% -21.11%
===========================================
Files 577 578 +1
Lines 59599 59813 +214
Branches 9351 9387 +36
===========================================
- Hits 49213 36767 -12446
- Misses 7978 20720 +12742
+ Partials 2408 2326 -82
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
hertschuh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR!
The Flax tests are failing though
| # Mirror Keras attributes to _var_metadata to ensure persistence | ||
| # if the Pytree registration is not respected by NNX. | ||
| if ( | ||
| name != "_var_metadata" | ||
| and name not in ("_raw_value", "_trace_state") | ||
| and hasattr(self, "_var_metadata") | ||
| ): | ||
| self._var_metadata[name] = value | ||
|
|
||
| object.__setattr__(self, name, value) | ||
|
|
||
| NnxVariable.__setattr__ = __setattr__ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you do NnxVariable.__setattr__ = __setattr__ instead of simply declaring def __setattr__(self, name, value): directly within the NnxVariable class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed to mirror Keras attributes into _var_metadata, so that they persist during NNX's Pytree registration, which might otherwise be missed if defined directly within the class due to the complex multiple inheritance
| # Note that we test against the latest JAX on GPU. | ||
| jax[cpu]==0.5.0 | ||
| flax | ||
| jax[cpu]==0.8.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is promising, but the TensorFlow CPU tests are failing. Upgrade TF version too?
80cf2b3 to
4143934
Compare
9fedd6d to
10ba8ec
Compare
9acaaf5
into
keras-team:master
This PR updates the Flax dependency to 0.12.1 and JAX to 0.8.1.
It addresses test failures in the NNX integration tests (
keras/src/backend/jax/core_test.py) caused by changes in Flax'snnx.Variableimplementation.nnx.Variablenow relies heavily on slots and metadata, causing Keras-specific attributes stored in__dict__to be lost duringnnx.split/merge.Fix: Registering
NnxVariableas a custom Pytree node with JAX. This ensures that the instance's__dict__(excluding the raw value) is treated as auxiliary data (static metadata) and preserved in the GraphDef.