Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activation config for callbacks #20494

Open
JohnHerry opened this issue Dec 13, 2024 · 1 comment
Open

Activation config for callbacks #20494

JohnHerry opened this issue Dec 13, 2024 · 1 comment
Labels
feature Is an improvement or enhancement

Comments

@JohnHerry
Copy link

JohnHerry commented Dec 13, 2024

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

@JohnHerry JohnHerry added feature Is an improvement or enhancement needs triage Waiting to be triaged by maintainers labels Dec 13, 2024
@lantiga
Copy link
Collaborator

lantiga commented Dec 16, 2024

Hey @JohnHerry why is this not a good design? You extended the ModelCheckpoint class correctly, subclassing existing callbacks is definitely encouraged.

We can consider adding this feature in the ModelCheckpoint callback itself, it would be nice if people could +1 this issue to probe interest.

@lantiga lantiga removed the needs triage Waiting to be triaged by maintainers label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants