deepspeedai / deepspeedai/DeepSpeed
[BUG] Multiple missing zero-guards cause ZeroDivisionError / non-finite values across DeepSpeed (4 locations)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 43.1k
- Forks
- 5k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 112
Description
Describe the bug
I found 4 related zero-handling issues where divisors/scales are not validated before use.
Three can raise ZeroDivisionError; one can silently propagate inf/nan.
Affected locations
-
deepspeed/utils/groups.py
_ensure_divisibility(numerator, denominator)usesnumerator % denominatorwithout guardingdenominator == 0. -
deepspeed/utils/timer.py
ThroughputTimer._is_report_boundary()checksNonebut not0before:
self.global_step_count % self.steps_per_output. -
deepspeed/inference/v2/inference_utils.py
ceil_div(a, b)returns-(-a // b)without guardingb == 0. -
op_builder/hpu/fp_quantizer.py
FPQuantizer.dequantize()computes(1.0 / scale)without guarding zero elements inscale, which can produce non-finite values and corrupt outputs silently.
To Reproduce
_ensure_divisibility(8, 0)->ZeroDivisionError_is_report_boundary()withsteps_per_output=0->ZeroDivisionErrorceil_div(10, 0)->ZeroDivisionError1.0 / torch.tensor([0.0, 1.0])->tensor([inf, 1.])(same pattern used in HPU dequantize path)
Expected behavior
- Explicit validation for invalid zero values.
- Clear user-facing error messages (or safe clamping where appropriate).
- No raw modulo/division-by-zero exceptions.
- No silent non-finite propagation in dequantization.
Suggested fixes
_ensure_divisibility: add guard before modulo (denominator != 0)._is_report_boundary: treat0as invalid/disabled (if not self.steps_per_output:or explicit<= 0validation).ceil_div: rejectb == 0with clear error.FPQuantizer.dequantize: clamp scale totorch.finfo(scale.dtype).tiny(or validate and fail clearly) before inversion.
System info
- Can provide full
ds_reportoutput if needed. - Repros above are minimal and mostly pure-Python, except item 4 which is on the HPU backend path.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the four affected functions in deepspeed/utils/groups.py, deepspeed/utils/timer.py, deepspeed/inference/v2/inference_utils.py, and op_builder/hpu/fp_quantizer.py. Run the four minimal reproductions from the issue, then determine the intended validation or safe handling for each case. Done means zero inputs produce clear behavior without raw division errors or silent non-finite dequantized values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- distributed-systems, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100