Skip to content

Deprecate Trainer.root_gpu #12064

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

Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

- Deprecated `Trainer.lr_schedulers` in favor of `Trainer.lr_scheduler_configs` which returns a list of dataclasses instead of dictionaries ([#11443](https://github.com/PyTorchLightning/pytorch-lightning/pull/11443))

- Deprecated `Trainer.root_gpu` in favor of `Trainer.strategy.root_device` ([#11994](https://github.com/PyTorchLightning/pytorch-lightning/pull/11994))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Deprecated `Trainer.root_gpu` in favor of `Trainer.strategy.root_device` ([#11994](https://github.com/PyTorchLightning/pytorch-lightning/pull/11994))
- Deprecated `Trainer.root_gpu` in favor of `Trainer.strategy.root_device.index` ([#11994](https://github.com/PyTorchLightning/pytorch-lightning/pull/11994))


- Deprecated `Trainer.verbose_evaluate` in favor of `EvaluationLoop(verbose=...)` ([#10931](https://github.com/PyTorchLightning/pytorch-lightning/pull/10931))

Expand Down
5 changes: 4 additions & 1 deletion pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,7 +2022,10 @@ def num_processes(self) -> int:

@property
def root_gpu(self) -> Optional[int]:
return self._accelerator_connector.root_gpu
rank_zero_deprecation(
"Method `trainer.root_gpu` is deprecated please use `trainer.strategy.root_device.index`", stacklevel=5
)
return self._strategy.root_device.index

@property
def tpu_cores(self) -> int:
Expand Down
2 changes: 1 addition & 1 deletion tests/models/data/horovod/train_default_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def training_epoch_end(self, outputs) -> None:
if on_gpu:
trainer = Trainer(gpus=1, strategy="horovod", max_epochs=1)
# Test the root_gpu property
assert trainer.root_gpu == hvd.local_rank()
assert trainer.strategy.root_device.index == hvd.local_rank()


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions tests/models/test_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def test_trainer_num_gpu_0(mocked_device_count_0, gpus, expected_num_gpus, strat
pytest.param(3, 0, "ddp", id="3 gpus, expect gpu root device to be 0.(backend:ddp)"),
],
)
def test_root_gpu_property(mocked_device_count, gpus, expected_root_gpu, strategy):
assert Trainer(gpus=gpus, strategy=strategy).root_gpu == expected_root_gpu
def test_root_device_property(mocked_device_count, gpus, expected_root_gpu, strategy):
assert Trainer(gpus=gpus, strategy=strategy).strategy.root_device.index == expected_root_gpu


@pytest.mark.parametrize(
Expand All @@ -141,8 +141,8 @@ def test_root_gpu_property(mocked_device_count, gpus, expected_root_gpu, strateg
pytest.param(0, None, "ddp", id="None is None"),
],
)
def test_root_gpu_property_0_passing(mocked_device_count_0, gpus, expected_root_gpu, strategy):
assert Trainer(gpus=gpus, strategy=strategy).root_gpu == expected_root_gpu
def test_root_device_property_0_passing(mocked_device_count_0, gpus, expected_root_gpu, strategy):
assert Trainer(gpus=gpus, strategy=strategy).strategy.root_device.index == expected_root_gpu


# Asking for a gpu when non are available will result in a MisconfigurationException
Expand Down