fix: add zero-guards for divisor/scale edge cases (#7838)#8133
Open
liuyun7345 wants to merge 1 commit into
Open
fix: add zero-guards for divisor/scale edge cases (#7838)#8133liuyun7345 wants to merge 1 commit into
liuyun7345 wants to merge 1 commit into
Conversation
Prevent ZeroDivisionError and silent non-finite propagation at four reported sites: 1. groups._ensure_divisibility: reject denominator == 0 before modulo 2. ThroughputTimer: reject non-positive steps_per_output at init and report-boundary time 3. inference_utils.ceil_div: reject divisor == 0 4. HPU FPQuantizer.dequantize: reject zero/non-finite scales before 1/scale Adds focused unit tests covering each failure mode. Picks up the inactive draft deepspeedai#7855. Fixes deepspeedai#7838 Signed-off-by: liuyun7345 <liuyun7345@sina.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #7838 by adding explicit zero/non-finite guards at the four reported sites so DeepSpeed fails early with a clear error instead of raising raw
ZeroDivisionErroror silently propagatinginf/nan.This picks up the inactive draft #7855 (no updates since 2026-02-17).
Changes
deepspeed/utils/groups.py—_ensure_divisibilityassertsdenominator != 0before modulo.deepspeed/utils/timer.py—ThroughputTimerrejects non-positivesteps_per_outputin__init__, and_is_report_boundaryre-checks if the attribute is later mutated.deepspeed/inference/v2/inference_utils.py—ceil_divraisesValueErrorwhenb == 0.op_builder/hpu/fp_quantizer.py—dequantizerejects zero / non-finite scales before computing1.0 / scale.tests/unit/utils/test_zero_guards.py— regression tests for each failure mode (HPU builder tests skip if that module is unavailable).Test plan
_ensure_divisibility(8, 0)raises clear AssertionError_ensure_divisibilityinputs still passceil_div(10, 0)raises ValueErrorceil_divmatchesmath.ceilfor valid inputsThroughputTimer(..., steps_per_output=0/-1)raises ValueErrorsteps_per_output=0is caught in_is_report_boundarydequantizerejects zero / NaN / zero-scalar scales before HPU opFixes #7838