-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Non cumulative model.predict #21673
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?
Non cumulative model.predict #21673
Conversation
Introduces an 'accumulate' argument to the predict method in all backend trainers and the base Trainer class. When set to False, predictions are not accumulated in memory and must be handled via callbacks, helping to avoid memory issues with large datasets. Updates method signatures, docstrings, and internal logic accordingly.
Standardizes the handling of outputs in the predict methods across all backend trainers by always initializing outputs as None and returning None when no outputs are accumulated. This simplifies the logic and ensures consistent behavior when accumulate is False or when no predictions are made.
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 @pctablet505, 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 highly requested feature for non-cumulative prediction within the model.predict
function. By adding an accumulate
boolean parameter, it allows users to prevent the accumulation of all prediction outputs in memory. This is particularly beneficial for scenarios involving very large datasets or environments with limited memory, as it enables processing of outputs through callbacks without storing the entire result set, thereby enhancing the scalability and efficiency of the prediction process.
Highlights
- Non-cumulative Prediction: Introduced an
accumulate
parameter to thepredict
method across all backend trainers (JAX, NumPy, OpenVINO, TensorFlow, Torch) and the basetrainer.py
. - Memory Optimization: When
accumulate
is set toFalse
, thepredict
method will no longer store all batch outputs in memory, addressing memory limitations for very large datasets. - Callback Integration: Users can now handle prediction outputs via callbacks when
accumulate=False
, allowing for custom storage or processing without accumulating results in the main return value. - Docstring Updates: The docstring for the
predict
method inkeras/src/trainers/trainer.py
has been updated to clearly explain the newaccumulate
parameter and its effect on the method's return value.
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
-
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 introduces a new accumulate
parameter to the model.predict()
method across all backends. This is a valuable feature for users working with very large datasets, as it allows them to process predictions batch by batch using callbacks without storing all outputs in memory, thus preventing potential out-of-memory errors. The implementation is consistent across the JAX, NumPy, TensorFlow, and Torch backends. However, I've found a critical issue in the OpenVINO backend implementation that needs to be addressed.
Refactored the predict method signatures in all backend trainer classes and the base Trainer to use one argument per line. Also reformatted long return statements for better readability. No functional changes were made.
…ablet505/keras into non_cumulative_model_predict
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #21673 +/- ##
==========================================
- Coverage 82.53% 82.51% -0.02%
==========================================
Files 571 571
Lines 57900 57925 +25
Branches 9056 9071 +15
==========================================
+ Hits 47785 47797 +12
- Misses 7800 7809 +9
- Partials 2315 2319 +4
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:
|
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 explain the advantages of calling predict()
(with a callback) if it returns nothing? Why not simply call predict(batch)
or predict_on_batch
in a loop?
there was a feature request for non cumulative model.predict, where we don't store the outputs and return it directly.
#21642 In case of very large datasets and limited memory, it is more feasible to retrieve the outputs using a callback and store to storage, instead of storing everything in memory.
This PR fixes #21642.