Compare commits

...

6 Commits

Author SHA1 Message Date
0d0ddab0ed Add tests 2022-07-08 23:25:22 +03:00
feeadc3cef Merge branch 'huggingface:main' into patch-1 2022-07-08 22:54:55 +03:00
8b849dea00 Small and different fix 2022-07-08 22:10:07 +03:00
3cc4a5038b Small fix 2022-07-08 22:01:54 +03:00
479995c204 Add on_predict 2022-07-08 21:20:01 +03:00
f495db0510 Make Trainer.predict call on_evaluate (#17952) 2022-06-30 00:08:22 +03:00
4 changed files with 24 additions and 0 deletions

View File

@ -2713,6 +2713,7 @@ class Trainer:
)
)
self.control = self.callback_handler.on_predict(self.args, self.state, self.control, output.metrics)
self._memory_tracker.stop_and_update_metrics(output.metrics)
return PredictionOutput(predictions=output.predictions, label_ids=output.label_ids, metrics=output.metrics)

View File

@ -262,6 +262,12 @@ class TrainerCallback:
"""
pass
def on_predict(self, args: TrainingArguments, state: TrainerState, control: TrainerControl, metrics, **kwargs):
"""
Event called after a successful prediction.
"""
pass
def on_save(self, args: TrainingArguments, state: TrainerState, control: TrainerControl, **kwargs):
"""
Event called after a checkpoint save.
@ -372,6 +378,9 @@ class CallbackHandler(TrainerCallback):
control.should_evaluate = False
return self.call_event("on_evaluate", args, state, control, metrics=metrics)
def on_predict(self, args: TrainingArguments, state: TrainerState, control: TrainerControl, metrics):
return self.call_event("on_predict", args, state, control, metrics=metrics)
def on_save(self, args: TrainingArguments, state: TrainerState, control: TrainerControl):
control.should_save = False
return self.call_event("on_save", args, state, control)
@ -484,6 +493,12 @@ class ProgressCallback(TrainerCallback):
self.prediction_bar.close()
self.prediction_bar = None
def on_predict(self, args, state, control, **kwargs):
if state.is_local_process_zero:
if self.prediction_bar is not None:
self.prediction_bar.close()
self.prediction_bar = None
def on_log(self, args, state, control, logs=None, **kwargs):
if state.is_local_process_zero and self.training_bar is not None:
_ = logs.pop("total_flos", None)

View File

@ -307,6 +307,11 @@ class NotebookProgressCallback(TrainerCallback):
else:
self.prediction_bar.update(self.prediction_bar.value + 1)
def on_predict(self, args, state, control, **kwargs):
if self.prediction_bar is not None:
self.prediction_bar.close()
self.prediction_bar = None
def on_log(self, args, state, control, logs=None, **kwargs):
# Only for when there is no evaluation
if args.evaluation_strategy == IntervalStrategy.NO and "loss" in logs:

View File

@ -66,6 +66,9 @@ class MyTestTrainerCallback(TrainerCallback):
def on_evaluate(self, args, state, control, **kwargs):
self.events.append("on_evaluate")
def on_predict(self, args, state, control, **kwargs):
self.events.append("on_predict")
def on_save(self, args, state, control, **kwargs):
self.events.append("on_save")