add smart gradient accumulation
parent
e34d4e9371
commit
54ac9e4462
|
|
@ -53,6 +53,10 @@ def train_epoch(epoch, wandb):
|
||||||
loss += res.aux_loss
|
loss += res.aux_loss
|
||||||
loss = loss / args.accumulation_steps
|
loss = loss / args.accumulation_steps
|
||||||
|
|
||||||
|
if (step + 1) % args.accumulation_steps != 0:
|
||||||
|
with model.no_sync(): # Disable DDP gradient synchronization
|
||||||
|
scaler.scale(loss).backward()
|
||||||
|
else:
|
||||||
scaler.scale(loss).backward()
|
scaler.scale(loss).backward()
|
||||||
|
|
||||||
if (step + 1) % args.accumulation_steps == 0:
|
if (step + 1) % args.accumulation_steps == 0:
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,10 @@ def train_epoch(epoch, wandb):
|
||||||
loss += res.aux_loss
|
loss += res.aux_loss
|
||||||
loss = loss / args.accumulation_steps
|
loss = loss / args.accumulation_steps
|
||||||
|
|
||||||
|
if (step + 1) % args.accumulation_steps != 0:
|
||||||
|
with model.no_sync(): # Disable DDP gradient synchronization
|
||||||
|
scaler.scale(loss).backward()
|
||||||
|
else:
|
||||||
scaler.scale(loss).backward()
|
scaler.scale(loss).backward()
|
||||||
|
|
||||||
if (step + 1) % args.accumulation_steps == 0:
|
if (step + 1) % args.accumulation_steps == 0:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue