Release each BF16 gradient once immediate_grad_update has accumulated it #8654
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 643 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.387
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8654"
general
weight: 0.35
0z5a
Summary
With
bf16.immediate_grad_update,BF16_Optimizeraccumulates each completed BF16 parameter gradient in the configured accumulation buffer (FP32 in the measured configuration). Previously it retained the BF16param.gradbeside that buffer until the optimizer step. The hook now releases the consumed gradient withparam.grad = None. With the option disabled, accumulation still happens in the backward epilogue; its default remains unchanged.For folded AutoEP+AutoTP (TP>1), the BF16 hook also applies folding correction before accumulation. A correction marker left on the parameter after
param.gradbecomesNonecannot be cleared by the engine's boundary reducer, which skips missing gradients; a later backward could therefore miss correction. The hook now clears that marker when it consumes and releases the corresponding BF16 gradient.This branch includes current upstream
master, which removed graph harvesting in #8579. The release hook no longer accesses that removed attribute. It also fixes the BF16 gradient-reconstruction issue exposed by releasingparam.grad: each rank contributes only its optimizer-owned fragment, even though BF16 keeps a full accumulation buffer on every rank. BF16's mapping indexes its full parameter list rather than ZeRO's local fragment list.Why
In a Qwen3-30B-A3B AutoEP training workload (S8192, EP16, 48 layers, 16 NVIDIA H100 GPUs, ZeRO Stage 1, FP32 gradient accumulation), an allocator trace locates peak allocation at the end of backward, when BF16 gradients occupy 6.7 GB per rank beside the accumulation buffers.
Results (16 NVIDIA H100 80GB HBM3)
Same allocation, four mirrored repeats per arm:
| | epilogue accumulation | immediate accumulation + BF16 grad release |
| --- | --- | --- |
| peak allocated | 54.439 GB | 50.434 GB |
| peak reserved | 57.481 GB | 56.762 GB |
| median step | 2654.2 ms | 2615.6 ms (-1.45%; 95% CI crosses zero) |
This A/B comparison changes the accumulation mode together with BF16 gradient release. It does not isolate the speedup or memory effect of the single
param.grad = Noneassignment. Step-0 losses match; the maximum cross-arm loss difference across 24 steps is 0.0091, versus 0.0072-0.0085 within an arm. Peak allocation falls by about 4.0 GB, less than the 6.7 GB of freed BF16 gradients because the peak moves to another point in backward.Numerical contract
After backward,
param.gradmay beNonewith immediate accumulation. In that casedeepspeed.utils.safe_get_full_grad(param)reconstructs the accumulation buffer from owned fragments beforeengine.step()(FP32 when FP32 accumulation is configured). All participating DP ranks must call this collective getter in the same order. Reduction uses the accumulation buffers viaget_grads_for_reduction; norm, clipping and the optimizer step use them viaget_grads_for_normand the FP32 partitions.Testing Done
Dependencies and scope
The non-immediate folded path's separate GAS>1 marker behavior is not changed; the two-micro-batch regression compares against a non-folded reference instead. Full folded-MoE BF16 Stage-1 integration has a separate pre-existing empty non-expert norm issue on non-zero TP ranks; the focused TP2 test isolates the gradient-lifecycle contract and does not claim full folded-MoE E2E acceptance. The
FP16_OptimizerMoE grad-norm fix (#8635) has merged upstream and is inherited frommaster, not included as a separate change in this PR. No default-option change or full E2E rerun is part of this follow-up.