[BUG] ZeRO-1 with fp32 grad accumulation rounds the window sum to the communication dtype

Aperta
#9,047 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@kritikagarg ci sta già lavorando.

Dal 22/11/2026.

  • #2 di @kritikagarg — aperta
  • #9172 di @YidaWeng — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with DeepSpeedZeroOptimizer.allreduce_bucket and gradient_reduction_w_predivide, then trace how communication_data_type is selected for ZeRO-1 when grad_accum_dtype is fp32. Run tests/unit/v1/zero/test_zero_offload_accum_precision.py and compare the stage 1 and stage 2 window sums. Done means the sums match exactly while explicit communication dtype settings and the autocast and MoE paths retain their stated behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

With ZeRO-1, a 16-bit model, and grad_accum_dtype: fp32, the gradient window is summed in fp32 on each rank but then reduced in the communication dtype (bf16 by default for a bf16 model). The fp32 window sum is rounded once to bf16 before the all-reduce, so the extra accumulation precision is discarded at reduction.

ZeRO-2 with the same config reduces each micro-step and adds the result to an fp32 partition. For inputs that are exact in bf16, the window sum is then exact. ZeRO-1 is not.

Found while reviewing #9044 (the table row for stage 1, fp32 masters, fp32 accumulation).

Where it happens

  • ZeRO-1 keeps the accumulated gradient in param.grad_accum (fp32) via use_grad_accum_attribute.
  • setup_buckets and _gradient_reduction_buffer_dtype allocate the IPG bucket in fp32, so the copy is exact.
  • At the boundary, average_tensor / allreduce_bucket cast to communication_data_type (bf16 for a bf16 model) before all_reduce, so the sum is rounded there.

The cast is in DeepSpeedZeroOptimizer.allreduce_bucket and gradient_reduction_w_predivide. Our reading is that communication_data_type is not the same thing as the gradient accumulation dtype on this path.

Reproduction

tests/unit/v1/zero/test_zero_offload_accum_precision.py, 16 micro-steps with gradients exact in bf16, relative max error of the window sum read before step():

stage masters accumulation error
2 fp32 fp32 0
1 fp32 fp32 2.4e-3

The same stage 1 value appears on a4c989b7, so this is pre-existing and not a regression from #9044.

Proposed change

When communication_data_type is not set explicitly, ZeRO-1 with fp32 accumulation on a 16-bit model reduces in gradient_accumulation_dtype (fp32). An explicit communication_data_type keeps its current meaning.

Costs and risks:

  • All-reduce bytes double for these configs. The reduction runs once per window on ZeRO-1, so the cost is small next to ZeRO-2's per-micro-step reduce-scatter, but it is a visible change.
  • Users can restore the old behavior with communication_data_type: bf16.
  • Not checked yet: the autocast per-parameter comm dtype path and MoE expert groups. These should stay unchanged.

Acceptance

  • Stage 1 and stage 2 window sums match exactly in the precision test for fp32 masters with fp32 accumulation.
  • Existing ZeRO-1 offload, coalesced reduction, and gradient-safety suites still pass.
  • B200 check of all-reduce time and step time, stage 1, one and two GPUs.

Open questions

  • Default on, or opt-in?
  • Should the explicit communication_data_type setting also be documented as the way to get the old rounding?
Lingua principale
Python
Stelle
43.3k
Fork
5.1k
Merge medio
5g 10h
PR unite (30g)
85

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di deepspeedai/DeepSpeed

Tutte le issue di deepspeedai/DeepSpeed

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.