Skip to content

Commit

Permalink
Use self._trial to generate trial_name for Trainer. (huggingface#19874)
Browse files Browse the repository at this point in the history
* Do not generate trial_name when trail is None

* Use (trial or self._trial) to generate trial_name

* Follow comments
  • Loading branch information
reyoung authored Oct 28, 2022
1 parent 347ba38 commit 9b1dcba
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 @@ -1652,7 +1652,10 @@ def _inner_training_loop(
self.callback_handler.optimizer = self.optimizer
self.callback_handler.lr_scheduler = self.lr_scheduler
self.callback_handler.train_dataloader = train_dataloader
self.state.trial_name = self.hp_name(trial) if self.hp_name is not None else None
if self.hp_name is not None and self._trial is not None:
# use self._trial because the SigOpt/Optuna hpo only call `_hp_search_setup(trial)` instead of passing trial
# parameter to Train when using DDP.
self.state.trial_name = self.hp_name(self._trial)
if trial is not None:
assignments = trial.assignments if self.hp_search_backend == HPSearchBackend.SIGOPT else trial
self.state.trial_params = hp_params(assignments)
Expand Down

0 comments on commit 9b1dcba

Please sign in to comment.