Skip to content

Fix selected layers being skipped by post-init sparsity - #2345

Merged
kevalmorabia97 merged 2 commits into
NVIDIA:mainfrom
darkdi:fix/puzzletron-weight-suffix
Oct 27, 2026
Merged

kevalmorabia97 merged 2 commits into
NVIDIA:mainfrom
darkdi:fix/puzzletron-weight-suffix

Conversation

@darkdi

@darkdi darkdi commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Type of change: Bug fix

do_sparsity() silently skips selected layers such as dense and gate: rstrip(".weight") treats its argument as a set of characters, turning dense.weight into dens and gate.weight into ga. 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 dense and gate because no pruning mask is attached; the proj control passes. With the fix, all three cases pass and verify the mask and resulting weights. All 13 tests in test_post_init_sparse.py and test_common.py pass 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.).

  • Is this change backward compatible?: ✅
  • If you copied code from any other sources or added a new PIP dependency, did you follow guidance in CONTRIBUTING.md: N/A
  • Did you write any new necessary tests?: ✅
  • Did you update Changelog?: N/A
  • Did you get Claude approval on this PR?: N/A

Additional Information

Found while inspecting the layer-name filtering in the post-initialization sparsity helper.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed sparsity processing for layers whose names include .weight, ensuring the correct model parameters are matched and updated.
  • Tests

    • Added coverage for structured 2:4 sparsity across dense, gate, and proj MLP layers, including mask placement and resulting weight values.

@darkdi
darkdi requested review from a team as code owners September 6, 2026 16:17
@copy-pr-bot

copy-pr-bot Bot commented Sep 6, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d0629883-72ae-4afa-bd0c-654ec6d055f0

📥 Commits

Reviewing files that changed from the base of the PR and between a7f339e and 9586109.

📒 Files selected for processing (2)
  • modelopt/torch/puzzletron/tools/post_init_sparse.py
  • tests/unit/torch/puzzletron/test_post_init_sparse.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The change fixes state-dict key normalization for sparsified layers. New parametrized tests verify 2:4 masks and masked weights for dense, gate, and proj MLP layers.

Changes: Post-initialization sparsity

Layer / File(s) Summary
Exact weight-key normalization and sparsity validation
modelopt/torch/puzzletron/tools/post_init_sparse.py, tests/unit/torch/puzzletron/test_post_init_sparse.py
The sparsity method removes the exact .weight suffix. Tests verify expected 2:4 masks and masked weights for supported MLP layer names.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · previous review 95861

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing skipped layers during post-initialization sparsity.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security Anti-Patterns ✅ Passed PASS. The PR changes only two suffix-matching expressions in modelopt/torch/puzzletron/tools/post_init_sparse.py and adds a test file. The added and modified Python lines contain no `torch.load(...,…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@darkdi

darkdi commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Could a PR vetter approve the CI run for this fix? The regression test exercises SparsityMethod2o4.do_sparsity() with dense, gate and proj layers; dense and gate failed before the fix. All 13 targeted tests and the applicable pre-commit hooks pass locally. DCO and CodeRabbit pass; the NVIDIA runner validation is the remaining step before the upstream tests can run.

@kevalmorabia97 kevalmorabia97 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve: correct one-line fix (rstrip(".weight") strips characters, not a suffix) with a regression test that fails without it.

No action needed:

  • k.rstrip(".weight") turned ...mlp.dense.weight into ...mlp.dens and ...gate.weight into ...gat, so those layers were never in full_name_layers and were silently skipped; removesuffix fixes it.
  • Reproduced: the test's dense and gate cases fail on main (no attribute 'weight_mask') and all three pass on the PR; proj is a control.
  • No other rstrip/strip misuse in post_init_sparse.py.
  • No changelog needed; not a setup-owned path.

@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test 9586109

@kevalmorabia97
kevalmorabia97 enabled auto-merge (squash) October 26, 2026 20:19
@kevalmorabia97

Copy link
Copy Markdown
Collaborator

/ok to test b86eaa2

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 73.97%. Comparing base (cc016cc) to head (b86eaa2).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2345      +/-   ##
==========================================
- Coverage   77.50%   73.97%   -3.53%     
==========================================
  Files         661      661              
  Lines       74977    90337   +15360     
==========================================
+ Hits        58110    66830    +8720     
- Misses      16867    23507    +6640     
Flag Coverage Δ
examples-diffusers 19.92% <ø> (+0.02%) ⬆️
examples-gpt-oss 13.45% <ø> (+<0.01%) ⬆️
examples-hf_ptq 23.36% <ø> (-0.03%) ⬇️
examples-llm_distill 13.53% <ø> (+<0.01%) ⬆️
examples-llm_eval 17.19% <ø> (+0.01%) ⬆️
examples-llm_qat 17.37% <ø> (-0.01%) ⬇️
examples-llm_sparsity 16.77% <ø> (+<0.01%) ⬆️
examples-megatron_bridge 26.50% <ø> (-0.20%) ⬇️
examples-specdec_bench 13.23% <ø> (-0.01%) ⬇️
examples-speculative_decoding 17.44% <ø> (-0.05%) ⬇️
examples-torch_onnx 21.23% <ø> (-0.02%) ⬇️
examples-torch_trt 15.17% <ø> (+0.01%) ⬆️
examples-vllm_serve 17.41% <ø> (+0.01%) ⬆️
gpu 59.05% <ø> (+8.01%) ⬆️
regression 15.05% <ø> (-0.01%) ⬇️
unit 61.25% <ø> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kevalmorabia97
kevalmorabia97 merged commit aed61b7 into NVIDIA:main Oct 27, 2026
69 of 72 checks passed
kevalmorabia97 added a commit that referenced this pull request Oct 28, 2026
#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]>
@rohansjoshi rohansjoshi added the cherry-pick-done Added by bot once PR is cherry-picked to the release branch label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-0.48.0 cherry-pick-done Added by bot once PR is cherry-picked to the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants