Repository navigation
Improve overflow handling in ZeRO - #6976
Merged
Merged
Conversation
Contributor
Author
|
@delock, @inkcherry, can you please help investigate the failing xpu-max1100 CI? Thanks! |
loadams
reviewed
Jan 30, 2025
Collaborator
@tjruwase thanks! Our engineer is looking into it. |
…o olruwase/ds_5241
Signed-off-by: Olatunji Ruwase <[email protected]>
|
Any ETA on this for merge? |
Contributor
Author
|
loadams
approved these changes
Jun 9, 2025
loadams
enabled auto-merge (squash)
June 9, 2025 16:39
deepcharm
pushed a commit
to deepcharm/DeepSpeed
that referenced
this pull request
Jun 16, 2025
Fix deepspeedai#5241: Improve overflow handling - [x] ZeRO 1 - [x] ZeRO 2 - [ ] ZeRO 3 - [ ] BF16Optimizer Enable pydantic configuration for mixed precision - [x] bf16 - [x] fp16 --------- Signed-off-by: Olatunji Ruwase <[email protected]> Signed-off-by: Fabien Dupont <[email protected]> Signed-off-by: Logan Adams <[email protected]> Signed-off-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Xinyu Lian <[email protected]> Co-authored-by: loadams <[email protected]> Co-authored-by: Omar Elayan <[email protected]> Co-authored-by: Fabio Geraci <[email protected]> Co-authored-by: Sam Foreman <[email protected]> Co-authored-by: Fabien Dupont <[email protected]> Co-authored-by: Liangliang Ma <[email protected]> Co-authored-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Olatunji Ruwase <[email protected]> Signed-off-by: Max Kovalenko <[email protected]>
Antlera
pushed a commit
to Antlera/DeepSpeed
that referenced
this pull request
Jun 27, 2025
Fix deepspeedai#5241: Improve overflow handling - [x] ZeRO 1 - [x] ZeRO 2 - [ ] ZeRO 3 - [ ] BF16Optimizer Enable pydantic configuration for mixed precision - [x] bf16 - [x] fp16 --------- Signed-off-by: Olatunji Ruwase <[email protected]> Signed-off-by: Fabien Dupont <[email protected]> Signed-off-by: Logan Adams <[email protected]> Signed-off-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Xinyu Lian <[email protected]> Co-authored-by: loadams <[email protected]> Co-authored-by: Omar Elayan <[email protected]> Co-authored-by: Fabio Geraci <[email protected]> Co-authored-by: Sam Foreman <[email protected]> Co-authored-by: Fabien Dupont <[email protected]> Co-authored-by: Liangliang Ma <[email protected]> Co-authored-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Olatunji Ruwase <[email protected]>
mauryaavinash95
pushed a commit
to DataStates/DeepSpeed
that referenced
this pull request
Oct 4, 2025
Fix deepspeedai#5241: Improve overflow handling - [x] ZeRO 1 - [x] ZeRO 2 - [ ] ZeRO 3 - [ ] BF16Optimizer Enable pydantic configuration for mixed precision - [x] bf16 - [x] fp16 --------- Signed-off-by: Olatunji Ruwase <[email protected]> Signed-off-by: Fabien Dupont <[email protected]> Signed-off-by: Logan Adams <[email protected]> Signed-off-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Xinyu Lian <[email protected]> Co-authored-by: loadams <[email protected]> Co-authored-by: Omar Elayan <[email protected]> Co-authored-by: Fabio Geraci <[email protected]> Co-authored-by: Sam Foreman <[email protected]> Co-authored-by: Fabien Dupont <[email protected]> Co-authored-by: Liangliang Ma <[email protected]> Co-authored-by: inkcherry <[email protected]> Co-authored-by: Logan Adams <[email protected]> Co-authored-by: Olatunji Ruwase <[email protected]>
2 tasks done
banxingmjj
pushed a commit
to openanolis/DeepSpeed
that referenced
this pull request
Jun 26, 2026
…ai#8035) ## Summary Flip `DeepSpeedBF16Config.check_grad_overflow` default from `False` to `True`, so bf16 users get the same gradient-overflow protection that fp16 users already get by default. ## Motivation The bf16 documentation states bf16 "does not require loss scaling" (deepspeed.ai/docs/config-json/), but this overstates the safety guarantee for the bf16 + ZeRO-2 (non-offload) partition-flat gradient accumulation path. We reproduced a deterministic catastrophic NaN under a small set of training conditions: - ZeRO-2 (non-offload) + bf16 - Mixture-of-Transformers (modality-specific transformer branches) - Heterogeneous per-sample loss masks (e.g. 50% action-invalid samples in robotics VLA training) Under these conditions, a single bf16 element in `engine.optimizer.averaged_gradients[i]` overflows to `+inf`. The downstream `Adam.step` then computes `inf / sqrt(inf) = NaN` in a fused kernel, which simultaneously corrupts the partition slice's `exp_avg`, `exp_avg_sq`, and fp32 master weights. The next forward pass propagates NaN through every layer; the training run is dead with no useful diagnostic. Reproduced consistently in DeepSpeed 0.16.9 - 0.17.1 at step ~22 with our internal repro. The infrastructure to detect and skip such steps was correctly added by deepspeedai#6976 (`check_grad_overflow` option, `DeepSpeedZeroOptimizer.check_overflow` method, and step-skip logic at `stage_1_and_2.step()` lines ~2128-2143). However the default was set to `False` for bf16, so users hitting this condition do not receive the protection. ## Change Single line: `check_grad_overflow: bool = False` -> `check_grad_overflow: bool = True` in `DeepSpeedBF16Config`. Updated docstring + bf16 example block accordingly. ## Backward compatibility Users who have benchmarked the check as too expensive AND have separately confirmed their bf16 path cannot overflow can opt out by setting: \`\`\`json "bf16": { "enabled": true, "check_grad_overflow": false } \`\`\` The runtime cost is one isfinite-style scan over the gradient partition per optimizer step (already implemented in `DeepSpeedZeroOptimizer.check_overflow`); typically under 1% of step wallclock. ## Related - Issue deepspeedai#5242 (open) - bf16+ZeRO-2 NaN on real training runs (Baichuan2-7B + 8x A800) - PR deepspeedai#6976 - introduced `check_grad_overflow` option and underlying skip logic ## Test plan - [x] Reproducer (private repo): with default `False`, run dies at step ~22; with `True`, training survives via DeepSpeed's existing skip-step path. - [x] Existing CI should pass unchanged; this PR only changes a default value in `precision_config.py`. Signed-off-by: Yongzhe Wang <[email protected]>
nathon-lee
pushed a commit
to nathon-lee/DeepSpeed_woo
that referenced
this pull request
Jul 1, 2026
…ai#8035) ## Summary Flip `DeepSpeedBF16Config.check_grad_overflow` default from `False` to `True`, so bf16 users get the same gradient-overflow protection that fp16 users already get by default. ## Motivation The bf16 documentation states bf16 "does not require loss scaling" (deepspeed.ai/docs/config-json/), but this overstates the safety guarantee for the bf16 + ZeRO-2 (non-offload) partition-flat gradient accumulation path. We reproduced a deterministic catastrophic NaN under a small set of training conditions: - ZeRO-2 (non-offload) + bf16 - Mixture-of-Transformers (modality-specific transformer branches) - Heterogeneous per-sample loss masks (e.g. 50% action-invalid samples in robotics VLA training) Under these conditions, a single bf16 element in `engine.optimizer.averaged_gradients[i]` overflows to `+inf`. The downstream `Adam.step` then computes `inf / sqrt(inf) = NaN` in a fused kernel, which simultaneously corrupts the partition slice's `exp_avg`, `exp_avg_sq`, and fp32 master weights. The next forward pass propagates NaN through every layer; the training run is dead with no useful diagnostic. Reproduced consistently in DeepSpeed 0.16.9 - 0.17.1 at step ~22 with our internal repro. The infrastructure to detect and skip such steps was correctly added by deepspeedai#6976 (`check_grad_overflow` option, `DeepSpeedZeroOptimizer.check_overflow` method, and step-skip logic at `stage_1_and_2.step()` lines ~2128-2143). However the default was set to `False` for bf16, so users hitting this condition do not receive the protection. ## Change Single line: `check_grad_overflow: bool = False` -> `check_grad_overflow: bool = True` in `DeepSpeedBF16Config`. Updated docstring + bf16 example block accordingly. ## Backward compatibility Users who have benchmarked the check as too expensive AND have separately confirmed their bf16 path cannot overflow can opt out by setting: \`\`\`json "bf16": { "enabled": true, "check_grad_overflow": false } \`\`\` The runtime cost is one isfinite-style scan over the gradient partition per optimizer step (already implemented in `DeepSpeedZeroOptimizer.check_overflow`); typically under 1% of step wallclock. ## Related - Issue deepspeedai#5242 (open) - bf16+ZeRO-2 NaN on real training runs (Baichuan2-7B + 8x A800) - PR deepspeedai#6976 - introduced `check_grad_overflow` option and underlying skip logic ## Test plan - [x] Reproducer (private repo): with default `False`, run dies at step ~22; with `True`, training survives via DeepSpeed's existing skip-step path. - [x] Existing CI should pass unchanged; this PR only changes a default value in `precision_config.py`. Signed-off-by: Yongzhe Wang <[email protected]> Signed-off-by: nathon-lee <[email protected]>
nathon-lee
pushed a commit
to nathon-lee/DeepSpeed_woo
that referenced
this pull request
Jul 1, 2026
…ai#8035) ## Summary Flip `DeepSpeedBF16Config.check_grad_overflow` default from `False` to `True`, so bf16 users get the same gradient-overflow protection that fp16 users already get by default. ## Motivation The bf16 documentation states bf16 "does not require loss scaling" (deepspeed.ai/docs/config-json/), but this overstates the safety guarantee for the bf16 + ZeRO-2 (non-offload) partition-flat gradient accumulation path. We reproduced a deterministic catastrophic NaN under a small set of training conditions: - ZeRO-2 (non-offload) + bf16 - Mixture-of-Transformers (modality-specific transformer branches) - Heterogeneous per-sample loss masks (e.g. 50% action-invalid samples in robotics VLA training) Under these conditions, a single bf16 element in `engine.optimizer.averaged_gradients[i]` overflows to `+inf`. The downstream `Adam.step` then computes `inf / sqrt(inf) = NaN` in a fused kernel, which simultaneously corrupts the partition slice's `exp_avg`, `exp_avg_sq`, and fp32 master weights. The next forward pass propagates NaN through every layer; the training run is dead with no useful diagnostic. Reproduced consistently in DeepSpeed 0.16.9 - 0.17.1 at step ~22 with our internal repro. The infrastructure to detect and skip such steps was correctly added by deepspeedai#6976 (`check_grad_overflow` option, `DeepSpeedZeroOptimizer.check_overflow` method, and step-skip logic at `stage_1_and_2.step()` lines ~2128-2143). However the default was set to `False` for bf16, so users hitting this condition do not receive the protection. ## Change Single line: `check_grad_overflow: bool = False` -> `check_grad_overflow: bool = True` in `DeepSpeedBF16Config`. Updated docstring + bf16 example block accordingly. ## Backward compatibility Users who have benchmarked the check as too expensive AND have separately confirmed their bf16 path cannot overflow can opt out by setting: \`\`\`json "bf16": { "enabled": true, "check_grad_overflow": false } \`\`\` The runtime cost is one isfinite-style scan over the gradient partition per optimizer step (already implemented in `DeepSpeedZeroOptimizer.check_overflow`); typically under 1% of step wallclock. ## Related - Issue deepspeedai#5242 (open) - bf16+ZeRO-2 NaN on real training runs (Baichuan2-7B + 8x A800) - PR deepspeedai#6976 - introduced `check_grad_overflow` option and underlying skip logic ## Test plan - [x] Reproducer (private repo): with default `False`, run dies at step ~22; with `True`, training survives via DeepSpeed's existing skip-step path. - [x] Existing CI should pass unchanged; this PR only changes a default value in `precision_config.py`. Signed-off-by: Yongzhe Wang <[email protected]>
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.
Fix #5241: Improve overflow handling
Enable pydantic configuration for mixed precision