espnet3.components.callbacks.default_callbacks.BestCheckpointLink
espnet3.components.callbacks.default_callbacks.BestCheckpointLink
class espnet3.components.callbacks.default_callbacks.BestCheckpointLink(output_dir, best_ckpt_callbacks)
Bases: Callback
Link the best checkpoint of each monitor for inference.
For each given ModelCheckpoint, output_dir/{monitor_name}.best.pth is a relative symlink to its best_model_path, e.g. valid.acc.best.pth. The link is refreshed after every epoch’s validation checkpoints are saved and at training end, so it is usable even if training stops early. Checkpoint selection itself remains ModelCheckpoint’s responsibility.
- Parameters:
- output_dir (str or Path) – The directory where the links are created.
- best_ckpt_callbacks (List *[*ModelCheckpoint ]) – ModelCheckpoint callbacks whose best checkpoints are linked.
Notes
- This callback only runs on the global rank 0 process : (for distributed training).
Example
>>> link_cb = BestCheckpointLink(
... output_dir="checkpoints/", best_ckpt_callbacks=[acc_ckpt_cb]
... )
>>> trainer = Trainer(callbacks=[acc_ckpt_cb, link_cb])Initialize BestCheckpointLink object.
on_train_end(trainer, pl_module)
Refresh the links once training is over.
on_train_epoch_end(trainer, pl_module)
Link the best checkpoints after the epoch’s validation saved them.
on_validation_end would run before ModelCheckpoint, which Lightning moves to the end of the callback list (see AverageCheckpointsCallback).
