Skip to content

Commit

Permalink
Remove get_gpu_memory_map deprecated since v1.5 (#15617)
Browse files Browse the repository at this point in the history
* Remove function deprecated in v1.5

* Update changelog

* rip

* Update graveyard

Co-authored-by: Carlos Mocholí <[email protected]>

* Add death test

Co-authored-by: Carlos Mocholí <[email protected]>

* Update test case name

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address pre-commit failures

Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 11, 2022
1 parent 43fd9c1 commit a7befe1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

-

Expand Down
3 changes: 2 additions & 1 deletion src/pytorch_lightning/_graveyard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
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
25 changes: 25 additions & 0 deletions src/pytorch_lightning/_graveyard/utilities.py
Original file line number Diff line number Diff line change
@@ -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
37 changes: 1 addition & 36 deletions src/pytorch_lightning/utilities/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
23 changes: 23 additions & 0 deletions tests/tests_pytorch/graveyard/test_utilities.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit a7befe1

Please sign in to comment.