From f4633132cf2a050ee6b924867053d36556ff912c Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 15 Mar 2022 02:59:02 +0400 Subject: [PATCH 1/6] Remove TPU Availability check from parse devices --- pytorch_lightning/utilities/device_parser.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pytorch_lightning/utilities/device_parser.py b/pytorch_lightning/utilities/device_parser.py index 3865ff0ee6bb9..b0c5a991b9036 100644 --- a/pytorch_lightning/utilities/device_parser.py +++ b/pytorch_lightning/utilities/device_parser.py @@ -17,7 +17,6 @@ from pytorch_lightning.plugins.environments import TorchElasticEnvironment from pytorch_lightning.tuner.auto_gpu_select import pick_multiple_gpus -from pytorch_lightning.utilities import _TPU_AVAILABLE from pytorch_lightning.utilities.exceptions import MisconfigurationException from pytorch_lightning.utilities.types import _DEVICE @@ -132,8 +131,8 @@ def parse_tpu_cores(tpu_cores: Optional[Union[int, str, List[int]]]) -> Optional if not _tpu_cores_valid(tpu_cores): raise MisconfigurationException("`tpu_cores` can only be 1, 8 or [<1-8>]") - if tpu_cores is not None and not _TPU_AVAILABLE: - raise MisconfigurationException("No TPU devices were found.") + if tpu_cores is not None: + raise MisconfigurationException(f"No TPU devices for {tpu_cores} were found.") return tpu_cores From 413973eb4fb66f7cbf26dfbf056b47029d06490f Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 29 Mar 2022 17:37:38 +0530 Subject: [PATCH 2/6] Update parse_tpu_cores --- pytorch_lightning/utilities/device_parser.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pytorch_lightning/utilities/device_parser.py b/pytorch_lightning/utilities/device_parser.py index b0c5a991b9036..52fcdb8288f8d 100644 --- a/pytorch_lightning/utilities/device_parser.py +++ b/pytorch_lightning/utilities/device_parser.py @@ -131,9 +131,6 @@ def parse_tpu_cores(tpu_cores: Optional[Union[int, str, List[int]]]) -> Optional if not _tpu_cores_valid(tpu_cores): raise MisconfigurationException("`tpu_cores` can only be 1, 8 or [<1-8>]") - if tpu_cores is not None: - raise MisconfigurationException(f"No TPU devices for {tpu_cores} were found.") - return tpu_cores From 3a2efac65040bcfbbf7e64013c9cafedd8e5e087 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 29 Mar 2022 17:39:23 +0530 Subject: [PATCH 3/6] Update parse_tpu_cores --- pytorch_lightning/utilities/device_parser.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/device_parser.py b/pytorch_lightning/utilities/device_parser.py index 52fcdb8288f8d..ef857bad87471 100644 --- a/pytorch_lightning/utilities/device_parser.py +++ b/pytorch_lightning/utilities/device_parser.py @@ -121,7 +121,7 @@ def parse_tpu_cores(tpu_cores: Optional[Union[int, str, List[int]]]) -> Optional Raises: MisconfigurationException: - If TPU cores aren't 1 or 8 cores, or no TPU devices are found + If TPU cores aren't 1, 8 or [<1-8>] """ _check_data_type(tpu_cores) From 44e8f8a90b51824ab6661233df5d32aadeb20dea Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 29 Mar 2022 17:44:38 +0530 Subject: [PATCH 4/6] Update tests --- tests/accelerators/test_accelerator_connector.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tests/accelerators/test_accelerator_connector.py b/tests/accelerators/test_accelerator_connector.py index 876c60d150dad..ccb7bc557b8e6 100644 --- a/tests/accelerators/test_accelerator_connector.py +++ b/tests/accelerators/test_accelerator_connector.py @@ -446,8 +446,7 @@ def test_ipython_compatible_dp_strategy_gpu(_, monkeypatch): @mock.patch("pytorch_lightning.accelerators.tpu.TPUAccelerator.is_available", return_value=True) -@mock.patch("pytorch_lightning.accelerators.tpu.TPUAccelerator.parse_devices", return_value=8) -def test_ipython_compatible_strategy_tpu(mock_devices, mock_tpu_acc_avail, monkeypatch): +def test_ipython_compatible_strategy_tpu(mock_tpu_acc_avail, monkeypatch): monkeypatch.setattr(pytorch_lightning.utilities, "_IS_INTERACTIVE", True) trainer = Trainer(accelerator="tpu") assert trainer.strategy.launcher is None or trainer.strategy.launcher.is_interactive_compatible @@ -894,8 +893,7 @@ def test_strategy_choice_ddp_cpu_slurm(device_count_mock, setup_distributed_mock @mock.patch("pytorch_lightning.accelerators.tpu.TPUAccelerator.is_available", return_value=True) -@mock.patch("pytorch_lightning.accelerators.tpu.TPUAccelerator.parse_devices", return_value=8) -def test_unsupported_tpu_choice(mock_devices, mock_tpu_acc_avail): +def test_unsupported_tpu_choice(mock_tpu_acc_avail): with pytest.raises(MisconfigurationException, match=r"accelerator='tpu', precision=64\)` is not implemented"): Trainer(accelerator="tpu", precision=64) From c64164f2e9abca7fbd0d435e5cefcb4c628704b2 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 29 Mar 2022 17:47:21 +0530 Subject: [PATCH 5/6] Update test --- tests/deprecated_api/test_remove_1-8.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/deprecated_api/test_remove_1-8.py b/tests/deprecated_api/test_remove_1-8.py index 4155804c4da80..0bc4aadc85959 100644 --- a/tests/deprecated_api/test_remove_1-8.py +++ b/tests/deprecated_api/test_remove_1-8.py @@ -1140,8 +1140,7 @@ def test_trainer_gpus(monkeypatch, trainer_kwargs): def test_trainer_tpu_cores(monkeypatch): monkeypatch.setattr(pytorch_lightning.accelerators.tpu.TPUAccelerator, "is_available", lambda: True) - monkeypatch.setattr(pytorch_lightning.accelerators.tpu.TPUAccelerator, "parse_devices", lambda: 8) - trainer = Trainer(accelerator="TPU", devices=8) + 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." From 659199ebd450e2fee2b5af6b60526c3a450329a8 Mon Sep 17 00:00:00 2001 From: Kaushik B Date: Tue, 29 Mar 2022 18:05:55 +0530 Subject: [PATCH 6/6] Fix tests --- tests/deprecated_api/test_remove_1-8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/deprecated_api/test_remove_1-8.py b/tests/deprecated_api/test_remove_1-8.py index 0bc4aadc85959..8975a8a3d47c1 100644 --- a/tests/deprecated_api/test_remove_1-8.py +++ b/tests/deprecated_api/test_remove_1-8.py @@ -1139,7 +1139,7 @@ def test_trainer_gpus(monkeypatch, trainer_kwargs): def test_trainer_tpu_cores(monkeypatch): - monkeypatch.setattr(pytorch_lightning.accelerators.tpu.TPUAccelerator, "is_available", lambda: True) + 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. "