Use math.fsum for StaticLossBalancer weight checks - #2491
aniruddh-krovvidi wants to merge 1 commit into
Conversation
Signed-off-by: Aniruddh Krovvidi <akrovvidi05@gmail.com>
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: NVIDIA/Model-Optimizer/.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. 📝 WalkthroughWalkthrough
ChangesLoss balancer precision
Priority: ➖ Normal Estimated code review effort: 1 (Trivial) | ~5 minutes Change: Bug fix · Severity of issue fixed: Medium 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Thanks, but this is likely overkill and not an issue in practice. |
What does this PR do?
Type of change: Bug fix
StaticLossBalancer.__init__checkssum(kd_loss_weight)against1.0. On Python 3.10 and 3.11 (both in the CI matrix) plainsum()is not compensated, so weights that sum to 1 in decimal can come out at0.9999999999999999and trigger the spurious "weights do not sum to 1.0" warning (or, past 1.0, theValueError). Python 3.12+ compensates insidesum(), which is why the check looks fine there.math.fsumgives the correctly rounded sum on every supported version. The samesum()inforward()derived the residualstudent_lossweight, so normalized weights left a1e-16coefficient on it; it now uses the samefsum.Fixes #2488
Usage
Testing
tests/unit/torch/distill/test_distill.py::test_static_loss_balancer_weights_summing_to_one_do_not_warn: fails on Python 3.11 before the change, passes after. Wholetest_distill.pymodule run on 3.11 CPU.Before your PR is "Ready for review"
CONTRIBUTING.md: N/AAdditional Information
The issue's snippet passes a dict, which
sum()cannot take at all; the warning it describes is the list form on a pre-3.12 interpreter.Summary by CodeRabbit
Bug Fixes
Tests