Skip to content

Conversation

@amitsrivastava78
Copy link
Collaborator

Support

  1. New loading function for the orbax checkpointing
  2. Support sharding feature

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 Model.load() method for Orbax checkpoints. This new functionality intelligently handles checkpoint directories, automatically identifying and loading the latest state. Crucially, it incorporates advanced sharding support for the JAX backend, allowing models to be loaded and resharded dynamically to match the current distribution configuration. Additionally, the Model.export() method has been refined by removing the LiteRT export option, focusing on core export functionalities.

Highlights

  • New Model.load() method for Orbax Checkpoints: A new load method has been added to the Model class, enabling direct loading of Orbax checkpoints. This method can automatically detect the latest checkpoint in a directory or load a specific step.
  • Sharding Support for JAX Backend: The Model.load() method now supports automatic resharding of data when loading Orbax checkpoints on the JAX backend, adapting to the current distribution strategy.
  • Refined Model.export() Functionality: The Model.export() method has been updated to remove support for LiteRT export, streamlining the available export formats.
  • Comprehensive Testing for Loading and Sharding: Extensive new tests have been added to orbax_checkpoint_test.py to validate the new Model.load() method, including synchronous/asynchronous saving, layout preservation, and JAX-specific resharding and distributed checkpoint structure verification.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 new Model.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.

@codecov-commenter
Copy link

codecov-commenter commented Dec 8, 2025

Codecov Report

❌ Patch coverage is 56.97674% with 37 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.50%. Comparing base (f0a48a6) to head (c592a27).

Files with missing lines Patch % Lines
keras/src/callbacks/orbax_checkpoint.py 41.37% 14 Missing and 3 partials ⚠️
keras/src/models/model.py 64.51% 4 Missing and 7 partials ⚠️
keras/src/saving/saving_api.py 65.38% 4 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21903      +/-   ##
==========================================
- Coverage   76.30%   71.50%   -4.80%     
==========================================
  Files         580      580              
  Lines       60029    60112      +83     
  Branches     9432     9450      +18     
==========================================
- Hits        45803    42982    -2821     
- Misses      11750    14759    +3009     
+ Partials     2476     2371     -105     
Flag Coverage Δ
keras 71.40% <56.97%> (-4.77%) ⬇️
keras-jax ?
keras-numpy 57.26% <13.95%> (-0.06%) ⬇️
keras-openvino 34.27% <13.95%> (-0.03%) ⬇️
keras-torch 63.21% <56.97%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants