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 AcceleratorConnector.tpu_id #12387

Merged
merged 4 commits into from
Mar 22, 2022
Merged
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Removed `AcceleratorConnector.root_gpu` property ([#12262](https://github.com/PyTorchLightning/pytorch-lightning/pull/12262))


- Removed `AcceleratorConnector.tpu_id` property ([#12387](https://github.com/PyTorchLightning/pytorch-lightning/pull/12387))


- Removed `AcceleratorConnector.num_gpus` property ([#12384](https://github.com/PyTorchLightning/pytorch-lightning/pull/12384))


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,6 @@ def tpu_cores(self) -> Optional[Union[List[int], int]]:
return self._tpu_cores # type: ignore
return 0

@property
def tpu_id(self) -> Optional[int]:
if isinstance(self.accelerator, TPUAccelerator):
if isinstance(self._tpu_cores, list):
return self._tpu_cores[0]
return None

krshrimali marked this conversation as resolved.
Show resolved Hide resolved
@property
def num_ipus(self) -> int:
if isinstance(self.accelerator, IPUAccelerator):
Expand Down
42 changes: 3 additions & 39 deletions tests/models/test_tpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,11 @@ def test_dataloaders_passed_to_fit(tmpdir):
assert trainer.state.finished, f"Training failed with {trainer.state}"


@pytest.mark.parametrize(
DuYicong515 marked this conversation as resolved.
Show resolved Hide resolved
["tpu_cores", "expected_tpu_id"],
[(1, None), (8, None), ([1], 1), ([8], 8)],
)
@RunIf(tpu=True)
def test_tpu_id_to_be_as_expected(tpu_cores, expected_tpu_id):
"""Test if trainer.tpu_id is set as expected."""
assert Trainer(tpu_cores=tpu_cores)._accelerator_connector.tpu_id == expected_tpu_id


def test_tpu_misconfiguration():
"""Test if trainer.tpu_id is set as expected."""
@pytest.mark.parametrize("tpu_cores", [[1, 8], "9, ", [9], [0], 2, 10])
def test_tpu_misconfiguration(tpu_cores):
with pytest.raises(MisconfigurationException, match="`tpu_cores` can only be"):
Trainer(tpu_cores=[1, 8])
Trainer(tpu_cores=tpu_cores)


@pytest.mark.skipif(_TPU_AVAILABLE, reason="test requires missing TPU")
Expand Down Expand Up @@ -289,33 +280,6 @@ def test_broadcast(rank):
xmp.spawn(test_broadcast, nprocs=8, start_method="fork")


@pytest.mark.parametrize(
rohitgr7 marked this conversation as resolved.
Show resolved Hide resolved
["tpu_cores", "expected_tpu_id", "error_expected"],
[
(1, None, False),
(8, None, False),
([1], 1, False),
([8], 8, False),
("1,", 1, False),
("1", None, False),
("9, ", 9, True),
([9], 9, True),
([0], 0, True),
(2, None, True),
(10, None, True),
],
DuYicong515 marked this conversation as resolved.
Show resolved Hide resolved
)
@RunIf(tpu=True)
@pl_multi_process_test
def test_tpu_choice(tmpdir, tpu_cores, expected_tpu_id, error_expected):
if error_expected:
with pytest.raises(MisconfigurationException, match=r".*tpu_cores` can only be 1, 8 or [<1-8>]*"):
Trainer(default_root_dir=tmpdir, tpu_cores=tpu_cores)
else:
trainer = Trainer(default_root_dir=tmpdir, tpu_cores=tpu_cores)
assert trainer._accelerator_connector.tpu_id == expected_tpu_id


@pytest.mark.parametrize(
["cli_args", "expected"],
[("--tpu_cores=8", {"tpu_cores": 8}), ("--tpu_cores=1,", {"tpu_cores": "1,"})],
Expand Down