-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Refactor variable serialization. #21713
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
base: master
Are you sure you want to change the base?
Refactor variable serialization. #21713
Conversation
Summary of ChangesHello @james77777778, 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 implements a significant refactoring of how Keras layers handle variable serialization, especially concerning quantized models. By introducing a 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 introduces a solid refactoring of variable serialization in Dense
, EinsumDense
, and Embedding
layers. By introducing variable_serialization_spec
, the serialization logic becomes more explicit, readable, and consistent, which is a great improvement for maintainability. The removal of legacy loading paths and the consolidation of checks into the base Layer
class further streamline the code. The changes are well-implemented and align with the goal of simplifying the serialization process. I have one minor suggestion regarding a comment to improve clarity.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #21713 +/- ##
==========================================
+ Coverage 82.60% 82.63% +0.03%
==========================================
Files 572 572
Lines 58326 58284 -42
Branches 9134 9117 -17
==========================================
- Hits 48179 48164 -15
+ Misses 7817 7802 -15
+ Partials 2330 2318 -12
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:
|
d52caae
to
9615b5b
Compare
Thanks for the PR! To be clear, the reason we were using indices instead of string names was that string names are susceptible to changes, while indices are more stable. It makes the format more future proof. One thing I've considered doing (and which could be done across the board, for all weights in all layers) is to have names like |
Thanks for providing the context.
Unfortunately, this is not backwards compatible in the way we were discussing. Let's say we save the latest Gemma checkpoints with Keras 3.12 with this new format, people using Keras 3.11 won't be able to load them. |
Yes, but historically it has been the case that file loading has been backwards compatible (newer Keras versions can load older files) but not forward compatible (older Keras versions may not necessarily load newer files). The only alternative here is to keep integer indices. |
…1713 - Remove variable_loading.py (quantization/saving related) - Fix duplicate import in core_test.py - Revert layer files to remove quantization changes - Keep only core JAX memory management changes for OOM fix
This is an alternative solution compared to #21681
Since the default behavior is to store the variables using their order as the keys, we can maintain this behavior by using a
variable_serialization_spec
to explicitly define the order.variable_serialization_spec
works like a human-readable proxy between the variables andstore
for better compatibility.IMO,
save_own_variables
andload_own_variables
become more readable and simpler in this PR.cc @hertschuh @fchollet @JyotinderSingh