Fix Hparam configurability restoration after exceptions - #2128
Merged
kevalmorabia97 merged 1 commit intoAug 11, 2026
Merged
Conversation
Signed-off-by: taking-lying-flat <1615405@qq.com>
Contributor
📝 WalkthroughWalkthrough
ChangesConfigurability restoration
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
taking-lying-flat
marked this pull request as draft
August 11, 2026 00:48
taking-lying-flat
marked this pull request as ready for review
August 11, 2026 01:52
kevalmorabia97
approved these changes
Aug 11, 2026
Collaborator
|
/ok to test 5496251 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2128 +/- ##
==========================================
- Coverage 78.73% 78.13% -0.60%
==========================================
Files 522 522
Lines 60342 60343 +1
==========================================
- Hits 47508 47152 -356
- Misses 12834 13191 +357
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:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Type of change: Bug fix
Hparam._force_configurable()restored_is_configurableonly after a normal context-manager exit. If code inside the context raised, the restoration statement was skipped and a previously non-configurableHparamremained permanently configurable.Wrap the
yieldintry/finallyso the original state is restored on both normal and exceptional exits. Add a regression test that raises inside the context and verifies the temporary configurable state does not leak.Usage
No call-site changes are required. Existing users of the context manager retain the same behavior, including when an operation inside the context fails:
Testing
hp.is_configurableremainsTrue..venv/bin/python -m pytest tests/unit/torch/opt/test_dynamic.py -q(3 passed).venv/bin/python -m pytest tests/unit/torch/opt -q(66 passed, 2 skipped)git diff --checkBefore your PR is "Ready for review"
Make sure you read and follow Contributor guidelines and your commits are signed (
git commit -s -S).Make sure you read and follow the Security Best Practices (e.g. avoiding hardcoded
trust_remote_code=True,torch.load(..., weights_only=False),pickle, etc.).CONTRIBUTING.md: N/AAdditional Information
Related prior work: #1913 was closed without merging and only tested the normal-exit path. This PR adds exception-path coverage together with the production fix.
Summary by CodeRabbit
Bug Fixes
Tests