Repository navigation
Fix nested distillation forward contexts - #2653
kevalmorabia97 merged 6 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Restore forward mode after nested contexts modelopt/torch/distill/distillation_model.py, tests/unit/torch/distill/test_distill.py, CHANGELOG.rst |
The context managers save and restore their prior mode flags. Tests check nested context behavior, outputs, and call counts, including exception cases. The changelog records the fix. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers: kevalmorabia97
Merge Risk: 
Minimal · up to ff482
-
The nested context restoration change is ready to merge.
Pre-merge checks: 
5 · 
1
-
Failed checks: 1 warning Passed checks: 5 passed-
Full details: Security Anti-Patterns
-
Explanation
PASS. The authoritative diff changes only DistillationModel context restoration, regression tests, and a changelog entry. Added Python lines contain none of the prohibited patterns. No dependency-file changes are present. SECURITY.md rules therefore identify no CRITICAL anti-pattern in this pull request.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 36.36% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 2 files. (1 skipped: 1 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
- Restore the previous teacher/student forward flags on context exit so nested and disabled contexts preserve the enclosing mode - Add regression tests for nesting, exceptions, and overlapping contexts Signed-off-by: Michael Rusu <[email protected]>
c25fd72 to
5c33d27
Compare
|
Thanks for the contribution! This PR now has merge conflicts with We've added the |
Signed-off-by: Michael-Rusu <[email protected]>
|
Updated the branch with the lates and resolved the conflicts. Thanks for the heads-up :) |
Signed-off-by: Michael-Rusu <[email protected]>
meenchen
left a comment
There was a problem hiding this comment.
Bot review (bedrock-claude-opus-5-5) — DM the bot to share feedback.
Approving: this is a small, correct fix. Each context manager now saves the previous value of its flag and puts it back in finally, the same way hide_teacher_model and hide_loss_modules already work. The new regression tests use real forward passes.
No action needed.
No action needed:
- I checked the test expectations against
DistillationModel.forwardand they hold:- The overlapping contexts give student output in both orders, because
_only_student_fwdis checked first. - The call counts work out to 3/4/5 in the non-overlapping cases.
- The overlapping contexts give student output in both orders, because
- No existing tests were changed, there are no licensing changes, and the CHANGELOG has an entry.
|
/ok to test ff48223 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2653 +/- ##
==========================================
+ Coverage 77.50% 79.17% +1.66%
==========================================
Files 661 661
Lines 74972 74974 +2
==========================================
+ Hits 58107 59360 +1253
+ Misses 16865 15614 -1251
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:
|
Signed-off-by: Keval Morabia <[email protected]>
|
/ok to test 2d0fd91 |
#2928 #2885 #2908 #2929 #2950 #2972 #2877 #2951 #2816 #3005 #3012 #2971 #3015 #3006 #3026 #2988 #3028 #1860 #3030 #2612 #3033 #2653 #2599 #2655 #2618 #2868 #3032 #3027 #2869 #2984 #2975 #2345 #3020 #2997 (#3072) ## Cherry-picked PRs - #2817 - #2671 - #2892 - #2876 - #2910 - #2911 - #2919 - #2904 - #2937 - #2928 - #2885 - #2908 - #2929 - #2950 - #2972 - #2877 - #2951 - #2816 - #3005 - #3012 - #2971 - #3015 - #3006 - #3026 - #2988 - #3028 - #1860 - #3030 - #2612 - #3033 - #2653 - #2599 - #2655 - #2618 - #2868 - #3032 - #3027 - #2869 - #2984 - #2975 - #2345 - #3020 - #2997 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Diffusion exports now offer more control over attention-quantizer metadata and preserve sparse-attention settings in a format compatible with downstream tooling. * Model loading better handles select bundled model implementations, and Docker guidance now covers writable CUDA-extension cache locations. * **Bug Fixes** * Improved reliability for model export and checkpoint saving, quantization across devices, ONNX processing, and calibration. * Temporary TensorRT and autotuning artifacts now use private directories by default. * **Documentation** * Updated installation guidance, compatibility notes, and links; corrected typos across guides and examples. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Chad Voegele <[email protected]> Signed-off-by: Rohan Joshi <[email protected]> Signed-off-by: LinCanNerd <[email protected]> Signed-off-by: Keval Morabia <[email protected]> Signed-off-by: weimingc <[email protected]> Signed-off-by: Noey Yang <[email protected]> Signed-off-by: Kai Xu <[email protected]> Signed-off-by: Zhehao Hu <[email protected]> Signed-off-by: noeyy-mino <[email protected]> Signed-off-by: joe-nv <[email protected]> Signed-off-by: yingguo-trt <[email protected]> Signed-off-by: Shengliang Xu <[email protected]> Signed-off-by: Chenjie Luo <[email protected]> Signed-off-by: anmaurya001 <[email protected]> Signed-off-by: Connor Baker <[email protected]> Signed-off-by: wiederse <[email protected]> Signed-off-by: Vu Dinh <[email protected]> Signed-off-by: Pratik Gandhi <[email protected]> Signed-off-by: Michael Rusu <[email protected]> Signed-off-by: Michael-Rusu <[email protected]> Signed-off-by: namgyu-youn <[email protected]> Signed-off-by: Sylvester Kaczmarek <[email protected]> Signed-off-by: Javier de Jesus <[email protected]> Signed-off-by: javierdejesusda <[email protected]> Signed-off-by: Zhiyu Cheng <[email protected]> Signed-off-by: Juhi Mittal <[email protected]> Signed-off-by: Dmitry Rantovov <[email protected]> Signed-off-by: h-guo18 <[email protected]> Co-authored-by: Chad Voegele <[email protected]> Co-authored-by: LinCanNerd <[email protected]> Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> Co-authored-by: Keval Morabia <[email protected]> Co-authored-by: Wei-Ming Chen <[email protected]> Co-authored-by: noeyy-mino <[email protected]> Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> Co-authored-by: kaix-nv <[email protected]> Co-authored-by: Zhehao Hu <[email protected]> Co-authored-by: joe <[email protected]> Co-authored-by: yingguo-trt <[email protected]> Co-authored-by: Shengliang Xu <[email protected]> Co-authored-by: Chenjie Luo <[email protected]> Co-authored-by: anmaurya001 <[email protected]> Co-authored-by: Connor Baker <[email protected]> Co-authored-by: Jiao Mingyang <[email protected]> Co-authored-by: Vu Dinh <[email protected]> Co-authored-by: Pratik Gandhi <[email protected]> Co-authored-by: Michael R <[email protected]> Co-authored-by: Michael-Rusu <[email protected]> Co-authored-by: namgyu-youn <[email protected]> Co-authored-by: Sylvester Kaczmarek <[email protected]> Co-authored-by: Javier De Jesus <[email protected]> Co-authored-by: Zhiyu <[email protected]> Co-authored-by: Juhi Mittal <[email protected]> Co-authored-by: Dmitry Rantovov <[email protected]> Co-authored-by: h-guo18 <[email protected]>
What does this PR do?
Type of change: Bug fix
I found that nesting
only_student_forward()oronly_teacher_forward()causes the outer context to stop working when the inner one exits. This also happens when the inner context usesenable=False.Both context managers reset their flags to
Falseon exit. This change saves the previous value and restores it infinally, so the enclosing context keeps its execution mode, including after an exception.Public APIs, checkpoint handling, and loss calculations are unchanged.
Testing
Added eight regression cases using small local models and real forward passes. They cover:
All eight cases fail before the fix and pass afterward.
Verified with CPU PyTorch:
GPU and distributed integration tests were not run.
Before this PR is ready for review
Summary by CodeRabbit