From 8eb832b27426c886b0118dada645bc73c83b1547 Mon Sep 17 00:00:00 2001 From: Danielle Pintz <38207072+daniellepintz@users.noreply.github.com> Date: Thu, 14 Oct 2021 08:52:45 -0700 Subject: [PATCH] Deprecate `GPUStatsMonitor` and `XLAStatsMonitor` in favor of `DeviceStatsMonitor` (#9924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carlos MocholĂ­ Co-authored-by: Nicki Skafte Detlefsen Co-authored-by: Rohit Gupta --- 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 | 14 ++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6e1317068ea..82120133b2626 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -362,6 +362,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 ([#9924](https://github.com/PyTorchLightning/pytorch-lightning/pull/9924)) + ### 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..eb0c090a9b8b1 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_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 @@ -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..20d3f1b8ba925 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_deprecation, rank_zero_info 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..4274ece17b617 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.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 @@ -366,3 +368,15 @@ 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" + + +@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_xla_stats_monitor(tmpdir): + with pytest.deprecated_call(match="The `XLAStatsMonitor` callback was deprecated in v1.5"): + _ = XLAStatsMonitor()