Repository navigation
Conversation
Signed-off-by: kaix-nv <[email protected]>
|
/claude review |
|
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 (1)
Included review availability: Your plan provides up to 12 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe storage rounding policy now selects the cast sequence from the exact representability relationship between live and storage dtypes. ChangesStorage rounding
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The updated rounding policy handles the intended dtype representability cases without an identified regression. 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.
28b1f1a
into
feature/dasc-state-sparsity-review-rounding
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Addresses the final non-blocking review suggestion on #2392.
Changes:
Validation:
Commit is ED25519-signed and carries a matching Signed-off-by trailer.
Summary by CodeRabbit