Release cached activations when exporting distillation models - #2368
Release cached activations when exporting distillation models#2368MrCapricornLiu wants to merge 1 commit into
Conversation
Signed-off-by: Chenghao Liu <chliu@stu.pku.edu.cn>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review. 📝 WalkthroughWalkthroughDistillation export now clears cached intermediate outputs and inputs from student and teacher layers. Regression tests verify garbage collection, attribute removal, preserved outputs, and hook behavior. ChangesDistillation export cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to Distillation export now releases cached student and teacher activations while preserving model outputs and user hooks. Current tests cover standard and layerwise cleanup, so the change is merge-ready. 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What does this PR do?
Type of change: Bug fix
After a distillation forward pass,
mtd.export()removes the capture hooks but leaves their last outputs attached to the student and teacher layers. Student outputs can retain an autograd graph even though distillation has finished. Layerwise distillation can also retain teacher inputs after a teacher-only forward.Remove these caches when exporting, deduplicating shared layers so a layer used by multiple loss pairs is cleaned up once. Existing unrelated user hooks remain installed.
Usage
The existing
mtd.export(model)call releases the distillation caches; no API change is required.Testing
tests/unit/torch/distill/test_distill.pyandtest_layerwise.pypass.Distributed execution, checkpoint serialization, and full-model training performance were not tested.
Before your PR is "Ready for review"
Additional Information
Related to the activation-retention report in item 6 of #1926 and #1923. Other reports in #1926 are outside this change.
Summary by CodeRabbit
Bug Fixes
Tests