- Notifications
You must be signed in to change notification settings - Fork19.7k
Orbax Loading and Sharding Support feature#21903
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Orbax Loading and Sharding Support feature#21903
Conversation
Summary of ChangesHello@amitsrivastava78, 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 significantly enhances Keras's checkpoint loading capabilities by introducing a dedicated Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on ourdocumentation 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 uphere. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with theGemini 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 introduces significant new functionality for Orbax checkpoint loading and sharding support. The changes include a newModel.load() method, helper functions for checkpoint discovery, and a comprehensive suite of new tests. The implementation is generally solid and well-tested. My feedback focuses on improving code maintainability by reducing duplication and enhancing error handling in the new test cases.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
ee32491 to10370f5Comparecodecov-commenter commentedDec 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@## master #21903 +/- ##==========================================+ Coverage 76.30% 82.61% +6.31%========================================== Files 580 588 +8 Lines 60029 61416 +1387 Branches 9432 9653 +221 ==========================================+ Hits 45803 50740 +4937+ Misses 11750 8168 -3582- Partials 2476 2508 +32
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:
|
10370f5 to325a03fCompare325a03f to43d45d0Compare- Remove complex JAX abstract pytree logic that was causing 'free(): invalid pointer' errors- Use preservation mode for all backends to avoid state structure mismatches- This prevents memory corruption when loading checkpoints with different optimizer states
- Replace bare 'except:' with specific 'except (ImportError, AttributeError):' for distribution import patterns- This improves error handling by only catching expected exceptions
- Extract duplicated tensor conversion logic into _to_numpy() helper method- Replace duplicated code blocks in optimizer and metrics variable comparisons- Improves maintainability and reduces code duplication
c592a27 tod8a86e8CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
- Add multi-host support using orbax.checkpoint.multihost APIs- Remove manual sync calls around save operations- Use proper Orbax v1 APIs instead of brittle file inspection- Fix 80-column line length violations in test files- Ensure cross-backend compatibility with appropriate test skipping- Clarify checkpoint directory terminology in documentation
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!
Can you tighten theorbax_checkpoint_test.py file. It's extremely long and hard to follow. I think:
- a lot fewer tests could cover basically the same
- some parameterized tests could minimize code duplication
- the verification blocks could be much shorter using
keras.treeandself.assertAllClose, I gave some examples.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
orbax-dev 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.
LGTM, it won't let me approve with comments.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
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.
A couple of complications I didn't think about:
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
- Remove redundant try/except blocks in favor of LazyModule error handling- Use ocp.multihost directly from LazyModule instead of custom function- Remove unnecessary dummy apply_gradients in Orbax loading (confirmed required)- Update sync key to be process-safe- Remove unused test case for asset support- Improve LazyModule to expose multihost from parent orbax.checkpoint module
- Remove manual directory cleanup in _save_checkpoint that interfered with Orbax preservation policies- Simplify preservation policy setup to use LatestN directly instead of AnyPreservationPolicy wrapper- Update asset directory structure to use checkpoint_dir/assets/step/ format- Add comprehensive asset saving/loading tests for both sync and async modes- Make test_save_freq_epoch more robust by checking for numeric checkpoint names rather than specific epoch- Fix asset loading to handle new directory structure in saving_api.pyAll Orbax checkpoint tests now pass on both JAX and TensorFlow backends.
- Remove manual directory cleanup in _save_checkpoint that interfered with Orbax preservation policies- Simplify preservation policy setup to use LatestN directly instead of AnyPreservationPolicy wrapper- Update asset directory structure to use checkpoint_dir/assets/step/ format- Add comprehensive asset saving/loading tests for both sync and async modes- Make test_save_freq_epoch more robust by checking for numeric checkpoint names rather than specific epoch- Fix asset loading to handle new directory structure in saving_api.pyAll Orbax checkpoint tests now pass on both JAX and TensorFlow backends.
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.
I didn't see where the hook is to supportmodel.load_weights. Did I miss something?
Uh oh!
There was an error while loading.Please reload this page.
- Save custom layer assets (binary data, strings, arrays) directly in the pytree as base64-encoded strings for Orbax compatibility- Remove separate asset file saving to eliminate synchronization races- Update loading to extract assets from pytree and decode back to original types- Modify tests to verify asset loading without directory checks- Ensures atomic saves with proper preservation policy handling
…points- Add asset loading logic to saving_api.load_weights for Orbax checkpoints- Include assets in weights-only Orbax checkpoints- Fix layer naming in MockLayerWithAssets test to avoid conflicts- Add test for load_weights with assets from Orbax checkpoints
amitsrivastava78 commentedDec 17, 2025
Added asset loading logic to saving_api.load_weights for Orbax checkpoints |
Support