Skip to content

Commit

Permalink
Fix lr scheduler when accumulating gradients
Browse files Browse the repository at this point in the history
  • Loading branch information
hmorimitsu committed Jun 12, 2024
1 parent d0291f4 commit 25295e8
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ptlflow/models/base_model/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,16 @@ def configure_optimizers(self) -> Dict[str, Any]:
optimizer = optim.AdamW(
self.parameters(), lr=self.args.lr, weight_decay=self.args.wdecay
)

accumulate_grad_batches = (
1
if self.args.accumulate_grad_batches is None
else self.args.accumulate_grad_batches
)
lr_scheduler = optim.lr_scheduler.OneCycleLR(
optimizer,
self.args.lr,
total_steps=self.args.max_steps,
total_steps=self.args.max_steps // accumulate_grad_batches,
pct_start=0.05,
cycle_momentum=False,
anneal_strategy="linear",
Expand Down

0 comments on commit 25295e8

Please sign in to comment.