From ceac0bf99f094dcfc2ba83e837264e6f803081dd Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 13 Oct 2021 23:01:49 -0700 Subject: [PATCH 1/7] Deprecate GPUStatsMonitor and XLAStatsMonitor --- CHANGELOG.md | 2 ++ pytorch_lightning/callbacks/gpu_stats_monitor.py | 11 ++++++++++- pytorch_lightning/callbacks/xla_stats_monitor.py | 14 ++++++++++++-- tests/deprecated_api/test_remove_1-7.py | 13 +++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f12dda513629..175bba66c0a1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -356,6 +356,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated passing `weights_summary` to the `Trainer` constructor in favor of adding the `ModelSummary` callback with `max_depth` directly to the list of callbacks ([#9699](https://github.com/PyTorchLightning/pytorch-lightning/pull/9699)) +- Deprecated `GPUStatsMonitor` and `XLAStatsMonitor` in favor of `DeviceStatsMonitor` callback ([#9922](https://github.com/PyTorchLightning/pytorch-lightning/pull/9922)) + ### Removed - Removed deprecated `metrics` ([#8586](https://github.com/PyTorchLightning/pytorch-lightning/pull/8586/)) diff --git a/pytorch_lightning/callbacks/gpu_stats_monitor.py b/pytorch_lightning/callbacks/gpu_stats_monitor.py index 8e9e671949c88..8913c9625ec42 100644 --- a/pytorch_lightning/callbacks/gpu_stats_monitor.py +++ b/pytorch_lightning/callbacks/gpu_stats_monitor.py @@ -29,7 +29,7 @@ import pytorch_lightning as pl from pytorch_lightning.callbacks.base import Callback -from pytorch_lightning.utilities import DeviceType, rank_zero_only +from pytorch_lightning.utilities import DeviceType, rank_zero_only, rank_zero_deprecation from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.parsing import AttributeDict from pytorch_lightning.utilities.types import STEP_OUTPUT @@ -37,6 +37,10 @@ class GPUStatsMonitor(Callback): r""" + .. deprecated:: v1.5 + The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " + "Please use the `DeviceStatsMonitor` callback instead. + Automatically monitors and logs GPU stats during training stage. ``GPUStatsMonitor`` is a callback and in order to use it you need to assign a logger in the ``Trainer``. @@ -91,6 +95,11 @@ def __init__( ): super().__init__() + rank_zero_deprecation( + "The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " + "Please use the `DeviceStatsMonitor` callback instead." + ) + if shutil.which("nvidia-smi") is None: raise MisconfigurationException( "Cannot use GPUStatsMonitor callback because NVIDIA driver is not installed." diff --git a/pytorch_lightning/callbacks/xla_stats_monitor.py b/pytorch_lightning/callbacks/xla_stats_monitor.py index 07e3008aa6cd1..b32793d60d47f 100644 --- a/pytorch_lightning/callbacks/xla_stats_monitor.py +++ b/pytorch_lightning/callbacks/xla_stats_monitor.py @@ -21,7 +21,7 @@ import time from pytorch_lightning.callbacks.base import Callback -from pytorch_lightning.utilities import _TPU_AVAILABLE, DeviceType, rank_zero_info +from pytorch_lightning.utilities import _TPU_AVAILABLE, DeviceType, rank_zero_info, rank_zero_deprecation from pytorch_lightning.utilities.exceptions import MisconfigurationException if _TPU_AVAILABLE: @@ -29,7 +29,12 @@ class XLAStatsMonitor(Callback): - """Automatically monitors and logs XLA stats during training stage. ``XLAStatsMonitor`` is a callback and in + r""" + .. deprecated:: v1.5 + The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " + "Please use the `DeviceStatsMonitor` callback instead. + + Automatically monitors and logs XLA stats during training stage. ``XLAStatsMonitor`` is a callback and in order to use it you need to assign a logger in the ``Trainer``. Args: @@ -51,6 +56,11 @@ class XLAStatsMonitor(Callback): def __init__(self, verbose: bool = True) -> None: super().__init__() + rank_zero_deprecation( + "The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " + "Please use the `DeviceStatsMonitor` callback instead." + ) + if not _TPU_AVAILABLE: raise MisconfigurationException("Cannot use XLAStatsMonitor with TPUs are not available") diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 08449f6fbbcff..9ab0b06661aae 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -18,6 +18,8 @@ import torch from pytorch_lightning import Callback, LightningDataModule, Trainer +from pytorch_lightning.callbacks.xla_stats_monitor import GPUStatsMonitor +from pytorch_lightning.callbacks.xla_stats_monitor import XLAStatsMonitor from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger from tests.deprecated_api import _soft_unimport_module from tests.helpers import BoringModel @@ -366,3 +368,14 @@ def test_v1_7_0_weights_summary_trainer(tmpdir): with pytest.deprecated_call(match=r"Setting `Trainer.weights_summary` is deprecated in v1.5"): t.weights_summary = "blah" + + +def test_v1_7_0_deprecate_gpu_stats_monitor(tmpdir): + with pytest.deprecated_call(match="The `GPUStatsMonitor` callback was deprecated in v1.5"): + _ = GPUStatsMonitor() + + +@RunIf(tpu=True) +def test_v1_7_0_deprecate_tpu_stats_monitor(tmpdir): + with pytest.deprecated_call(match="The `XLAStatsMonitor` callback was deprecated in v1.5"): + _ = XLAStatsMonitor() From d07b9da05b8eb0be1675a0f684045919baa4e25f Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 13 Oct 2021 23:09:49 -0700 Subject: [PATCH 2/7] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 175bba66c0a1b..01f9e5d0509d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -356,7 +356,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Deprecated passing `weights_summary` to the `Trainer` constructor in favor of adding the `ModelSummary` callback with `max_depth` directly to the list of callbacks ([#9699](https://github.com/PyTorchLightning/pytorch-lightning/pull/9699)) -- Deprecated `GPUStatsMonitor` and `XLAStatsMonitor` in favor of `DeviceStatsMonitor` callback ([#9922](https://github.com/PyTorchLightning/pytorch-lightning/pull/9922)) +- Deprecated `GPUStatsMonitor` and `XLAStatsMonitor` in favor of `DeviceStatsMonitor` callback ([#9924](https://github.com/PyTorchLightning/pytorch-lightning/pull/9924)) ### Removed From d300849de46e5a3714dfeabab9fbc0355f8c76ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Oct 2021 06:10:10 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytorch_lightning/callbacks/gpu_stats_monitor.py | 2 +- pytorch_lightning/callbacks/xla_stats_monitor.py | 2 +- tests/deprecated_api/test_remove_1-7.py | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pytorch_lightning/callbacks/gpu_stats_monitor.py b/pytorch_lightning/callbacks/gpu_stats_monitor.py index 8913c9625ec42..56ab82e559280 100644 --- a/pytorch_lightning/callbacks/gpu_stats_monitor.py +++ b/pytorch_lightning/callbacks/gpu_stats_monitor.py @@ -29,7 +29,7 @@ import pytorch_lightning as pl from pytorch_lightning.callbacks.base import Callback -from pytorch_lightning.utilities import DeviceType, rank_zero_only, rank_zero_deprecation +from pytorch_lightning.utilities import DeviceType, rank_zero_deprecation, rank_zero_only from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.parsing import AttributeDict from pytorch_lightning.utilities.types import STEP_OUTPUT diff --git a/pytorch_lightning/callbacks/xla_stats_monitor.py b/pytorch_lightning/callbacks/xla_stats_monitor.py index b32793d60d47f..79ca20c81b794 100644 --- a/pytorch_lightning/callbacks/xla_stats_monitor.py +++ b/pytorch_lightning/callbacks/xla_stats_monitor.py @@ -21,7 +21,7 @@ import time from pytorch_lightning.callbacks.base import Callback -from pytorch_lightning.utilities import _TPU_AVAILABLE, DeviceType, rank_zero_info, rank_zero_deprecation +from pytorch_lightning.utilities import _TPU_AVAILABLE, DeviceType, rank_zero_deprecation, rank_zero_info from pytorch_lightning.utilities.exceptions import MisconfigurationException if _TPU_AVAILABLE: diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 9ab0b06661aae..07fb550f9e3cf 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -18,8 +18,7 @@ import torch from pytorch_lightning import Callback, LightningDataModule, Trainer -from pytorch_lightning.callbacks.xla_stats_monitor import GPUStatsMonitor -from pytorch_lightning.callbacks.xla_stats_monitor import XLAStatsMonitor +from pytorch_lightning.callbacks.xla_stats_monitor import GPUStatsMonitor, XLAStatsMonitor from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger from tests.deprecated_api import _soft_unimport_module from tests.helpers import BoringModel From 8806d9d9839353805ff2c3daea6e6f53f417773f Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 13 Oct 2021 23:12:49 -0700 Subject: [PATCH 4/7] fix import --- tests/deprecated_api/test_remove_1-7.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 07fb550f9e3cf..0769a5a1a95cd 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -18,7 +18,8 @@ import torch from pytorch_lightning import Callback, LightningDataModule, Trainer -from pytorch_lightning.callbacks.xla_stats_monitor import GPUStatsMonitor, XLAStatsMonitor +from pytorch_lightning.callbacks.gpu_stats_monitor import GPUStatsMonitor +from pytorch_lightning.callbacks.xla_stats_monitor import XLAStatsMonitor from pytorch_lightning.loggers import LoggerCollection, TestTubeLogger from tests.deprecated_api import _soft_unimport_module from tests.helpers import BoringModel From a85cdbdf8d5fcb43440c8e87f7a1920aac87505f Mon Sep 17 00:00:00 2001 From: Danielle Pintz Date: Wed, 13 Oct 2021 23:44:12 -0700 Subject: [PATCH 5/7] RunIf(min_gpus=1) --- pytorch_lightning/core/datamodule.py | 4 +++- tests/deprecated_api/test_remove_1-7.py | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pytorch_lightning/core/datamodule.py b/pytorch_lightning/core/datamodule.py index f3a5c855fe07a..44cd1bf5cd563 100644 --- a/pytorch_lightning/core/datamodule.py +++ b/pytorch_lightning/core/datamodule.py @@ -22,7 +22,9 @@ from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks from pytorch_lightning.core.mixins import HyperparametersMixin from pytorch_lightning.utilities import rank_zero_deprecation -from pytorch_lightning.utilities.argparse import add_argparse_args, from_argparse_args, get_init_arguments_and_types +from pytorch_lightning.utilities.argparse import (add_argparse_args, + from_argparse_args, + get_init_arguments_and_types) class LightningDataModule(CheckpointHooks, DataHooks, HyperparametersMixin): diff --git a/tests/deprecated_api/test_remove_1-7.py b/tests/deprecated_api/test_remove_1-7.py index 0769a5a1a95cd..4274ece17b617 100644 --- a/tests/deprecated_api/test_remove_1-7.py +++ b/tests/deprecated_api/test_remove_1-7.py @@ -370,12 +370,13 @@ def test_v1_7_0_weights_summary_trainer(tmpdir): t.weights_summary = "blah" +@RunIf(min_gpus=1) def test_v1_7_0_deprecate_gpu_stats_monitor(tmpdir): with pytest.deprecated_call(match="The `GPUStatsMonitor` callback was deprecated in v1.5"): _ = GPUStatsMonitor() @RunIf(tpu=True) -def test_v1_7_0_deprecate_tpu_stats_monitor(tmpdir): +def test_v1_7_0_deprecate_xla_stats_monitor(tmpdir): with pytest.deprecated_call(match="The `XLAStatsMonitor` callback was deprecated in v1.5"): _ = XLAStatsMonitor() From 754da5b0a636231ba5f21a6bcdb69075e2026c83 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 14 Oct 2021 06:45:23 +0000 Subject: [PATCH 6/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- pytorch_lightning/core/datamodule.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pytorch_lightning/core/datamodule.py b/pytorch_lightning/core/datamodule.py index 44cd1bf5cd563..f3a5c855fe07a 100644 --- a/pytorch_lightning/core/datamodule.py +++ b/pytorch_lightning/core/datamodule.py @@ -22,9 +22,7 @@ from pytorch_lightning.core.hooks import CheckpointHooks, DataHooks from pytorch_lightning.core.mixins import HyperparametersMixin from pytorch_lightning.utilities import rank_zero_deprecation -from pytorch_lightning.utilities.argparse import (add_argparse_args, - from_argparse_args, - get_init_arguments_and_types) +from pytorch_lightning.utilities.argparse import add_argparse_args, from_argparse_args, get_init_arguments_and_types class LightningDataModule(CheckpointHooks, DataHooks, HyperparametersMixin): From 73580a33af623f6b54f9c95f52747afa6a2996e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mochol=C3=AD?= Date: Thu, 14 Oct 2021 17:16:56 +0200 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Nicki Skafte Detlefsen Co-authored-by: Rohit Gupta --- pytorch_lightning/callbacks/gpu_stats_monitor.py | 8 ++++---- pytorch_lightning/callbacks/xla_stats_monitor.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pytorch_lightning/callbacks/gpu_stats_monitor.py b/pytorch_lightning/callbacks/gpu_stats_monitor.py index 56ab82e559280..eb0c090a9b8b1 100644 --- a/pytorch_lightning/callbacks/gpu_stats_monitor.py +++ b/pytorch_lightning/callbacks/gpu_stats_monitor.py @@ -38,8 +38,8 @@ class GPUStatsMonitor(Callback): r""" .. deprecated:: v1.5 - The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " - "Please use the `DeviceStatsMonitor` callback instead. + The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. + Please use the `DeviceStatsMonitor` callback instead. Automatically monitors and logs GPU stats during training stage. ``GPUStatsMonitor`` is a callback and in order to use it you need to assign a logger in the ``Trainer``. @@ -96,8 +96,8 @@ def __init__( super().__init__() rank_zero_deprecation( - "The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " - "Please use the `DeviceStatsMonitor` callback instead." + "The `GPUStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7." + " Please use the `DeviceStatsMonitor` callback instead." ) if shutil.which("nvidia-smi") is None: diff --git a/pytorch_lightning/callbacks/xla_stats_monitor.py b/pytorch_lightning/callbacks/xla_stats_monitor.py index 79ca20c81b794..20d3f1b8ba925 100644 --- a/pytorch_lightning/callbacks/xla_stats_monitor.py +++ b/pytorch_lightning/callbacks/xla_stats_monitor.py @@ -31,8 +31,8 @@ class XLAStatsMonitor(Callback): r""" .. deprecated:: v1.5 - The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " - "Please use the `DeviceStatsMonitor` callback instead. + The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. + Please use the `DeviceStatsMonitor` callback instead. Automatically monitors and logs XLA stats during training stage. ``XLAStatsMonitor`` is a callback and in order to use it you need to assign a logger in the ``Trainer``. @@ -57,8 +57,8 @@ def __init__(self, verbose: bool = True) -> None: super().__init__() rank_zero_deprecation( - "The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7. " - "Please use the `DeviceStatsMonitor` callback instead." + "The `XLAStatsMonitor` callback was deprecated in v1.5 and will be removed in v1.7." + " Please use the `DeviceStatsMonitor` callback instead." ) if not _TPU_AVAILABLE: