Skip to content

Commit

Permalink
Remove remaining old-style AcceleratorConnector properties (#13412)
Browse files Browse the repository at this point in the history
Co-authored-by: Jirka <[email protected]>
  • Loading branch information
awaelchli and Borda authored Jun 29, 2022
1 parent 55e347b commit 43635a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -811,22 +811,9 @@ def _lazy_init_strategy(self) -> None:
f" found {self.strategy.__class__.__name__}."
)

"""The following properties are here for backward-compatibility and will be deprecated and removed in favor
of accessing this information through the strategy/accelerator directly."""
# TODO: deprecate all properties below

@property
def tpu_cores(self) -> Optional[Union[List[int], int]]:
if isinstance(self.accelerator, TPUAccelerator):
return self._tpu_cores # type: ignore
return 0

@property
def gpus(self) -> Optional[Union[List[int], str, int]]:
return self._gpus

@property
def is_distributed(self) -> bool:
# TODO: deprecate this property
# Used for custom plugins.
# Custom plugins should implement is_distributed property.
if hasattr(self.strategy, "is_distributed") and not isinstance(self.accelerator, TPUAccelerator):
Expand Down
2 changes: 1 addition & 1 deletion src/pytorch_lightning/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2180,7 +2180,7 @@ def gpus(self) -> Optional[Union[List[int], str, int]]:
"`Trainer.gpus` was deprecated in v1.6 and will be removed in v1.8."
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
)
return self._accelerator_connector.gpus
return self._accelerator_connector._gpus

@property
def model(self) -> torch.nn.Module:
Expand Down
12 changes: 8 additions & 4 deletions tests/tests_pytorch/deprecated_api/test_remove_1-8.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,8 +1131,10 @@ def test_trainer_gpus(monkeypatch, trainer_kwargs):
monkeypatch.setattr(torch.cuda, "device_count", lambda: 4)
trainer = Trainer(**trainer_kwargs)
with pytest.deprecated_call(
match="`Trainer.gpus` was deprecated in v1.6 and will be removed in v1.8."
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
match=(
"`Trainer.gpus` was deprecated in v1.6 and will be removed in v1.8."
" Please use `Trainer.num_devices` or `Trainer.device_ids` to get device information instead."
)
):
assert trainer.gpus == trainer_kwargs["devices"]

Expand All @@ -1141,8 +1143,10 @@ def test_trainer_tpu_cores(monkeypatch):
monkeypatch.setattr(pytorch_lightning.accelerators.tpu.TPUAccelerator, "is_available", lambda _: True)
trainer = Trainer(accelerator="tpu", devices=8)
with pytest.deprecated_call(
match="`Trainer.tpu_cores` is deprecated in v1.6 and will be removed in v1.8. "
"Please use `Trainer.num_devices` instead."
match=(
"`Trainer.tpu_cores` is deprecated in v1.6 and will be removed in v1.8. "
"Please use `Trainer.num_devices` instead."
)
):
assert trainer.tpu_cores == 8

Expand Down

0 comments on commit 43635a9

Please sign in to comment.