-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Orbax checkpointing guide #2169
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
Conversation
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.
Summary of Changes
Hello @SamanehSaadat, 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 introduces a new guide for Keras users, demonstrating how to implement Orbax checkpointing when training models with the JAX backend. This is particularly beneficial for multi-host training scenarios where the default .keras format may not be suitable.
Highlights
- New Orbax Checkpointing Guide: A comprehensive guide (guides/orbax_checkpoint.py) has been added, detailing the process of using Orbax for checkpointing in Keras with the JAX backend.
- Custom Checkpointing Utilities: The guide introduces and explains two custom Python classes, KerasOrbaxCheckpointManager and OrbaxCheckpointCallback, which wrap Orbax's functionality for seamless integration with Keras models.
- Practical Example: The guide includes a runnable example demonstrating how to set up and use the OrbaxCheckpointCallback during model training.
- Guide Integration: The new guide has been registered in scripts/guides_master.py to ensure it appears in the documentation.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| 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 issue 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
-
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. ↩
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 adds a new guide for using Orbax for checkpointing in Keras with the JAX backend. The guide is well-structured and provides useful utility classes. I've provided some suggestions to improve the robustness and usability of the provided OrbaxCheckpointCallback and KerasOrbaxCheckpointManager utilities, including automatically inferring steps_per_epoch, handling potential None values during state restoration, and improving code style and logging practices.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
… into orbax-guide
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! This is very useful.
| """ | ||
|
|
||
| """ | ||
| ## Introduction |
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.
nitpick: add an empty line after each header, like:
## Introduction
Orbax is...
guides/orbax_checkpoint.py
Outdated
| This guide explains how to do Orbax checkpointing when training a model in | ||
| the Jax backend. | ||
|
|
||
| The default `.keras` format doesn't support multi-host checkpointing so if |
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.
Let's rephrase this slightly, it's not intrinsically the file format that's wrong. How about:
Note that you should use Orbax checkpointing for multi-host training as the default Keras checkpointing currently does not support multi-host.
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.
Sounds good! Done
guides/orbax_checkpoint.py
Outdated
| """ | ||
|
|
||
| """ | ||
| We need to set the Keras backend to Jax as this guide is intended for the |
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 see both JAX and Jax. Let's stay consistent and use JAX everywhere.
guides/orbax_checkpoint.py
Outdated
| """ | ||
|
|
||
| """shell | ||
| pip install -q -u orbax-checkpoint |
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 think it's -U uppercase for upgrade.
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.
Right :D fixed
guides/orbax_checkpoint.py
Outdated
| super().__init__(checkpoint_dir, options=options) | ||
|
|
||
| def _get_state(self): | ||
| """Gets the model state and metrics""" |
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.
Add Returns: to docstring
guides/orbax_checkpoint.py
Outdated
| if keras.config.backend() != "jax": | ||
| raise ValueError( | ||
| "`OrbaxCheckpointCallback` is only supported on a " | ||
| "`jax` backend. Provided backend is %s." % keras.config.backend() |
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.
Use f-string here.
| """ | ||
| Now if you look at the Orbax checkpoint directory, you can see all the files | ||
| saved as part of Orbax checkpointing. | ||
| """ |
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.
Oh maybe you can add:
"""shell
ls -l /tmp/ckpt
"""
Does that work?
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.
|
Can you also run it and generate the |
Added |
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.
Great, thanks!
Thank you for the review! |

No description provided.