mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
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:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user