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

Remove deprecated auto_select_gpus Trainer argument #16184

Merged
merged 7 commits into from
Dec 24, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/pytorch_lightning/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
* Removed the `Trainer(ipus=...)` argument
* Removed the `Trainer(num_processes=...)` argument

- Removed the deprecated automatic GPU selection ([#16184](https://github.com/Lightning-AI/lightning/pull/16184))
* Removed the `Trainer(auto_select_gpus=...)` argument
* Removed the `pytorch_lightning.tuner.auto_gpu_select.{pick_single_gpu,pick_multiple_gpus}` functions


## [unreleased] - 202Y-MM-DD

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,9 @@
TPUSpawnStrategy,
)
from pytorch_lightning.strategies.ddp_spawn import _DDP_FORK_ALIASES
from pytorch_lightning.tuner.auto_gpu_select import pick_multiple_gpus
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from pytorch_lightning.utilities.imports import _IPU_AVAILABLE
from pytorch_lightning.utilities.rank_zero import rank_zero_deprecation, rank_zero_info, rank_zero_warn
from pytorch_lightning.utilities.rank_zero import rank_zero_info, rank_zero_warn

log = logging.getLogger(__name__)

Expand All @@ -98,7 +97,6 @@ def __init__(
benchmark: Optional[bool] = None,
replace_sampler_ddp: bool = True,
deterministic: Optional[Union[bool, _LITERAL_WARN]] = False,
auto_select_gpus: Optional[bool] = None, # TODO: Remove in v1.10.0
) -> None:
"""The AcceleratorConnector parses several Trainer arguments and instantiates the Strategy including other
components such as the Accelerator and Precision plugins.
Expand Down Expand Up @@ -161,7 +159,6 @@ def __init__(
self._parallel_devices: List[Union[int, torch.device, str]] = []
self._layer_sync: Optional[LayerSync] = NativeSyncBatchNorm() if sync_batchnorm else None
self.checkpoint_io: Optional[CheckpointIO] = None
self._auto_select_gpus: Optional[bool] = auto_select_gpus

self._check_config_and_set_final_flags(
strategy=strategy,
Expand Down Expand Up @@ -426,7 +423,6 @@ def _set_parallel_devices_and_init_accelerator(self) -> None:
)

self._set_devices_flag_if_auto_passed()
self._set_devices_flag_if_auto_select_gpus_passed()
self._devices_flag = accelerator_cls.parse_devices(self._devices_flag)
if not self._parallel_devices:
self._parallel_devices = accelerator_cls.get_parallel_devices(self._devices_flag)
Expand All @@ -435,24 +431,6 @@ def _set_devices_flag_if_auto_passed(self) -> None:
if self._devices_flag == "auto" or self._devices_flag is None:
self._devices_flag = self.accelerator.auto_device_count()

def _set_devices_flag_if_auto_select_gpus_passed(self) -> None:
if self._auto_select_gpus is not None:
rank_zero_deprecation(
"The Trainer argument `auto_select_gpus` has been deprecated in v1.9.0 and will be removed in v1.10.0."
" Please use the function `pytorch_lightning.accelerators.find_usable_cuda_devices` instead."
)
if (
self._auto_select_gpus
and isinstance(self._devices_flag, int)
and isinstance(self.accelerator, CUDAAccelerator)
):
self._devices_flag = pick_multiple_gpus(
self._devices_flag,
# we already show a deprecation message when user sets Trainer(auto_select_gpus=...)
_show_deprecation=False,
)
log.info(f"Auto select gpus: {self._devices_flag}")

def _choose_and_init_cluster_environment(self) -> ClusterEnvironment:
if isinstance(self._cluster_environment_flag, ClusterEnvironment):
return self._cluster_environment_flag
Expand Down
12 changes: 0 additions & 12 deletions src/pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ def __init__(
gradient_clip_algorithm: Optional[str] = None,
num_nodes: int = 1,
devices: Optional[Union[List[int], str, int]] = None,
auto_select_gpus: Optional[bool] = None, # TODO: Remove in 2.0
enable_progress_bar: bool = True,
overfit_batches: Union[int, float] = 0.0,
track_grad_norm: Union[int, float, str] = -1,
Expand Down Expand Up @@ -184,16 +183,6 @@ def __init__(
a power search or `binsearch` that estimates the batch size through a binary search.
Default: ``False``.

auto_select_gpus: If enabled and ``gpus`` or ``devices`` is an integer, pick available
gpus automatically. This is especially useful when
GPUs are configured to be in "exclusive mode", such
that only one process at a time can access them.
Default: ``False``.

.. deprecated:: v1.9
``auto_select_gpus`` has been deprecated in v1.9.0 and will be removed in v1.10.0.
Please use the function :func:`~lightning_lite.accelerators.cuda.find_usable_cuda_devices` instead.

benchmark: The value (``True`` or ``False``) to set ``torch.backends.cudnn.benchmark`` to.
The value for ``torch.backends.cudnn.benchmark`` set in the current session will be used
(``False`` if not manually set). If :paramref:`~pytorch_lightning.trainer.Trainer.deterministic` is set
Expand Down Expand Up @@ -372,7 +361,6 @@ def __init__(
benchmark=benchmark,
replace_sampler_ddp=replace_sampler_ddp,
deterministic=deterministic,
auto_select_gpus=auto_select_gpus,
precision=precision,
plugins=plugins,
)
Expand Down
96 changes: 0 additions & 96 deletions src/pytorch_lightning/tuner/auto_gpu_select.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/tests_pytorch/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def reset_deterministic_algorithm():
def mock_cuda_count(monkeypatch, n: int) -> None:
monkeypatch.setattr(lightning_fabric.accelerators.cuda, "num_cuda_devices", lambda: n)
monkeypatch.setattr(pytorch_lightning.accelerators.cuda, "num_cuda_devices", lambda: n)
monkeypatch.setattr(pytorch_lightning.tuner.auto_gpu_select, "num_cuda_devices", lambda: n)


@pytest.fixture(scope="function")
Expand Down
22 changes: 0 additions & 22 deletions tests/tests_pytorch/deprecated_api/test_remove_1-10.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from torch.utils.data import DataLoader

import pytorch_lightning.profiler as profiler
from lightning_fabric.utilities.exceptions import MisconfigurationException
from pytorch_lightning import Trainer
from pytorch_lightning.accelerators.cpu import CPUAccelerator
from pytorch_lightning.cli import LightningCLI
Expand All @@ -34,7 +33,6 @@
from pytorch_lightning.strategies.bagua import LightningBaguaModule
from pytorch_lightning.strategies.utils import on_colab_kaggle
from pytorch_lightning.trainer.states import RunningStage, TrainerFn
from pytorch_lightning.tuner.auto_gpu_select import pick_multiple_gpus, pick_single_gpu
from pytorch_lightning.utilities.apply_func import (
apply_to_collection,
apply_to_collections,
Expand Down Expand Up @@ -329,23 +327,3 @@ def test_profiler_classes_deprecated_warning(cls):
f" Use .*profilers.{cls.__name__}` class instead."
):
cls()


def test_auto_select_gpus():
with pytest.deprecated_call(match="The Trainer argument `auto_select_gpus` has been deprecated in v1.9.0"):
Trainer(auto_select_gpus=False)


def test_pick_multiple_gpus():
with pytest.deprecated_call(match="The function `pick_multiple_gpus` has been deprecated in v1.9.0"), pytest.raises(
MisconfigurationException
):
pick_multiple_gpus(0)


@mock.patch("pytorch_lightning.tuner.auto_gpu_select.num_cuda_devices", return_value=0)
def test_pick_single_gpu(_):
with pytest.deprecated_call(match="The function `pick_single_gpu` has been deprecated in v1.9.0"), pytest.raises(
RuntimeError
):
pick_single_gpu([])
59 changes: 0 additions & 59 deletions tests/tests_pytorch/trainer/properties/test_auto_gpu_select.py

This file was deleted.

9 changes: 0 additions & 9 deletions tests/tests_pytorch/trainer/test_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1168,15 +1168,6 @@ def test_invalid_gradient_clip_algo(tmpdir):
Trainer(default_root_dir=tmpdir, gradient_clip_algorithm="norm2")


@RunIf(min_cuda_gpus=1)
def test_invalid_gpu_choice_with_auto_select_gpus():
num_gpus = torch.cuda.device_count()
with pytest.raises(MisconfigurationException, match=r".*but your machine only has.*"), pytest.deprecated_call(
match="The function `pick_multiple_gpus` has been deprecated in v1.9.0"
):
Trainer(accelerator="gpu", devices=num_gpus + 1, auto_select_gpus=True)


@pytest.mark.parametrize("limit_val_batches", [0.0, 1, 1.0, 0.5, 5])
def test_num_sanity_val_steps(tmpdir, limit_val_batches):
"""Test that the number of sanity check batches is clipped to `limit_val_batches`."""
Expand Down