diff --git a/src/pytorch_lightning/CHANGELOG.md b/src/pytorch_lightning/CHANGELOG.md index 16c9aed7a8..d6726f985d 100644 --- a/src/pytorch_lightning/CHANGELOG.md +++ b/src/pytorch_lightning/CHANGELOG.md @@ -50,7 +50,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). ### Removed -- +- Removed deprecated `pytorch_lightning.utilities.memory.get_gpu_memory_map` in favor of `pytorch_lightning.accelerators.cuda.get_nvidia_gpu_stats` ([#15617](https://github.com/Lightning-AI/lightning/pull/15617)) - diff --git a/src/pytorch_lightning/_graveyard/__init__.py b/src/pytorch_lightning/_graveyard/__init__.py index 0a507179e5..55f0f8241c 100644 --- a/src/pytorch_lightning/_graveyard/__init__.py +++ b/src/pytorch_lightning/_graveyard/__init__.py @@ -17,4 +17,5 @@ import pytorch_lightning._graveyard.core import pytorch_lightning._graveyard.legacy_import_unpickler import pytorch_lightning._graveyard.loggers import pytorch_lightning._graveyard.trainer -import pytorch_lightning._graveyard.training_type # noqa: F401 +import pytorch_lightning._graveyard.training_type +import pytorch_lightning._graveyard.utilities # noqa: F401 diff --git a/src/pytorch_lightning/_graveyard/utilities.py b/src/pytorch_lightning/_graveyard/utilities.py new file mode 100644 index 0000000000..b767414f73 --- /dev/null +++ b/src/pytorch_lightning/_graveyard/utilities.py @@ -0,0 +1,25 @@ +# 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 pytorch_lightning as pl + + +def _get_gpu_memory_map() -> None: + # TODO: Remove in v2.0.0 + raise RuntimeError( + "`pytorch_lightning.utilities.memory.get_gpu_memory_map` was deprecated in v1.5 and is no longer supported" + " as of v1.9. Use `pytorch_lightning.accelerators.cuda.get_nvidia_gpu_stats` instead." + ) + + +pl.utilities.memory.get_gpu_memory_map = _get_gpu_memory_map diff --git a/src/pytorch_lightning/utilities/memory.py b/src/pytorch_lightning/utilities/memory.py index f796d6d30a..7c1e04c7bb 100644 --- a/src/pytorch_lightning/utilities/memory.py +++ b/src/pytorch_lightning/utilities/memory.py @@ -14,11 +14,8 @@ """Utilities related to memory.""" import gc -import os -import shutil -import subprocess from io import BytesIO -from typing import Any, Dict +from typing import Any import torch from lightning_utilities.core.apply_func import apply_to_collection @@ -96,38 +93,6 @@ def garbage_collection_cuda() -> None: raise -def get_gpu_memory_map() -> Dict[str, float]: - r""" - .. deprecated:: v1.5 - This function was deprecated in v1.5 in favor of - `pytorch_lightning.accelerators.cuda._get_nvidia_gpu_stats` and will be removed in v1.7. - - Get the current gpu usage. - - Return: - A dictionary in which the keys are device ids as integers and - values are memory usage as integers in MB. - - Raises: - FileNotFoundError: - If nvidia-smi installation not found - """ - nvidia_smi_path = shutil.which("nvidia-smi") - if nvidia_smi_path is None: - raise FileNotFoundError("nvidia-smi: command not found") - result = subprocess.run( - [nvidia_smi_path, "--query-gpu=memory.used", "--format=csv,nounits,noheader"], - encoding="utf-8", - capture_output=True, - check=True, - ) - - # Convert lines into a dictionary - gpu_memory = [float(x) for x in result.stdout.strip().split(os.linesep)] - gpu_memory_map = {f"gpu_id: {gpu_id}/memory.used (MB)": memory for gpu_id, memory in enumerate(gpu_memory)} - return gpu_memory_map - - def get_model_size_mb(model: Module) -> float: """Calculates the size of a Module in megabytes. diff --git a/tests/tests_pytorch/graveyard/test_utilities.py b/tests/tests_pytorch/graveyard/test_utilities.py new file mode 100644 index 0000000000..e75c0ceaab --- /dev/null +++ b/tests/tests_pytorch/graveyard/test_utilities.py @@ -0,0 +1,23 @@ +# 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 + + +def test_v2_0_0_get_gpu_memory_map(): + from pytorch_lightning.utilities.memory import get_gpu_memory_map + + with pytest.raises( + RuntimeError, match="get_gpu_memory_map` was deprecated in v1.5 and is no longer supported as of v1.9." + ): + get_gpu_memory_map()