Lightning-AI / Lightning-AI/pytorch-lightning

put the monitor metric into default filename for ModelCheckpoint

Open
#20,397 2 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

Tiny annoyance, but wouldn't it make sense to put the monitor value in the default value of the filename so it's not just epoch-X-step-y by default?

Pitch

Couldn't something like this work here?

    def _format_checkpoint_name(
        self,
        filename: Optional[str],
        metrics: Dict[str, Tensor],
        prefix: str = "",
        auto_insert_metric_name: bool = True,
    ) -> str:
        if not filename:
            if self.monitor is not None and self.monitor in metrics:
                filename = "{epoch}" + self.CHECKPOINT_JOIN_CHAR + "{step}" + self.CHECKPOINT_JOIN_CHAR + f"{{{self.monitor}}}"
            # filename is not set, use default name
            else:
                filename = "{epoch}" + self.CHECKPOINT_JOIN_CHAR + "{step}"

Alternatives

No response

Additional context

Happy to put it in MR

cc @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 in src/lightning/pytorch/callbacks/model_checkpoint.py at the _format_checkpoint_name method and review the surrounding filename-generation logic. Confirm that default filenames include the monitored metric when one is configured and available, while retaining the existing epoch-step fallback when it is not.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
machine-learning
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.