fix(train): align DDP no_sync with gradient accumulation (#3472)

Synchronize DDP/FSDP gradients on the final microbatch of each accumulation window.

Verified with a two-rank CPU/Gloo reproduction, py_compile, diff checks, and a clean synthetic merge against current main.
This commit is contained in:
May
2026-08-05 11:32:24 +08:00
committed by GitHub
parent 6829ba7845
commit d410a5652d
+3 -1
View File
@@ -648,7 +648,9 @@ class Trainer:
my_context = nullcontext
if self.use_ddp or self.use_fsdp:
my_context = model.no_sync if batch_idx % accum_grad != 0 else my_context
my_context = (
model.no_sync if (batch_idx + 1) % accum_grad != 0 else my_context
)
with my_context():
time2 = time.perf_counter()