From 06e1f19f42d7b7ce5e231db8817d4e6f631411bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Thu, 15 Dec 2022 11:02:33 +0100 Subject: [PATCH] Remove the deprecated profiler imports (#16059) --- src/lightning_app/utilities/introspection.py | 14 +-- src/pytorch_lightning/CHANGELOG.md | 6 +- src/pytorch_lightning/_graveyard/profiler.py | 93 +++++++++++++++++-- src/pytorch_lightning/profiler/__init__.py | 70 ++++++++++++-- src/pytorch_lightning/profiler/advanced.py | 24 ----- src/pytorch_lightning/profiler/base.py | 25 ----- src/pytorch_lightning/profiler/profiler.py | 30 ------ src/pytorch_lightning/profiler/pytorch.py | 44 --------- src/pytorch_lightning/profiler/simple.py | 24 ----- src/pytorch_lightning/profiler/xla.py | 24 ----- .../core/scripts/lightning_overrides.py | 10 +- .../tests_app/utilities/test_introspection.py | 11 ++- .../deprecated_api/test_remove_1-10.py | 19 ++++ .../deprecated_api/test_remove_1-9.py | 41 -------- .../tests_pytorch/graveyard/test_profiler.py | 56 ++++++++++- 15 files changed, 246 insertions(+), 245 deletions(-) delete mode 100644 src/pytorch_lightning/profiler/advanced.py delete mode 100644 src/pytorch_lightning/profiler/base.py delete mode 100644 src/pytorch_lightning/profiler/profiler.py delete mode 100644 src/pytorch_lightning/profiler/pytorch.py delete mode 100644 src/pytorch_lightning/profiler/simple.py delete mode 100644 src/pytorch_lightning/profiler/xla.py diff --git a/src/lightning_app/utilities/introspection.py b/src/lightning_app/utilities/introspection.py index 856f6d6ea84a8..4f49f5617db09 100644 --- a/src/lightning_app/utilities/introspection.py +++ b/src/lightning_app/utilities/introspection.py @@ -149,7 +149,7 @@ class LightningLoggerVisitor(LightningVisitor): Names of methods that are part of the Logger API. """ - class_name = "LightningLoggerBase" + class_name = "Logger" methods: Set[str] = {"log_hyperparams", "log_metrics"} @@ -248,10 +248,6 @@ class LightningAcceleratorVisitor(LightningVisitor): class_name = "Accelerator" -class LightningLoggerBaseVisitor(LightningVisitor): - class_name = "LightningLoggerBase" - - class LightningLoopVisitor(LightningVisitor): class_name = "Loop" @@ -264,8 +260,8 @@ class LightningLiteVisitor(LightningVisitor): class_name = "LightningLite" -class LightningBaseProfilerVisitor(LightningVisitor): - class_name = "BaseProfiler" +class LightningProfilerVisitor(LightningVisitor): + class_name = "Profiler" class Scanner: @@ -295,11 +291,11 @@ class Scanner: LightningStrategyVisitor, LightningPrecisionPluginVisitor, LightningAcceleratorVisitor, - LightningLoggerBaseVisitor, + LightningLoggerVisitor, LightningLoopVisitor, TorchMetricVisitor, LightningLiteVisitor, - LightningBaseProfilerVisitor, + LightningProfilerVisitor, ] def __init__(self, path: str, glob_pattern: str = "**/*.py"): diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 09f0bf5442215..5f8289a76c35c 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -69,7 +69,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated `description`, `env_prefix` and `env_parse` parameters in `LightningCLI.__init__` in favour of giving them through `parser_kwargs` ([#15651](https://github.com/Lightning-AI/lightning/pull/15651)) -- +- Deprecated `pytorch_lightning.profiler` in favor of `pytorch_lightning.profilers` ([#16059](https://github.com/PyTorchLightning/pytorch-lightning/pull/16059)) ### Removed @@ -95,6 +95,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Removed the deprecated `pytorch_lightning.accelerators.GPUAccelerator` in favor of `pytorch_lightning.accelerators.CUDAAccelerator` ([#16050](https://github.com/Lightning-AI/lightning/pull/16050)) +- Removed the deprecated `pytorch_lightning.profiler.*` classes in favor of `pytorch_lightning.profilers` ([#16059](https://github.com/PyTorchLightning/pytorch-lightning/pull/16059)) + ### Fixed @@ -508,7 +510,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated `Trainer.reset_train_val_dataloaders()` in favor of `Trainer.reset_{train,val}_dataloader` ([#12184](https://github.com/Lightning-AI/lightning/pull/12184)) - Deprecated LightningCLI's registries in favor of importing the respective package ([#13221](https://github.com/Lightning-AI/lightning/pull/13221)) - Deprecated public utilities in `pytorch_lightning.utilities.cli.LightningCLI` in favor of equivalent copies in `pytorch_lightning.cli.LightningCLI` ([#13767](https://github.com/Lightning-AI/lightning/pull/13767)) -- Deprecated `pytorch_lightning.profiler` in favor of `pytorch_lightning.profilers` ([#12308](https://github.com/Lightning-AI/lightning/pull/12308)) +- Deprecated `pytorch_lightning.profiler.*` in favor of `pytorch_lightning.profilers` ([#12308](https://github.com/Lightning-AI/lightning/pull/12308)) ### Removed diff --git a/src/pytorch_lightning/_graveyard/profiler.py b/src/pytorch_lightning/_graveyard/profiler.py index 258a68443e605..6c53e4a7eb86b 100644 --- a/src/pytorch_lightning/_graveyard/profiler.py +++ b/src/pytorch_lightning/_graveyard/profiler.py @@ -11,12 +11,22 @@ # 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 sys from typing import Any -import pytorch_lightning.profiler.base as base + +def _patch_sys_modules() -> None: + # TODO: Remove in v2.0.0 + self = sys.modules[__name__] + sys.modules["pytorch_lightning.profiler.advanced"] = self + sys.modules["pytorch_lightning.profiler.base"] = self + sys.modules["pytorch_lightning.profiler.profiler"] = self + sys.modules["pytorch_lightning.profiler.pytorch"] = self + sys.modules["pytorch_lightning.profiler.simple"] = self + sys.modules["pytorch_lightning.profiler.xla"] = self -class _AbstractProfiler: +class AbstractProfiler: # TODO: Remove in v2.0.0 def __init__(self, *_: Any, **__: Any) -> None: raise NotImplementedError( @@ -25,14 +35,85 @@ def __init__(self, *_: Any, **__: Any) -> None: ) -class _BaseProfiler: +class BaseProfiler: # TODO: Remove in v2.0.0 def __init__(self, *_: Any, **__: Any) -> None: raise RuntimeError( - "`pytorch_lightning.profiler.base.AbstractProfiler` was deprecated in v1.6 and is no longer supported" + "`pytorch_lightning.profiler.base.BaseProfiler` was deprecated in v1.6 and is no longer supported" " as of v1.9. Use `pytorch_lightning.profilers.Profiler` instead." ) -base.AbstractProfiler = _AbstractProfiler -base.BaseProfiler = _BaseProfiler +class AdvancedProfiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.advanced.AdvancedProfiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.AdvancedProfiler` instead." + ) + + +class PassThroughProfiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.base.PassThroughProfiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.PassThroughProfiler` instead." + ) + + +class Profiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.profiler.Profiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.Profiler` instead." + ) + + +class PyTorchProfiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.pytorch.PyTorchProfiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.PyTorchProfiler` instead." + ) + + +class RegisterRecordFunction: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.pytorch.RegisterRecordFunction` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.pytorch.RegisterRecordFunction` instead." + ) + + +class ScheduleWrapper: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.pytorch.ScheduleWrapper` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.pytorch.ScheduleWrapper` instead." + ) + + +class SimpleProfiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.simple.SimpleProfiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.SimpleProfiler` instead." + ) + + +class XLAProfiler: + # TODO: Remove in v2.0.0 + def __init__(self, *_: Any, **__: Any) -> None: + raise RuntimeError( + "`pytorch_lightning.profiler.xla.XLAProfiler` was deprecated in v1.7.0 and is not longer" + " supported as of v1.9.0. Use `pytorch_lightning.profilers.XLAProfiler` instead." + ) + + +_patch_sys_modules() diff --git a/src/pytorch_lightning/profiler/__init__.py b/src/pytorch_lightning/profiler/__init__.py index 0e97d02feb202..376c221290175 100644 --- a/src/pytorch_lightning/profiler/__init__.py +++ b/src/pytorch_lightning/profiler/__init__.py @@ -11,12 +11,70 @@ # 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 pytorch_lightning.profilers.advanced import AdvancedProfiler -from pytorch_lightning.profilers.base import PassThroughProfiler -from pytorch_lightning.profilers.profiler import Profiler -from pytorch_lightning.profilers.pytorch import PyTorchProfiler -from pytorch_lightning.profilers.simple import SimpleProfiler -from pytorch_lightning.profilers.xla import XLAProfiler +from typing import Any + +from pytorch_lightning.profilers.advanced import AdvancedProfiler as NewAdvancedProfiler +from pytorch_lightning.profilers.base import PassThroughProfiler as NewPassThroughProfiler +from pytorch_lightning.profilers.profiler import Profiler as NewProfiler +from pytorch_lightning.profilers.pytorch import PyTorchProfiler as NewPyTorchProfiler +from pytorch_lightning.profilers.simple import SimpleProfiler as NewSimpleProfiler +from pytorch_lightning.profilers.xla import XLAProfiler as NewXLAProfiler +from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation + + +class AdvancedProfiler(NewAdvancedProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.AdvancedProfiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.AdvancedProfiler` class instead." + ) + super().__init__(*args, **kwargs) + + +class PassThroughProfiler(NewPassThroughProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.PassThroughProfiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.PassThroughProfiler` class instead." + ) + super().__init__(*args, **kwargs) + + +class Profiler(NewProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.Profiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.Profiler` class instead." + ) + super().__init__(*args, **kwargs) + + +class PyTorchProfiler(NewPyTorchProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.PyTorchProfiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.PyTorchProfiler` class instead." + ) + super().__init__(*args, **kwargs) + + +class SimpleProfiler(NewSimpleProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.SimpleProfiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.SimpleProfiler` class instead." + ) + super().__init__(*args, **kwargs) + + +class XLAProfiler(NewXLAProfiler): + def __init__(self, *args: Any, **kwargs: Any) -> None: + rank_zero_deprecation( + "`pytorch_lightning.profiler.XLAProfiler` is deprecated in v1.9.0 and will be removed in v1.10.0." + " Use the equivalent `pytorch_lightning.profilers.XLAProfiler` class instead." + ) + super().__init__(*args, **kwargs) + __all__ = [ "Profiler", diff --git a/src/pytorch_lightning/profiler/advanced.py b/src/pytorch_lightning/profiler/advanced.py deleted file mode 100644 index d0456f7afa303..0000000000000 --- a/src/pytorch_lightning/profiler/advanced.py +++ /dev/null @@ -1,24 +0,0 @@ -# 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 pytorch_lightning.profilers.advanced import AdvancedProfiler as NewAdvancedProfiler -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class AdvancedProfiler(NewAdvancedProfiler): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.AdvancedProfiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.AdvancedProfiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/src/pytorch_lightning/profiler/base.py b/src/pytorch_lightning/profiler/base.py deleted file mode 100644 index 72eeccf38070b..0000000000000 --- a/src/pytorch_lightning/profiler/base.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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. -"""Profiler to check if there are any bottlenecks in your code.""" -from pytorch_lightning.profilers.base import PassThroughProfiler as NewPassThroughProfiler -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class PassThroughProfiler(NewPassThroughProfiler): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.PassThroughProfiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.PassThroughProfiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/src/pytorch_lightning/profiler/profiler.py b/src/pytorch_lightning/profiler/profiler.py deleted file mode 100644 index 544a0a83f6054..0000000000000 --- a/src/pytorch_lightning/profiler/profiler.py +++ /dev/null @@ -1,30 +0,0 @@ -# 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 pytorch_lightning.profilers.profiler import Profiler as NewProfiler -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class Profiler(NewProfiler): - """ - .. deprecated:: v1.7 - `pytorch_lightning.profiler.Profiler` is deprecated in v1.7 and will be removed in v1.9. - Use the equivalent `pytorch_lightning.profilers.Profiler` class instead. - """ - - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.Profiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.Profiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/src/pytorch_lightning/profiler/pytorch.py b/src/pytorch_lightning/profiler/pytorch.py deleted file mode 100644 index 488ce3b654673..0000000000000 --- a/src/pytorch_lightning/profiler/pytorch.py +++ /dev/null @@ -1,44 +0,0 @@ -# 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 pytorch_lightning.profilers.pytorch import PyTorchProfiler as NewPyTorchProfiler -from pytorch_lightning.profilers.pytorch import RegisterRecordFunction as NewRegisterRecordFuncion -from pytorch_lightning.profilers.pytorch import ScheduleWrapper as NewScheduleWrapper -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class RegisterRecordFunction(NewRegisterRecordFuncion): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.pytorch.RegisterRecordFunction` is deprecated in v1.7 and will be removed in" - " in v1.9. Use the equivalent `pytorch_lightning.profilers.pytorch.RegisterRecordFunction` class instead." - ) - super().__init__(*args, **kwargs) - - -class ScheduleWrapper(NewScheduleWrapper): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.pytorch.ScheduleWrapper` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.pytorch.ScheduleWrapper` class instead." - ) - super().__init__(*args, **kwargs) - - -class PyTorchProfiler(NewPyTorchProfiler): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.PyTorchProfiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.PyTorchProfiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/src/pytorch_lightning/profiler/simple.py b/src/pytorch_lightning/profiler/simple.py deleted file mode 100644 index 9438f516b2c93..0000000000000 --- a/src/pytorch_lightning/profiler/simple.py +++ /dev/null @@ -1,24 +0,0 @@ -# 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 pytorch_lightning.profilers.simple import SimpleProfiler as NewSimpleProfiler -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class SimpleProfiler(NewSimpleProfiler): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.SimpleProfiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.SimpleProfiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/src/pytorch_lightning/profiler/xla.py b/src/pytorch_lightning/profiler/xla.py deleted file mode 100644 index 0cdc0196001ff..0000000000000 --- a/src/pytorch_lightning/profiler/xla.py +++ /dev/null @@ -1,24 +0,0 @@ -# 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 pytorch_lightning.profilers.xla import XLAProfiler as NewXLAProfiler -from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation - - -class XLAProfiler(NewXLAProfiler): - def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] - rank_zero_deprecation( - "`pytorch_lightning.profiler.XLAProfiler` is deprecated in v1.7 and will be removed in v1.9." - " Use the equivalent `pytorch_lightning.profilers.XLAProfiler` class instead." - ) - super().__init__(*args, **kwargs) diff --git a/tests/tests_app/core/scripts/lightning_overrides.py b/tests/tests_app/core/scripts/lightning_overrides.py index 6139d970289d0..4271a3384c1b3 100644 --- a/tests/tests_app/core/scripts/lightning_overrides.py +++ b/tests/tests_app/core/scripts/lightning_overrides.py @@ -10,10 +10,10 @@ from pytorch_lightning.accelerators.accelerator import Accelerator from pytorch_lightning.callbacks import Callback from pytorch_lightning.lite import LightningLite - from pytorch_lightning.loggers import LightningLoggerBase - from pytorch_lightning.loops.base import Loop + from pytorch_lightning.loggers import Logger + from pytorch_lightning.loops import Loop from pytorch_lightning.plugins import PrecisionPlugin - from pytorch_lightning.profiler.base import BaseProfiler + from pytorch_lightning.profilers import Profiler if __name__ == "__main__": @@ -39,7 +39,7 @@ class BoringAccelerator(Accelerator): class BoringCallback(Callback): pass - class BoringLightningLoggerBase(LightningLoggerBase): + class BoringLogger(Logger): pass class BoringLoop(Loop): @@ -51,5 +51,5 @@ class BoringMetric(Metric): class BoringLightningLite(LightningLite): pass - class BoringBaseProfiler(BaseProfiler): + class BoringProfiler(Profiler): pass diff --git a/tests/tests_app/utilities/test_introspection.py b/tests/tests_app/utilities/test_introspection.py index 1f8be2eafe04d..142beb0e40a1c 100644 --- a/tests/tests_app/utilities/test_introspection.py +++ b/tests/tests_app/utilities/test_introspection.py @@ -42,18 +42,21 @@ def test_introspection_lightning_overrides(): """This test validates the scanner can find all the subclasses from primitives classes from PyTorch Lightning in the provided files.""" scanner = Scanner(str(os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/lightning_cli.py"))) + scan = scanner.scan() + assert set(scan) == {"LightningDataModule", "LightningModule"} + scanner = Scanner(str(os.path.join(_PROJECT_ROOT, "tests/tests_app/core/scripts/lightning_overrides.py"))) scan = scanner.scan() - assert sorted(scan.keys()) == [ + assert set(scan) == { "Accelerator", - "BaseProfiler", + "Profiler", "Callback", "LightningDataModule", "LightningLite", - "LightningLoggerBase", + "Logger", "LightningModule", "Loop", "Metric", "PrecisionPlugin", "Trainer", - ] + } diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-10.py b/tests/tests_pytorch/deprecated_api/test_remove_1-10.py index 6b37a03aecfe0..72a03957f3a28 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-10.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-10.py @@ -21,6 +21,7 @@ from lightning_utilities.test.warning import no_warning_call from torch.utils.data import DataLoader +import pytorch_lightning.profiler as profiler from lightning_lite.accelerators import CUDAAccelerator as LiteCUDAAccelerator from lightning_lite.accelerators import TPUAccelerator as LiteTPUAccelerator from pytorch_lightning import Trainer @@ -337,3 +338,21 @@ def test_v1_8_1_deprecated_rank_zero_only(): with pytest.deprecated_call(match="rank_zero_only` has been deprecated in v1.8.1"): rank_zero_only(lambda: None) + + +@pytest.mark.parametrize( + "cls", + [ + profiler.AdvancedProfiler, + profiler.PassThroughProfiler, + profiler.PyTorchProfiler, + profiler.SimpleProfiler, + pytest.param(profiler.XLAProfiler, marks=RunIf(tpu=True)), + ], +) +def test_profiler_classes_deprecated_warning(cls): + with pytest.deprecated_call( + match=f"profiler.{cls.__name__}` is deprecated in v1.9.0 and will be removed in v1.10.0." + f" Use .*profilers.{cls.__name__}` class instead." + ): + cls() diff --git a/tests/tests_pytorch/deprecated_api/test_remove_1-9.py b/tests/tests_pytorch/deprecated_api/test_remove_1-9.py index 90dd4372bf89e..7f07baf315f33 100644 --- a/tests/tests_pytorch/deprecated_api/test_remove_1-9.py +++ b/tests/tests_pytorch/deprecated_api/test_remove_1-9.py @@ -23,15 +23,7 @@ from pytorch_lightning.cli import LightningCLI, SaveConfigCallback from pytorch_lightning.core.module import LightningModule from pytorch_lightning.demos.boring_classes import BoringModel -from pytorch_lightning.profiler.advanced import AdvancedProfiler -from pytorch_lightning.profiler.base import PassThroughProfiler -from pytorch_lightning.profiler.profiler import Profiler -from pytorch_lightning.profiler.pytorch import PyTorchProfiler, RegisterRecordFunction, ScheduleWrapper -from pytorch_lightning.profiler.simple import SimpleProfiler -from pytorch_lightning.profiler.xla import XLAProfiler -from pytorch_lightning.utilities.imports import _KINETO_AVAILABLE from pytorch_lightning.utilities.rank_zero import rank_zero_only -from tests_pytorch.helpers.runif import RunIf def test_lightning_logger_base_deprecation_warning(): @@ -173,36 +165,3 @@ def test_lightningCLI_old_module_deprecation(): with pytest.deprecated_call(match=r"instantiate_class.*deprecated in v1.7.*Use the equivalent function"): assert isinstance(old_cli.instantiate_class(tuple(), {"class_path": "pytorch_lightning.Trainer"}), Trainer) - - -def test_profiler_deprecation_warning(): - assert "Profiler` is deprecated in v1.7" in Profiler.__doc__ - - -@pytest.mark.parametrize( - "cls", - [ - AdvancedProfiler, - PassThroughProfiler, - PyTorchProfiler, - SimpleProfiler, - pytest.param(XLAProfiler, marks=RunIf(tpu=True)), - ], -) -def test_profiler_classes_deprecated_warning(cls): - with pytest.deprecated_call( - match=f"profiler.{cls.__name__}` is deprecated in v1.7 and will be removed in v1.9." - f" Use .*profilers.{cls.__name__}` class instead." - ): - cls() - - -@pytest.mark.skipif(not _KINETO_AVAILABLE, reason="Requires PyTorch Profiler Kineto") -def test_pytorch_profiler_schedule_wrapper_deprecation_warning(): - with pytest.deprecated_call(match="ScheduleWrapper` is deprecated in v1.7 and will be removed in v1.9."): - _ = ScheduleWrapper(None) - - -def test_pytorch_profiler_register_record_function_deprecation_warning(): - with pytest.deprecated_call(match="RegisterRecordFunction` is deprecated in v1.7 and will be removed in in v1.9."): - _ = RegisterRecordFunction(None) diff --git a/tests/tests_pytorch/graveyard/test_profiler.py b/tests/tests_pytorch/graveyard/test_profiler.py index 8341ef4aeb76f..9d192b3eee8d1 100644 --- a/tests/tests_pytorch/graveyard/test_profiler.py +++ b/tests/tests_pytorch/graveyard/test_profiler.py @@ -23,6 +23,60 @@ def test_v2_0_0_base_profilers(): AbstractProfiler() with pytest.raises( - RuntimeError, match="AbstractProfiler` was deprecated in v1.6 and is no longer supported as of v1.9." + RuntimeError, match="BaseProfiler` was deprecated in v1.6 and is no longer supported as of v1.9." ): BaseProfiler() + + from pytorch_lightning.profiler.advanced import AdvancedProfiler + + with pytest.raises( + RuntimeError, match="AdvancedProfiler` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + AdvancedProfiler() + + from pytorch_lightning.profiler.base import PassThroughProfiler + + with pytest.raises( + RuntimeError, match="PassThroughProfiler` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + PassThroughProfiler() + + from pytorch_lightning.profiler.profiler import Profiler + + with pytest.raises(RuntimeError, match="Profiler` was deprecated in v1.7.0 and is not longer supported as of v1.9"): + Profiler() + + from pytorch_lightning.profiler.pytorch import PyTorchProfiler + + with pytest.raises( + RuntimeError, match="PyTorchProfiler` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + PyTorchProfiler() + + from pytorch_lightning.profiler.pytorch import RegisterRecordFunction + + with pytest.raises( + RuntimeError, match="RegisterRecordFunction` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + RegisterRecordFunction() + + from pytorch_lightning.profiler.pytorch import ScheduleWrapper + + with pytest.raises( + RuntimeError, match="ScheduleWrapper` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + ScheduleWrapper() + + from pytorch_lightning.profiler.simple import SimpleProfiler + + with pytest.raises( + RuntimeError, match="SimpleProfiler` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + SimpleProfiler() + + from pytorch_lightning.profiler.xla import XLAProfiler + + with pytest.raises( + RuntimeError, match="XLAProfiler` was deprecated in v1.7.0 and is not longer supported as of v1.9" + ): + XLAProfiler()