Skip to content

Add best_model_metrics to ModelCheckpoint callback #19007

@libokj

Description

@libokj

Description & Motivation

There doesn't seem to be a straightforward way to get the training and validation metrics of the best model as monitored by ModelCheckpoint. Adding best_model_metrics attribute to ModelCheckpoint can be done easily in a way similar to how best_model_score works now.

Pitch

Accessing training and validation metrics of the best model checkpoint by accessing trainer.checkpoint_callback.best_model_metrics right after a trainer.fit call is useful for hyperparameter optimization if you want to optimize based on a validation metric or use other custom callbacks to summarize a batch experiment. I am willing to implement this feature.

Alternatives

  1. Running trainer.test on the training and validation dataset again after a trainer.fit call.
  2. Getting records saved by loggers by checking the epoch number in the filename of a checkpoint file.

These two options create unnecessary overheads for a simple feature like this.

Additional context

#18398

cc @lantiga @Borda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions