Lightning-AI / Lightning-AI/pytorch-lightning

Activation config for callbacks

Open
#20,494 1 comment 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

My situation: I am using a ModelCheckpoint callback, My configuation is like follows:
```
callbacks:
- class_path: pytorch_lightning.callbacks.ModelCheckpoint
init_args:
monitor: val_loss
filename: "checkpoint_{epoch}_{step}_{vall_loss}.ckpt"
save_top_k: 55
every_n_train_steps: 1000
```
My traning have a warmup stage that is over 1000 steps, catastrophicly, the lowest monitor metric is just stand at the warmup stage. certainly this value appear there when the model is far from stable. So I want to config the ModelCheckpoint callback do activated after warmup stage, or it is activated when a certain of training steps passed. Here in the example, I can do as follows:
```
class MyModelCheckpoint(pytorch_lightning.callbacks.ModelCheckpoint):
def __init__(self, dirpath, filename, ...., active_after_step=20000):
super(MyModelCheckpoint, self).__init__(dirpath, filename, ...)
self.activte_after_step = active_after_step

def _should_skip_saving_checkpoint(self, trainer):
if trainer.global_steps < self.activate_after_step:
return True
return super(MyModelCheckpoint, self)._should_skip_saving_checkpoint(trainer)
```
but this is not a good desgin, and can not slove similar problems on other callbacks. So, Is there any root desigin to support activation condition conf on each callbacks?

If there has been and I did not noticed that, say sorry for my careless.

### Pitch

_No response_

### Alternatives

_No response_

### Additional context

_No response_

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 with the ModelCheckpoint callback and its _should_skip_saving_checkpoint method, then review how callbacks are configured through the callbacks section. The issue proposes a general activation condition based on training steps, but does not name implementation files or tests. Done would mean agreeing on and implementing a reusable activation configuration for callbacks, with coverage for the requested warmup behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.