Callbacks
best_model_callback
Callback for saving and loading best model
- class mindnlp.engine.callbacks.best_model_callback.BestModelCallback(save_path, ckpt_name=None, larger_better=True, auto_load=False, save_on_exception=False)[source]
Bases:
CallbackSave the model with the best metrics value and reload the model at the end of the training. The best model can only be loaded at the end of the training.
- Parameters:
save_path (str) – Folder for saving.
ckpt_name (str) – Checkpoint name to store. It will set “best_so_far.ckpt” when not specified. Default: None.
larger_better (bool) – Whether the larger metrics, the better metrics. Default: True.
auto_load (bool) – Whether load the best model at the end of the training.
save_on_exception (bool) – Whether save the model on exception.
- evaluate_end(run_context)[source]
Called after evaluating.
- Parameters:
run_context (RunContext) – Information about the model.
- is_better_metric_value(metrics_values)[source]
Compare each metrics values with the best metrics values.
- Parameters:
metrics_values (float) – metrics values used to compared with the best metrics values so far.
- train_end(run_context)[source]
Called once after network training and load the best model params.
- Parameters:
run_context (RunContext) – Information about the model.
callback_manager
Callback Manager.
checkpoint_callback
Callback for saving checkpoint.
- class mindnlp.engine.callbacks.checkpoint_callback.CheckpointCallback(save_path, ckpt_name=None, epochs=None, keep_checkpoint_max=5)[source]
Bases:
CallbackSave checkpoint of the model. save the current Trainer state at the end of each epoch, which can be used to resume previous operations. Continue training a sample code using the most recent epoch
- Parameters:
save_path (str, Path) – The path to save the state. A specific path needs to be specified, such as ‘checkpoints/’.
ckpt_name (str) – Checkpoint name to store. It will set model class name when not specified. Default: None.
epochs (int) – Save a checkpoint file every n epochs.
keep_checkpoint_max (int) – Save checkpoint files at most. Default:5.
- train_begin(run_context)[source]
Notice the file saved path of checkpoints at the beginning of training.
- Parameters:
run_context (RunContext) – Information about the model.
- train_epoch_end(run_context)[source]
Save checkpoint every n epochs at the end of the epoch.
- Parameters:
run_context (RunContext) – Information about the model.
earlystop_callback
Callback for Early Stop.
- class mindnlp.engine.callbacks.earlystop_callback.EarlyStopCallback(patience=10, larger_better=True)[source]
Bases:
CallbackStop training without getting better after n epochs.
- Parameters:
patience (int) – Numbers of epochs evaluations without raising. Default:10.
larger_better (bool) – Whether the larger value of the metric is better. Default:True.
- evaluate_end(run_context)[source]
Called after evaluating.
- Parameters:
run_context (RunContext) – Information about the model.
timer_callback
Callback for timing.
- class mindnlp.engine.callbacks.timer_callback.TimerCallback(print_steps=0, time_ndigit=3)[source]
Bases:
CallbackPrint relevant event information during the training process, such as training duration, evaluation duration, total duration.
- Parameters:
print_steps (int) –
When to print time information.Default:-1.
-1: print once at the end of each epoch.
positive number n: print once n steps.
time_ndigit (int) – Number of decimal places to keep. Default:3
- evaluate_begin(run_context)[source]
Called once before the network evaluating.
- Parameters:
run_context (RunContext) – Information about the model.
- evaluate_end(run_context)[source]
Called once after the network evaluating.
- Parameters:
run_context (RunContext) – Information about the model.
- format_timer(reset=True, train_end=False)[source]
Format the output.
- Parameters:
run_context (RunContext) – Information about the model.
- train_begin(run_context)[source]
Called once before the network training.
- Parameters:
run_context (RunContext) – Information about the model.
- train_end(run_context)[source]
Called once after network training.
- Parameters:
run_context (RunContext) – Information about the model.
- train_epoch_begin(run_context)[source]
Called before each train epoch beginning.
- Parameters:
run_context (RunContext) – Information about the model.
- train_epoch_end(run_context)[source]
Called after each train epoch finished.
- Parameters:
run_context (RunContext) – Information about the model.
- train_step_begin(run_context)[source]
Called before each train step beginning.
- Parameters:
run_context (RunContext) – Information about the model.
- train_step_end(run_context)[source]
Called after each train step finished.
- Parameters:
run_context (RunContext) – Information about the model.