-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Description
Discussed in #10677
Part of #7740
Originally posted by daniellepintz November 22, 2021
These hooks are called when trainer initialization begins and ends, before the model has been set, essentially allowing the user to modify the Trainer constructor. Should we be giving the user this much control over Trainer constructor? Are there scenarios where this is needed? Or can we deprecate these hooks?
@carmocca @tchaton @awaelchli do you know how these hooks are used? Have you seen any examples of these being used by the community? These hooks go way, way back, but I can't think of when they'd be needed given the user handles the Trainer initialization. It's also unclear when on_init_start actually happens: does that mean callbacks should be the first thing initialized?
We also have correctness issues for these hooks when callbacks are passed directly to the Trainer vs configured from the LightningModule: https://github.com/PyTorchLightning/pytorch-lightning/blob/f407a00cec59886cbaf8816630f6760e34926bd5/pytorch_lightning/core/lightning.py#L1140-L1142
Therefore, as a user, it seems more concise to write this:
trainer = Trainer(...)
run_all_my_fancy_logic_now(trainer)
# use the trainer herevs this:
class MyCallback(Callback):
def on_init_start(self, trainer) -> None:
...
def on_init_end(self, trainer) -> None:
...
cb = MyCallback()
trainer = Trainer(callbacks=[cb])cc @awaelchli @ananthsub @tchaton @carmocca @Borda @ninginthecloud