"src/sdk/pynni/git@developer.sourcefind.cn:OpenDAS/nni.git" did not exist on "1e511829e7dd66dd6850098f8d744fb07f2228a0"
Unverified Commit c44a17db authored by mataney's avatar mataney Committed by GitHub
Browse files

[FIX] not training when epoch is small (#3006)

* solving bug where for small epochs and large gradient_accumulation_steps we never train

* black formatting

* no need to change these files
parent ad7233fc
...@@ -233,7 +233,11 @@ def train(args, train_dataset, model, tokenizer): ...@@ -233,7 +233,11 @@ def train(args, train_dataset, model, tokenizer):
loss.backward() loss.backward()
tr_loss += loss.item() tr_loss += loss.item()
if (step + 1) % args.gradient_accumulation_steps == 0: if (step + 1) % args.gradient_accumulation_steps == 0 or (
# last step in epoch but step is always smaller than gradient_accumulation_steps
len(epoch_iterator) <= args.gradient_accumulation_steps
and (step + 1) == len(epoch_iterator)
):
if args.fp16: if args.fp16:
torch.nn.utils.clip_grad_norm_(amp.master_params(optimizer), args.max_grad_norm) torch.nn.utils.clip_grad_norm_(amp.master_params(optimizer), args.max_grad_norm)
else: else:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment