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

Fix setup callback hook to pass LightningModule through #4608

Merged
merged 7 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Fixed logged keys in mlflow logger ([#4412](https://github.com/PyTorchLightning/pytorch-lightning/pull/4412))
- Fixed `is_picklable` by catching `AttributeError` ([#4508](https://github.com/PyTorchLightning/pytorch-lightning/pull/4508))

- Fixed `setup` callback hook to correctly pass the LightningModule through ([#4608](https://github.com/PyTorchLightning/pytorch-lightning/pull/4608))


## [1.0.5] - 2020-11-03

Expand Down
4 changes: 2 additions & 2 deletions pytorch_lightning/trainer/callback_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class TrainerCallbackHookMixin(ABC):
callbacks: List[Callback] = []
get_model: Callable

def setup(self, stage: str):
def setup(self, model, stage: str):
"""Called in the beginning of fit and test"""
for callback in self.callbacks:
callback.setup(self, self.get_model(), stage)
callback.setup(self, model, stage)

def teardown(self, stage: str):
"""Called at the end of fit and test"""
Expand Down
2 changes: 1 addition & 1 deletion pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ def call_setup_hook(self, model):
called = self.datamodule.has_setup_test if self.testing else self.datamodule.has_setup_fit
if not called:
self.datamodule.setup(stage_name)
self.setup(stage_name)
self.setup(model, stage_name)
ananthsub marked this conversation as resolved.
Show resolved Hide resolved
model.setup(stage_name)

def _reset_result_and_set_hook_fx_name(self, hook_name):
Expand Down
3 changes: 2 additions & 1 deletion tests/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,8 @@ def setup(self, stage):
self.stage = stage

class TrainerSubclass(Trainer):
def setup(self, stage):
def setup(self, model, stage):
assert model is not None
self.stage = stage

model = CurrentModel()
Expand Down