Skip to content

Commit

Permalink
Trainer: fixed evaluate raising KeyError for ReduceLROnPlateau (#23952
Browse files Browse the repository at this point in the history
)

Trainer: fixed KeyError on evaluate for ReduceLROnPlateau

Co-authored-by: Claudius Kienle <[email protected]>
  • Loading branch information
claudius-kienle and Claudius Kienle authored Jun 2, 2023
1 parent 2fdba73 commit 8940d31
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,10 @@ def _maybe_log_save_evaluate(self, tr_loss, model, trial, epoch, ignore_keys_for

# Run delayed LR scheduler now that metrics are populated
if isinstance(self.lr_scheduler, torch.optim.lr_scheduler.ReduceLROnPlateau):
self.lr_scheduler.step(metrics[self.args.metric_for_best_model])
metric_to_check = self.args.metric_for_best_model
if not metric_to_check.startswith("eval_"):
metric_to_check = f"eval_{metric_to_check}"
self.lr_scheduler.step(metrics[metric_to_check])

if self.control.should_save:
self._save_checkpoint(model, trial, metrics=metrics)
Expand Down

0 comments on commit 8940d31

Please sign in to comment.