Invalidate sharded sparsity masks after updating the source mask - #2370
Invalidate sharded sparsity masks after updating the source mask#2370MrCapricornLiu 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 (3)
Included review availability: Your plan provides up to 12 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughThe change fixes DTensor mask cache handling in ChangesSparsity mask cache updates
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: Merge Risk: ⚪ Minimal · up to This fixes stale sparsity masks for FSDP2 reads and exports without changing the public API or checkpoint format. The targeted regression coverage passes, so the change is ready to merge. 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What does this PR do?
Type of change: Bug fix
Calling
set_mask()after FSDP2 sharding can leave the previous sparsity mask active when reading or exporting the sharded weight. The method invalidates its DTensor cache first, but then readsself.weight.shapefor validation. That dynamic weight access rebuilds the cache from the old mask before the mask buffer is updated.Invalidate the cache after updating the source mask instead, including the
Nonepath. Subsequent weight reads and sparse export then use the newly requested mask.Usage
No API change.
SparseModule.set_mask()updates the mask used by sharded weights and their exported state.Testing
tests/gpu/torch/sparsity/weight_sparsity/test_sparse_fsdp.pypass on two H800 GPUs, including the existing FSDP tests and new FP32/BF16 cases with and without a prior sparse mask.tests/unit/torch/sparsity/weight_sparsity/test_sparsify.pypass.Multi-node execution, CPU offload and performance were not tested. The change addresses
set_mask(); direct in-place mutation or checkpoint loading into an already populated cache is outside this regression.Before your PR is "Ready for review"
Additional Information
The DTensor mask cache was introduced in #1818. This corrects its invalidation ordering without changing the sharding strategy.
Summary by CodeRabbit
Bug Fixes
Tests