Lightning-AI / Lightning-AI/pytorch-lightning

`top_k` parameter of `ModelCheckpoint` default value

Open
#20,539 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Description & Motivation

I believe that the `top_k` would highly benefit from the improvement in its default value. Currently, it defaults to `1`. However, sometimes, like for example when I am trying to save models every n train steps, it doesn't make sense to save the `top_k=1` model. I would presumably like to have it save all the models.

### Pitch

So, I would suggest that the default value should be `None`. In case where `every_n_train_steps` or `every_n_epochs` or `train_time_interval` has some value with `monitor=None` and the `top_k` value is not given, i.e., still bears `None` it should change to -1. However in cases where the `monitor` parameter is set the `top_k` value should be changed to 1, if not specified.

### Alternatives

_No response_

### Additional context

_No response_

cc @lantiga @borda

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the ModelCheckpoint entry point and trace how top_k interacts with monitor, every_n_train_steps, every_n_epochs, and train_time_interval. Clarify the default behavior for monitored versus unmonitored checkpoints, then verify that the resulting behavior matches the requested cases and does not regress existing checkpoint selection.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.