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
1 change: 1 addition & 0 deletions src/pytorch_lightning/_graveyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pytorch_lightning._graveyard.callbacks
import pytorch_lightning._graveyard.trainer
import pytorch_lightning._graveyard.training_type # noqa: F401
30 changes: 30 additions & 0 deletions src/pytorch_lightning/_graveyard/callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any

from pytorch_lightning.callbacks import ModelCheckpoint


def _save_checkpoint(_: ModelCheckpoint, __: Any) -> None:
# Remove in v2.0.0
raise NotImplementedError(
f"`{ModelCheckpoint.__name__}.save_checkpoint()` was deprecated in v1.6 and is no longer supported"
f" as of 1.8. Please use `trainer.save_checkpoint()` to manually save a checkpoint. This method will be"
f" removed completely in v2.0."
)


# Methods
ModelCheckpoint.save_checkpoint = _save_checkpoint
7 changes: 0 additions & 7 deletions src/pytorch_lightning/callbacks/model_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,13 +351,6 @@ def load_state_dict(self, state_dict: Dict[str, Any]) -> None:

self.best_model_path = state_dict["best_model_path"]

def save_checkpoint(self, trainer: "pl.Trainer") -> None:
raise NotImplementedError(
f"`{self.__class__.__name__}.save_checkpoint()` was deprecated in v1.6 and is no longer supported"
f" as of 1.8. Please use `trainer.save_checkpoint()` to manually save a checkpoint. This method will be"
f" removed completely in v2.0."
)

def _save_topk_checkpoint(self, trainer: "pl.Trainer", monitor_candidates: Dict[str, Tensor]) -> None:
if self.save_top_k == 0:
return
Expand Down
8 changes: 8 additions & 0 deletions src/pytorch_lightning/trainer/configuration_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ def _check_on_pretrain_routine(model: "pl.LightningModule") -> None:

def _check_deprecated_callback_hooks(trainer: "pl.Trainer") -> None:
for callback in trainer.callbacks:
if callable(getattr(callback, "on_init_start", None)):
raise RuntimeError(
"The `on_init_start` callback hook was deprecated in v1.6 and is no longer supported as of v1.8."
)
if callable(getattr(callback, "on_init_end", None)):
raise RuntimeError(
"The `on_init_end` callback hook was deprecated in v1.6 and is no longer supported as of v1.8."
)
if callable(getattr(callback, "on_configure_sharded_model", None)):
raise RuntimeError(
"The `on_configure_sharded_model` callback hook was removed in v1.8. Use `setup()` instead."
Expand Down
36 changes: 28 additions & 8 deletions tests/tests_pytorch/deprecated_api/test_remove_2-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import pytorch_lightning
from pytorch_lightning import Callback, Trainer
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.demos.boring_classes import BoringModel
from tests_pytorch.callbacks.test_callbacks import OldStatefulCallback
from tests_pytorch.helpers.runif import RunIf
Expand Down Expand Up @@ -292,11 +291,32 @@ def on_pretrain_routine_end(self, trainer, pl_module):
trainer.fit(model)


def test_v2_0_0_deprecated_mc_save_checkpoint():
mc = ModelCheckpoint()
trainer = Trainer()
with mock.patch.object(trainer, "save_checkpoint"), pytest.raises(
NotImplementedError,
match=r"ModelCheckpoint.save_checkpoint\(\)` was deprecated in v1.6 and is no longer supported as of 1.8.",
class OnInitStartCallback(Callback):
def on_init_start(self, trainer):
print("Starting to init trainer!")


class OnInitEndCallback(Callback):
def on_init_end(self, trainer):
print("Trainer is init now")


@pytest.mark.parametrize("callback_class", [OnInitStartCallback, OnInitEndCallback])
def test_v2_0_0_unsupported_on_init_start_end(callback_class, tmpdir):
model = BoringModel()
trainer = Trainer(
callbacks=[callback_class()],
max_epochs=1,
fast_dev_run=True,
enable_progress_bar=False,
logger=False,
default_root_dir=tmpdir,
)
with pytest.raises(
RuntimeError, match="callback hook was deprecated in v1.6 and is no longer supported as of v1.8"
):
trainer.fit(model)
with pytest.raises(
RuntimeError, match="callback hook was deprecated in v1.6 and is no longer supported as of v1.8"
):
mc.save_checkpoint(trainer)
trainer.validate(model)
26 changes: 26 additions & 0 deletions tests/tests_pytorch/graveyard/test_callbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pytest

from pytorch_lightning.callbacks import ModelCheckpoint


def test_v2_0_0_deprecated_mc_save_checkpoint():
mc = ModelCheckpoint()
with pytest.raises(
NotImplementedError,
match=r"ModelCheckpoint.save_checkpoint\(\)` was deprecated in v1.6 and is no longer supported as of 1.8.",
):
mc.save_checkpoint(None)