Gist on how to use Schedule-Free in Lightning #19759
Replies: 4 comments 6 replies
-
class MyNet(pl.LightningModule):
...
def train(self, mode: bool = True) -> None:
"""Set the model to training mode"""
self.model.train(mode)
self.optimizers().train()
def eval(self) -> None:
"""Set the model to evaluation mode"""
self.model.eval()
self.optimizers().eval() Seemingly the following doesn't cause issues, need to verify whether the results are good. This only would work if the module has a single optimizer |
Beta Was this translation helpful? Give feedback.
-
Using the on_fit_start and on_predict_start hooks seems to work for a single optimizer (or at least doesn't throw an error): class MyNet(pl.LightningModule):
...
def on_fit_start(self) -> None:
self.optimizers().train()
def on_predict_start(self) -> None:
self.optimizers().eval() Versions
UPDATE: Looking more at the Hooks pseudocode I believe you also want to set some others as well: def on_validation_model_eval(self) -> None:
self.model.eval()
self.optimizers().eval()
def on_validation_model_train(self) -> None:
self.model.train()
self.optimizers().train()
def on_test_model_eval(self) -> None:
self.model.eval()
self.optimizers().eval()
def on_test_model_train(self) -> None:
self.model.train()
self.optimizers().train()
def on_predict_model_eval(self) -> None: # redundant with on_predict_start()
self.model.eval()
self.optimizers().eval() |
Beta Was this translation helpful? Give feedback.
-
This is interesting! |
Beta Was this translation helpful? Give feedback.
-
The schedulerfree docs state that the scheduler should be put into eval mode when saving checkpoints. How is this best achieved? |
Beta Was this translation helpful? Give feedback.
-
Recent interest has emerged on twitter regarding https://github.com/facebookresearch/schedule_free given promising results without the need to configure a learning rate schedule.
However the optimizer requires
.eval()
and.train()
calls to ensure that the correct parameter buffer is used. Where is the right place to add these additional calls to the methods of a lightning module?Beta Was this translation helpful? Give feedback.
All reactions