Skip to content

Fix zero/division safety gaps in utility and inference paths - #7855

Draft
harshang03 wants to merge 1 commit into
deepspeedai:masterfrom
harshang03:fix/issue-7838-zero-guards
Draft

harshang03 wants to merge 1 commit into
deepspeedai:masterfrom
harshang03:fix/issue-7838-zero-guards

Conversation

@harshang03

Copy link
Copy Markdown

Describe your changes

  • Added a shared non-zero divisor validator and wired it into group divisibility checks and inference ceil_div.
  • Added strict steps_per_output validation in ThroughputTimer so invalid values fail early instead of triggering modulo-by-zero at runtime.
  • Hardened HPU FP8 dequantization to reject zero or non-finite scales before inverse-scale computation.
  • Added targeted regression tests for groups, timer, inference utils, and HPU quantizer scale validation.

Screenshot or video (only for visual changes)

  • N/A

GitHub Issue Link (if applicable)

Testing Plan

  • Explanation of why no additional tests are needed:
    • Added focused unit tests that directly cover each reported failure mode and guard path.
  • Unit Tests (JS and/or Python):
    • ./.venv/bin/python -m pytest tests/unit/utils/test_groups.py tests/unit/utils/test_timer.py tests/unit/inference/test_inference_utils.py tests/unit/ops/fp_quantizer/test_fp_quantizer_scale_validation.py
  • E2E Tests:
    • Not run (change is utility-level and covered by unit tests).
  • Any manual testing needed?:
    • No.

Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

Add explicit validation for divisor inputs in groups and inference utilities, enforce valid throughput report intervals, and reject invalid HPU dequantization scales to avoid ZeroDivisionError and silent inf/nan propagation.
liuyun7345 added a commit to liuyun7345/DeepSpeed that referenced this pull request Jul 12, 2026
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 <[email protected]>
@liuyun7345

Copy link
Copy Markdown

Following up on the earlier request to pick this up: opened a fresh non-draft PR at #8133 that covers the four #7838 sites with unit tests. Happy to close this draft if maintainers prefer the new PR.

liuyun7345 added a commit to liuyun7345/DeepSpeed that referenced this pull request Nov 6, 2026
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. FP_Quantize.dequantize/selective_dequantize: reject zero/non-finite
   scales before 1/scale, at the shared front-end so every backend is
   covered

Adds accelerator-agnostic regression tests for each failure mode.

Picks up the inactive draft deepspeedai#7855. Fixes deepspeedai#7838.

Rebased onto master, resolving the overlap with deepspeedai#8950 in
deepspeed/ops/fp_quantizer/quantize.py and
tests/unit/ops/fp_quantizer/test_fp_quant.py: both sets of new tests
are kept, and the accidentally duplicated guard tests from the previous
head are deduplicated.

Co-authored-by: Cursor <[email protected]>
Signed-off-by: liuyun7345 <[email protected]>

This branch has not been deployed

No deployments
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.

2 participants