Why do we have the on_{validation/test/predict}_model_{train/eval} hooks? #8760
Unanswered
ananthsub
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 1 comment 5 replies
-
As a note, some people override them to avoid changing the model state. One example: |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Why do we have the
on_{validation/test/predict}_model_{train/eval}
hooks?https://github.com/PyTorchLightning/pytorch-lightning/blob/8473cf44ec0177ace2b17cf304a960e71b4d5fa6/pytorch_lightning/core/hooks.py#L192-L220
These were added back in #3858
#2551 (comment) contains the original design idea.
However, since the initial PR, these now have a default implementation on them to handle the wrapped model provided by the training type plugin. This implementation references the
self.trainer.model
. This now leaks abstractions for a number of reasons:self.trainer
doesn't exist on ModelHooks. This is set in the LightningModule, which subclasses ModelHooks. This means the ModelHooks is not self-contained.self.eval()
- they will run into bugs. Users are in essence forced to callsuper().
to stay correct. This is very fragile and hard to enforce.Given the complexity that's grown in the Trainer, I think it'd be desirable to deprecate these hooks, and ask users to check the train/eval status of layers during the epoch start or end hooks.
@PyTorchLightning/core-contributors
Beta Was this translation helpful? Give feedback.
All reactions