Remove `get_gpu_memory_map` deprecated since v1.5 (#15617)
* Remove function deprecated in v1.5 * Update changelog * rip * Update graveyard Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com> * Add death test Co-authored-by: Carlos Mocholí <carlossmocholi@gmail.com> * 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í <carlossmocholi@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
43fd9c1534
commit
a7befe1238
|
@ -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))
|
||||
|
||||
-
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue