Fix selected layers being skipped by post-init sparsity - #2345
Conversation
Signed-off-by: Dmitry Rantovov <rantovov5@gmail.com>
|
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 (2)
Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review. 📝 WalkthroughWalkthroughThe change fixes state-dict key normalization for sparsified layers. New parametrized tests verify 2:4 masks and masked weights for ChangesPost-initialization sparsity
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to Post-initialization sparsity now preserves selected layer names when removing the .weight suffix, and regression coverage verifies correct 2:4 pruning for the affected MLP layer names. No current merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What does this PR do?
Type of change: Bug fix
do_sparsity()silently skips selected layers such asdenseandgate:rstrip(".weight")treats its argument as a set of characters, turningdense.weightintodensandgate.weightintoga. Those names no longer match the selected modules. Remove the literal suffix instead.Usage
No API changes. The regression test builds a small model and applies
SparsityMethod2o4().do_sparsity(model)to each selected layer.Testing
On main, the regression test fails for
denseandgatebecause no pruning mask is attached; theprojcontrol passes. With the fix, all three cases pass and verify the mask and resulting weights. All 13 tests intest_post_init_sparse.pyandtest_common.pypass on CPU. Pre-commit checks pass for both changed files.Before 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
Found while inspecting the layer-name filtering in the post-initialization sparsity helper.
Summary by CodeRabbit
Bug Fixes
.weight, ensuring the correct model parameters are matched and updated.Tests
dense,gate, andprojMLP layers, including mask placement and resulting weight values.