-
Couldn't load subscription status.
- Fork 19.6k
Fix deadlock in CallbackList.
#21701
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
Summary of ChangesHello @hertschuh, 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 resolves a critical deadlock vulnerability within the 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 effectively resolves a potential deadlock in CallbackList by replacing the unsafe __del__ implementation with a reference counting mechanism to manage the ThreadPoolExecutor's lifecycle. The new approach using _on_begin and _on_end hooks is robust and correctly handles nested calls and reuse. The renaming of _clear_futures to _flush_futures also improves clarity. I've added a few suggestions to improve docstrings for the new and renamed methods to enhance maintainability, in line with the project's style guide.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #21701 +/- ##
=======================================
Coverage 82.59% 82.59%
=======================================
Files 572 572
Lines 58314 58327 +13
Branches 9130 9131 +1
=======================================
+ Hits 48166 48177 +11
- Misses 7817 7818 +1
- Partials 2331 2332 +1
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:
|
A memory leak related to the executor in `CallbackList` was fixed in keras-team#20779 However, calling `Executor.shutdown` within `__del__` is intrisincally unsafe and can create deadlocks because the garbage collector can be called in different contexts. This new approach uses the `on_train/test/predict_begin` and `on_train/test/predict_end` callbacks to detect when we're done with the executor. - it counts the number of "begin"s and "end"s to handle the case of `evaluate` within `fit` (we do not shutdown the executor at the end of `evaluate` but instead keep it around for the rest of the training) - it also handles `CallbackList` being reused between calls to `fit`, `evaluate` or `predict` even though Keras doesn't reuse. Also renamed `_clear_futures` to `_flush_futures` to make it clear futures are not discarded, but exectuted.
66b1ea8 to
9b129f4
Compare
Original PR #21701 by hertschuh Original: keras-team/keras#21701
Merged from original PR #21701 Original: keras-team/keras#21701
A memory leak related to the executor in
CallbackListwas fixed in #20779However, calling
Executor.shutdownwithin__del__is intrisincally unsafe and can create deadlocks because the garbage collector can be called in different contexts.This new approach uses the
on_train/test/predict_beginandon_train/test/predict_endcallbacks to detect when we're done with the executor.evaluatewithinfit(we do not shutdown the executor at the end ofevaluatebut instead keep it around for the rest of the training)CallbackListbeing reused between calls tofit,evaluateorpredicteven though Keras doesn't reuse.Also renamed
_clear_futuresto_flush_futuresto make it clear futures are not discarded, but exectuted.