Skip to content

Sort DASC modules by explicit name - #2386

Merged
kaix-nv merged 1 commit into
feature/dasc-state-sparsity-validation-helpersfrom
feature/dasc-state-sparsity-explicit-sort
Sep 11, 2026
Merged

kaix-nv merged 1 commit into
feature/dasc-state-sparsity-validation-helpersfrom
feature/dasc-state-sparsity-explicit-sort

Conversation

@kaix-nv

@kaix-nv kaix-nv commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #2385 addressing its sole defensive Claude suggestion:

  • sort discovered GDN modules with an explicit qualified-name key
  • prevent any hypothetical duplicate-name fallback from comparing nn.Module objects

This PR is intentionally stacked on #2385 because repository rules protect a PR head branch after creation.

Validation

  • focused DASC suite: 23 passed, 1 absent optional Megatron skip
  • DASC plus weight sparsity plus attention sparsity compatibility suite: 134 passed, 1 optional skip
  • full pre-commit on the touched file: passed
  • prior full-package coverage remains 408/408 statements; this change adds no statements and the line is exercised by the focused suite

Summary by CodeRabbit

  • Bug Fixes
    • GDN modules are now returned in a consistent, predictable order.

Signed-off-by: Kai Xu <kaix@nvidia.com>
@kaix-nv
kaix-nv requested a review from a team as a code owner September 11, 2026 02:46
@kaix-nv
kaix-nv requested review from kevalmorabia97 and removed request for a team September 11, 2026 02:46
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview 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: 419e10df-63c6-45ba-ad81-cbe51d54694e

📥 Commits

Reviewing files that changed from the base of the PR and between 2da09a6 and ca749f3.

📒 Files selected for processing (1)
  • modelopt/torch/sparsity/state_sparsity/policy.py

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


📝 Walkthrough

Walkthrough

The state sparsity policy now sorts GDN modules explicitly by module name before returning them. This replaces default tuple sorting and makes module ordering deterministic.

Changes

State sparsity policy

Layer / File(s) Summary
Deterministic GDN module ordering
modelopt/torch/sparsity/state_sparsity/policy.py
_get_gdn_modules sorts discovered modules by name before constructing the returned dictionary.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Merge Risk: ⚪ Minimal · up to ca749

The deterministic ordering change is covered by the passing validation results and is ready to merge.

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: sorting DASC modules by an explicit name. It is concise and specific.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files.
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 authoritative diff changes only _get_gdn_modules in policy.py, replacing default tuple sorting with key=lambda item: item[0]. The added line does not load data, execute code, add `# no…
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/dasc-state-sparsity-explicit-sort

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

@kaix-nv

kaix-nv commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

/claude review

@claude

claude Bot commented Sep 11, 2026

Copy link
Copy Markdown

Claude review summary

Scope: full review — the trigger comment carried no extra scoping. 1 file changed (+1/-1), modelopt/torch/sparsity/state_sparsity/policy.py, reviewed in full along with the surrounding _get_gdn_modules helper.

Findings: CRITICAL: 0, IMPORTANT: 0, SUGGESTION: 0

Analysis

The change replaces dict(sorted(identity_modules)) with dict(sorted(identity_modules, key=lambda item: item[0])).

  • Ordering is unchanged. identity_modules is a list[tuple[str, nn.Module]] filtered from model.named_modules(). Since named_modules() yields unique qualified-name paths, the tuple comparison in the old code only ever compared element 0, so the explicit key produces byte-identical ordering. Downstream consumers of the returned dict (horizon analysis in _analyze_gdn_modules, and anything relying on deterministic module iteration order) see no change.
  • The defensive intent holds. The old form would fall through to comparing nn.Module objects on a name tie and raise TypeError: '<' not supported between instances of .... The key eliminates that path without adding a branch.
  • No composability or compatibility surface touched. Private helper, no mode registration, no modelopt_state schema, no config field, no public export, no signature or default change. Nothing to migrate or version-bump.
  • No CHANGELOG.rst entry needed — per the repo guidance, defensive hardening of a code path introduced in the same unreleased cycle is not changelog-worthy.
  • Performance: the lambda adds one Python call per discovered GDN module during one-time mode application. Not a hot path.

Risk assessment

Very low. Single-line, order-preserving, and it strictly narrows a latent failure mode. The stated validation (focused DASC suite plus the DASC / weight-sparsity / attention-sparsity compatibility suite) exercises this line.

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude review passed — no blocking issues found. LGTM

@kaix-nv
kaix-nv merged commit 1b2d494 into feature/dasc-state-sparsity-validation-helpers Sep 11, 2026
15 of 16 checks passed
@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-09-11 02:55 UTC

@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.76%. Comparing base (2da09a6) to head (ca749f3).
⚠️ Report is 1 commits behind head on feature/dasc-state-sparsity-validation-helpers.

Additional details and impacted files
@@                                 Coverage Diff                                 @@
##           feature/dasc-state-sparsity-validation-helpers    #2386       +/-   ##
===================================================================================
+ Coverage                                           67.60%   78.76%   +11.16%     
===================================================================================
  Files                                                 548      548               
  Lines                                               64193    64192        -1     
===================================================================================
+ Hits                                                43395    50564     +7169     
+ Misses                                              20798    13628     -7170     
Flag Coverage Δ
examples-diffusers 20.81% <0.00%> (+0.01%) ⬆️
examples-gpt-oss 13.38% <0.00%> (+<0.01%) ⬆️
examples-hf_ptq 21.78% <0.00%> (+0.01%) ⬆️
examples-llm_distill 13.45% <0.00%> (+<0.01%) ⬆️
examples-llm_eval 17.25% <0.00%> (+0.02%) ⬆️
examples-llm_qat 17.59% <0.00%> (+0.03%) ⬆️
examples-llm_sparsity 15.94% <0.00%> (+<0.01%) ⬆️
examples-megatron_bridge 26.26% <0.00%> (-0.01%) ⬇️
examples-specdec_bench 13.13% <0.00%> (+<0.01%) ⬆️
examples-speculative_decoding 17.67% <0.00%> (+0.02%) ⬆️
examples-torch_onnx 21.82% <0.00%> (+0.01%) ⬆️
examples-torch_trt 15.14% <0.00%> (+<0.01%) ⬆️
gpu 58.38% <0.00%> (+42.83%) ⬆️
regression 15.15% <0.00%> (+<0.01%) ⬆️
unit 57.44% <100.00%> (ø)

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.

kaix-nv added a commit that referenced this pull request Sep 11, 2026
## Summary

Consolidates the complete reviewed fix stack for #2375 into one DCO-safe
commit:

- harden package exports, measurement semantics, wrapper handling, and
actionable calibration errors
- validate exact installed GDN identities plus ModelOpt dynamic
subclasses; reject lookalikes, ordinary subclasses, incomplete layers,
and partial layer sets
- make stale checkpoints saveable and restorable while keeping
deployment export strict
- make DASC recalibration replace and deduplicate existing mode state
without stale-metadata refresh
- record the declared decay-parameter checkpoint storage dtype and use
derived FP16/BF16/FP32 rounding bounds
- preserve BF16/FP16 storage and wider/cross-dtype reload compatibility
without globally widening FP32 tolerance
- add installed Transformers path coverage, optional Megatron gating,
lifecycle, tamper, lossy-cast, and mixed-layer regressions
- document the explicit storage-dtype contract

This consolidated PR supersedes the mechanically stacked review-fix PRs
#2377, #2378, #2379, #2380, #2382, #2383, #2384, and #2385. Its tree is
byte-identical to the independently reviewed leaf commit from #2386.

## Validation

- focused DASC suite: 23 passed, 1 absent optional Megatron skip
- DASC plus weight sparsity plus attention sparsity compatibility suite:
134 passed, 1 optional skip
- DASC package coverage: 408/408 statements, 100%
- full pre-commit on all touched files: passed
- real Transformers Qwen3NextGatedDeltaNet BF16 storage to FP32 reload
smoke: passed
- commit author and Signed-off-by identity both use kaix-nv
<kaix@nvidia.com>

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added support for configuring decay-parameter storage precision with
FP16, BF16, or FP32.
  * Added safer recalibration that replaces existing DASC state.
* Expanded compatibility with supported GDN adapter classes and model
wrappers.
* Added improved validation for sparsity policies, measurements, model
structure, and decay parameters.
  * Added support for perplexity-retention values above 1.

* **Documentation**
* Clarified evaluation responsibilities, recalibration behavior,
stale-policy handling, supported adapters, and dtype requirements.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: kaix-nv <kaix@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant