Fix RematScope(mode=None) truthy bug in get_current_remat_mode - #23411
Fix RematScope(mode=None) truthy bug in get_current_remat_mode#23411Vansh-Sharmaa wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request updates the rematerialization utility to correctly handle cases where a RematScope is explicitly initialized with mode=None. Specifically, get_current_remat_mode() now returns None if the active scope's mode is None, and a corresponding unit test has been added to verify this behavior. I have no additional feedback to provide as the changes are clean, correct, and well-tested.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #23411 +/- ##
==========================================
- Coverage 84.91% 84.15% -0.76%
==========================================
Files 468 468
Lines 70693 70699 +6
Branches 11711 11711
==========================================
- Hits 60027 59499 -528
- Misses 7659 8204 +545
+ Partials 3007 2996 -11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary of Changes
Fixes an issue where
RematScope(mode=None)was incorrectly evaluated as truthy when callingget_current_remat_mode().Root Cause
RematScopeacceptsmode=Noneto explicitly disable rematerialization within a context block. Previously,get_current_remat_mode()returned aRematModenamedtuple (RematMode(mode=None, ...)), which evaluates toTruein boolean context checks (if get_current_remat_mode():). Consequently, downstream code treated rematerialization as enabled even whenmode=Nonewas specified.Solution
get_current_remat_mode()inkeras/src/backend/common/remat.pyto returnNonewhenactive_scope.mode is None.TestRematScope.test_remat_scope_activationinkeras/src/backend/common/remat_test.pyverifying thatget_current_remat_mode()returnsNoneinsidewith RematScope(mode=None):.Testing
keras/src/backend/common/remat_test.py(6/6 passed).