Skip to content

Commit f8f34ad

Browse files
committed
deprecation test
1 parent 4687517 commit f8f34ad

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
552552
- Deprecated `Trainer.data_parallel_device_ids` in favor of `Trainer.device_ids` ([#12072](https://github.com/PyTorchLightning/pytorch-lightning/pull/12072))
553553

554554

555+
- Deprecated `Trainer.gpus` in favor of `Trainer.device_ids` or `Trainer.num_devices` ([#12436](https://github.com/PyTorchLightning/pytorch-lightning/pull/12436))
556+
557+
555558
### Removed
556559

557560
- Removed deprecated parameter `method` in `pytorch_lightning.utilities.model_helpers.is_overridden` ([#10507](https://github.com/PyTorchLightning/pytorch-lightning/pull/10507))

pytorch_lightning/callbacks/gpu_stats_monitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ def setup(self, trainer: "pl.Trainer", pl_module: "pl.LightningModule", stage: O
128128

129129
if trainer.strategy.root_device.type != "cuda":
130130
raise MisconfigurationException(
131-
"You are using GPUStatsMonitor but are not running on GPU"
132-
f" since gpus attribute in Trainer is set to {trainer.gpus}."
131+
"You are using GPUStatsMonitor but are not running on GPU."
132+
f"The root device type is {trainer.strategy.root_device.type}."
133133
)
134134

135135
# The logical device IDs for selected devices

tests/deprecated_api/test_remove_1-8.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,3 +1054,24 @@ def test_trainer_data_parallel_device_ids(monkeypatch, trainer_kwargs, expected_
10541054
" Please use `Trainer.device_ids` instead."
10551055
):
10561056
assert trainer.data_parallel_device_ids == expected_data_parallel_device_ids
1057+
1058+
1059+
@pytest.mark.parametrize(
1060+
"trainer_kwargs",
1061+
[
1062+
{"accelerator": "gpu", "devices": 2},
1063+
{"accelerator": "gpu", "devices": [0, 2]},
1064+
{"accelerator": "gpu", "devices": "0"},
1065+
{"accelerator": "gpu", "devices": "2"},
1066+
{"accelerator": "gpu", "devices": "0,"},
1067+
],
1068+
)
1069+
def test_trainer_gpus(monkeypatch, trainer_kwargs):
1070+
monkeypatch.setattr(torch.cuda, "is_available", lambda: True)
1071+
monkeypatch.setattr(torch.cuda, "device_count", lambda: 4)
1072+
trainer = Trainer(**trainer_kwargs)
1073+
with pytest.deprecated_call(
1074+
match="`Trainer.gpus` was deprecated in v1.6 and will be removed in v1.8."
1075+
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
1076+
):
1077+
assert trainer.gpus == trainer_kwargs.get("devices")

0 commit comments

Comments
 (0)