Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate GPUStatsMonitor and XLAStatsMonitor in favor of DeviceStatsMonitor #9924

Merged
merged 8 commits into from
Oct 14, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ([#9924](https://github.com/PyTorchLightning/pytorch-lightning/pull/9924))

### Removed

- Removed deprecated `metrics` ([#8586](https://github.com/PyTorchLightning/pytorch-lightning/pull/8586/))
Expand Down
11 changes: 10 additions & 1 deletion pytorch_lightning/callbacks/gpu_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@

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


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``.

Expand Down Expand Up @@ -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."
Expand Down
14 changes: 12 additions & 2 deletions pytorch_lightning/callbacks/xla_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
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:
import torch_xla.core.xla_model as xm


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:
Expand All @@ -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")

Expand Down
14 changes: 14 additions & 0 deletions tests/deprecated_api/test_remove_1-7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()