Skip to content

Clarify DASC rounding dtype selection - #2393

Merged
kaix-nv merged 1 commit into
feature/dasc-state-sparsity-review-roundingfrom
feature/dasc-state-sparsity-review-rounding-cleanup
Sep 11, 2026
Merged

kaix-nv merged 1 commit into
feature/dasc-state-sparsity-review-roundingfrom
feature/dasc-state-sparsity-review-rounding-cleanup

Conversation

@kaix-nv

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

Copy link
Copy Markdown
Contributor

Addresses the final non-blocking review suggestion on #2392.

Changes:

  • replace the generic containment filter with an explicit three-way dtype selection
  • guarantee a non-empty bound tuple
  • make the exact outcomes obvious: keep live, keep storage, or compose both

Validation:

  • focused DASC tests: 27 passed, 1 skipped (optional Megatron dependency)
  • pre-commit on the touched file: passed

Commit is ED25519-signed and carries a matching Signed-off-by trailer.

Summary by CodeRabbit

  • Bug Fixes
    • Improved numerical handling when determining storage rounding behavior across different data types.
    • Ensured cast sequences are selected according to exact representability between live and storage formats.

@kaix-nv
kaix-nv requested a review from a team as a code owner September 11, 2026 03:45
@kaix-nv
kaix-nv removed the request for review from a team September 11, 2026 03:45
@kaix-nv

kaix-nv commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

/claude review

@kaix-nv
kaix-nv requested a review from rohansjoshi September 11, 2026 03:45
@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: 62cfaec4-6f5c-46e1-aaa0-7d8aefaa4f3f

📥 Commits

Reviewing files that changed from the base of the PR and between aca0183 and 77feb64.

📒 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; 3 remain after this review.


📝 Walkthrough

Walkthrough

The storage rounding policy now selects the cast sequence from the exact representability relationship between live and storage dtypes.

Changes

Storage rounding

Layer / File(s) Summary
Select representable cast sequence
modelopt/torch/sparsity/state_sparsity/policy.py
_storage_rounding_radius now uses the live dtype, storage dtype, or both dtypes before calculating accumulated cast error.

Priority: ⬇️ Low

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

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 77feb

The updated rounding policy handles the intended dtype representability cases without an identified regression.

🚥 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 and concisely describes the main change: clarifying DASC rounding dtype selection.
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 1 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 pull request changes only modelopt/torch/sparsity/state_sparsity/policy.py. The added lines select dtype tuples and introduce no torch.load, numpy.load(..., allow_pickle=True), `trust_…
✨ 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-review-rounding-cleanup

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

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

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

Scope: full review. 1 file changed (+7/-8): modelopt/torch/sparsity/state_sparsity/policy.py.

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

What I verified

Behavioral equivalence with the old filter. storage_dtype is restricted to the validated allowlist {float16, bfloat16, float32} (policy.py:49-53), so I enumerated the new three-way branch against the replaced comprehension for every reachable (storage, live) pair:

storage live old new
fp32 fp32 / fp16 / bf16 (fp32,) / (fp16,) / (bf16,) same
fp16 fp32 / fp16 (fp16,) / (fp16,) same
fp16 bf16 (fp16, bf16) same
bf16 fp32 / bf16 (bf16,) / (bf16,) same
bf16 fp16 (bf16, fp16) same

The old comprehension dropped any dtype whose values another dtype's values exactly fit inside — i.e. keep the narrower. Because _dtype_exactly_contains is a partial order over these dtypes, that is precisely the new selection. It also holds for fp64 and the fp8 dtypes should the allowlist ever widen.

The non-empty-tuple guarantee. The only way old and new can diverge is mutual containment between two distinct dtypes (old produces an empty tuple and therefore a zero radius; new yields (live_dtype,)). That requires two dtypes with identical finfo, which the allowlist makes unreachable. So this is defensive hardening rather than a live-bug fix — matching how the PR description frames it.

Numerical direction preserved. reversed(cast_dtypes) still inverts the live to storage to live chain starting from the materialization cast, and retaining an extra dtype only widens [lower, upper] in _storage_cast_horizon_bounds (a_radius/dt_radius enter with opposite signs), so the bound stays conservative in every branch. No fp32-upcast, reduction-dimension, or division-guard concerns: the reduction runs in float64 on CPU, and 1.0 - unit_roundoff cannot reach zero for any supported dtype.

Branch coverage. All three branches are exercised by existing tests — test_storage_rounding_excludes_exact_fp32_widening (live inside storage), test_bf16_storage_round_trip_loaded_in_fp32_preserves_policy plus test_calibration_uses_storage_canonical_mask_at_wmax_boundary (storage inside live), and test_cross_dtype_reload_accumulates_both_rounding_bounds (incomparable).

Not applicable to this diff. Both helpers are private and module-local — the only callers are _storage_cast_horizon_bounds and the two tests — so there is no mode-registration, modelopt_state schema, public-API, or export-path exposure. No new arguments or config fields, hence no backward-compatibility or CHANGELOG obligation. Nothing here runs on a hot path.

Assessment

Risk: very low. A readability-only refactor that provably preserves behavior across all reachable dtype combinations, with the intent now legible directly from the control flow. Consistent with the CONTRIBUTING preference for simple, surgical changes over clever filtering.

@kaix-nv
kaix-nv merged commit 28b1f1a into feature/dasc-state-sparsity-review-rounding 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 03:50 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.78%. Comparing base (aca0183) to head (77feb64).
⚠️ Report is 1 commits behind head on feature/dasc-state-sparsity-review-rounding.

Additional details and impacted files
@@                               Coverage Diff                                @@
##           feature/dasc-state-sparsity-review-rounding    #2393       +/-   ##
================================================================================
+ Coverage                                        68.74%   78.78%   +10.03%     
================================================================================
  Files                                              548      548               
  Lines                                            64224    64227        +3     
================================================================================
+ Hits                                             44149    50599     +6450     
+ Misses                                           20075    13628     -6447     
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.25% <0.00%> (-0.01%) ⬇️
examples-specdec_bench 13.14% <0.00%> (+<0.01%) ⬆️
examples-speculative_decoding 17.67% <0.00%> (+0.01%) ⬆️
examples-torch_onnx 21.81% <0.00%> (+<0.01%) ⬆️
examples-torch_trt 15.14% <0.00%> (+<0.01%) ⬆️
gpu 58.35% <0.00%> (+37.44%) ⬆️
regression 15.15% <0.00%> (+<0.01%) ⬆️
unit 57.46% <100.00%> (+0.01%) ⬆️

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.

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