Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 1 addition & 6 deletions docs/source-pytorch/extensions/loops.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ Here is a simple example how to add a new hook:

class CustomFitLoop(FitLoop):
def advance(self):
# ... whatever code before

# pass anything you want to the hook
self.trainer.call_hook("my_new_hook", *args, **kwargs)

# ... whatever code after
"""Put your custom logic here."""

Now simply attach the correct loop in the trainer directly:

Expand Down
5 changes: 5 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Removed the deprecated `Trainer.use_amp` and `LightningModule.use_amp` attributes ([#14832](https://github.com/Lightning-AI/lightning/pull/14832))


- Removed the deprecated `Trainer.run_stage` in favor of `Trainer.{fit,validate,test,predict}`


Expand All @@ -232,9 +233,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Remove the deprecated `Trainer.should_rank_save_checkpoint` ([#14885](https://github.com/Lightning-AI/lightning/pull/14885))


- Removed the deprecated `TrainerDataLoadingMixin` ([#14888](https://github.com/Lightning-AI/lightning/pull/14888))


- Removed the deprecated `Trainer.call_hook` in favor of `Trainer._call_callback_hooks`, `Trainer._call_lightning_module_hook`, `Trainer._call_ttp_hook`, and `Trainer._call_accelerator_hook` ([#14869](https://github.com/Lightning-AI/lightning/pull/14869))


### Fixed

- Fixed an issue with `LightningLite.setup()` not setting the `.device` attribute correctly on the returned wrapper ([#14822](https://github.com/Lightning-AI/lightning/pull/14822))
Expand Down
39 changes: 0 additions & 39 deletions src/pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1289,45 +1289,6 @@ def _call_teardown_hook(self) -> None:
# summarize profile results
self.profiler.describe()

def call_hook(
self, hook_name: str, *args: Any, pl_module: Optional["pl.LightningModule"] = None, **kwargs: Any
) -> Any:
r"""
.. deprecated:: v1.6
The Trainer's `call_hook` method was deprecated in v1.6 and will be removed in v1.8.
"""
rank_zero_deprecation("The Trainer's `call_hook` method was deprecated in v1.6 and will be removed in v1.8.")
pl_module = self.lightning_module or pl_module
if pl_module:
prev_fx_name = pl_module._current_fx_name
pl_module._current_fx_name = hook_name

# always profile hooks
with self.profiler.profile(hook_name):

# first call trainer hook
callback_fx = getattr(self, hook_name, None)
if callable(callback_fx):
callback_fx(*args, **kwargs)

# next call hook in lightningModule
output = None
model_fx = getattr(pl_module, hook_name, None)
if callable(model_fx):
output = model_fx(*args, **kwargs)

# call the strategy hook
if hook_name not in ("setup", "teardown", "on_train_start") and hasattr(self.strategy, hook_name):
strategy_hook = getattr(self.strategy, hook_name)
strategy_output = strategy_hook(*args, **kwargs)
output = strategy_output if output is None else output

if pl_module:
# restore current_fx when nested context
pl_module._current_fx_name = prev_fx_name

return output

def _call_lightning_module_hook(
self,
hook_name: str,
Expand Down
12 changes: 0 additions & 12 deletions tests/tests_pytorch/deprecated_api/test_remove_1-8.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ def on_init_end(self, trainer):
trainer.validate(model)


def test_v1_8_0_deprecated_call_hook():
trainer = Trainer(
max_epochs=1,
limit_val_batches=0.1,
limit_train_batches=0.2,
enable_progress_bar=False,
logger=False,
)
with pytest.deprecated_call(match="was deprecated in v1.6 and will be removed in v1.8."):
trainer.call_hook("test_hook")


@pytest.mark.parametrize("fn_prefix", ["validated", "tested", "predicted"])
def test_v1_8_0_trainer_ckpt_path_attributes(fn_prefix: str):
test_attr = f"{fn_prefix}_ckpt_path"
Expand Down