Repository navigation
Add end-to-end BF16 stage 1 tests for zero and invalid gradient norms - #8614
Open
vineethsaivs wants to merge 1 commit into
Open
vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
vineethsaivs
requested review from
loadams,
tjruwase and
tohtana
as code owners
September 20, 2026 19:42
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The training-loop behavior needs integration coverage using an initialized BF16 optimizer rather than a private-state stand-in.
Review effort: Balanced
Findings: 1
What changed in this PR
Improves BF16 gradient-norm handling by allowing valid zero norms while rejecting the -1 non-finite sentinel with an actionable error.
Changes:
- Replaces the optimization-removable assertion with an explicit runtime check.
- Adds focused tests for zero, non-finite, and ordinary gradient norms.
| File | Description |
|---|---|
deepspeed/runtime/bf16_optimizer.py |
Validates gradient norms before clipping. |
tests/unit/runtime/half_precision/test_bf16_grad_norm_guard.py |
Tests gradient-norm guard behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+39
to
+42
| class _Bf16Step: | ||
| """The parts of BF16_Optimizer.step that reaching the guard needs, and nothing else.""" | ||
|
|
||
| step = BF16_Optimizer.step |
Contributor
Author
There was a problem hiding this comment.
Done in 2541d80: the stand-in is replaced by an engine test with a real BF16_Optimizer (ZeRO 1, bf16, fp32 grad accumulation), covering the zero-gradient step and the non-finite error.
Run a ZeRO stage 1 bf16 engine through deepspeed.initialize for two cases: an all-zero-gradient step (norm 0) still runs, and an inf loss skips the step (skipped_steps == 1) and leaves the parameters unchanged. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
vineethsaivs
force-pushed
the
fix-bf16-zero-norm-assert-20260920
branch
from
October 22, 2026 15:33
2541d80 to
9284f23
Compare
This branch has not been deployed
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.

Adds two end-to-end BF16 ZeRO stage 1 tests, built through
deepspeed.initialize: an all-zero-gradient step (fully masked batch) runs and reports norm 0, and an inf loss skips the step (skipped_steps == 1) with parameters unchanged.Not a duplicate: #8638 already changed the behavior this PR first targeted, so the source change is dropped. Its only BF16 skip test,
test_bf16_optimizer_reports_invalid_step_and_recovers, mocks the norm; nothing covers these two cases on a real engine. No other open PR adds them.Tests (CPU only, current master):
pytest tests/unit/runtime/half_precision/test_bf16_grad_norm_guard.py: 2 passed. Both fail ifassert all_groups_norm > 0.is restored.pytest tests/unit/v1/zero/test_invalid_grad_norm.py: 17 passed, 1 skipped (needs 2 GPUs).GPU/NPU and the compatibility matrix were not run.