-
Notifications
You must be signed in to change notification settings - Fork 19.7k
Fix torch keyword arguments in remat.
#21883
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?
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 an issue in the Keras PyTorch backend where 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 correctly fixes an issue in the PyTorch backend where remat would not forward keyword arguments. The change simply passes **kwargs to torch.utils.checkpoint.checkpoint. A new test, test_remat_with_kwargs, is added to verify the fix with various keyword argument scenarios, including full, partial, and default arguments. The implementation is correct and the test coverage is good.
| # Test with keyword arguments | ||
| remat_fn = backend.core.remat(fn_with_kwargs) | ||
| result_with_kwargs = remat_fn(x, scale=2.0, offset=1.0) | ||
| expected = fn_with_kwargs(x, scale=2.0, offset=1.0) | ||
| self.assertAllClose(result_with_kwargs, expected) | ||
|
|
||
| # Test with default keyword arguments | ||
| result_with_defaults = remat_fn(x) | ||
| expected_defaults = fn_with_kwargs(x) | ||
| self.assertAllClose(result_with_defaults, expected_defaults) | ||
|
|
||
| # Test with partial keyword arguments | ||
| result_partial = remat_fn(x, scale=3.0) | ||
| expected_partial = fn_with_kwargs(x, scale=3.0) | ||
| self.assertAllClose(result_partial, expected_partial) |
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.
The test cases for different keyword argument scenarios are well-covered. For better maintainability and readability, you could consider parameterizing this test using subTest. This would make it more compact and easier to add new test cases in the future.
| # Test with keyword arguments | |
| remat_fn = backend.core.remat(fn_with_kwargs) | |
| result_with_kwargs = remat_fn(x, scale=2.0, offset=1.0) | |
| expected = fn_with_kwargs(x, scale=2.0, offset=1.0) | |
| self.assertAllClose(result_with_kwargs, expected) | |
| # Test with default keyword arguments | |
| result_with_defaults = remat_fn(x) | |
| expected_defaults = fn_with_kwargs(x) | |
| self.assertAllClose(result_with_defaults, expected_defaults) | |
| # Test with partial keyword arguments | |
| result_partial = remat_fn(x, scale=3.0) | |
| expected_partial = fn_with_kwargs(x, scale=3.0) | |
| self.assertAllClose(result_partial, expected_partial) | |
| remat_fn = backend.core.remat(fn_with_kwargs) | |
| test_cases = [ | |
| ("with_kwargs", {"scale": 2.0, "offset": 1.0}), | |
| ("with_defaults", {}), | |
| ("partial_kwargs", {"scale": 3.0}), | |
| ] | |
| for name, kwargs in test_cases: | |
| with self.subTest(msg=name): | |
| result = remat_fn(x, **kwargs) | |
| expected = fn_with_kwargs(x, **kwargs) | |
| self.assertAllClose(result, expected) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #21883 +/- ##
=======================================
Coverage 82.57% 82.57%
=======================================
Files 577 577
Lines 59599 59599
Branches 9351 9351
=======================================
Hits 49213 49213
Misses 7978 7978
Partials 2408 2408
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:
|
#21861