Skip to content

Fix tpu spawn plugin test #11131

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

Merged
merged 2 commits into from
Dec 18, 2021
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
1 change: 1 addition & 0 deletions dockers/tpu-tests/tpu_test_cases.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ local tputests = base.BaseTest {
echo $KUBE_GOOGLE_CLOUD_TPU_ENDPOINTS
export XRT_TPU_CONFIG="tpu_worker;0;${KUBE_GOOGLE_CLOUD_TPU_ENDPOINTS:7}"
coverage run --source=pytorch_lightning -m pytest -v --capture=no \
tests/plugins/test_tpu_spawn.py \
tests/profiler/test_xla_profiler.py \
pytorch_lightning/utilities/xla_device.py \
tests/accelerators/test_tpu.py \
Expand Down
6 changes: 3 additions & 3 deletions tests/plugins/test_tpu_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ def test_error_process_iterable_dataloader(_):

class BoringModelTPU(BoringModel):
def on_train_start(self) -> None:
assert self.device == torch.device("xla")
assert self.device == torch.device("xla", index=1)
assert os.environ.get("PT_XLA_DEBUG") == "1"


@RunIf(tpu=True)
@pl_multi_process_test
def test_model_tpu_one_core():
"""Tests if device/debug flag is set correctely when training and after teardown for TPUSpawnPlugin."""
trainer = Trainer(tpu_cores=1, fast_dev_run=True, plugin=TPUSpawnPlugin(debug=True))
trainer = Trainer(tpu_cores=1, fast_dev_run=True, strategy=TPUSpawnPlugin(debug=True))
# assert training type plugin attributes for device setting
assert isinstance(trainer.training_type_plugin, TPUSpawnPlugin)
assert not trainer.training_type_plugin.on_gpu
assert trainer.training_type_plugin.on_tpu
assert trainer.training_type_plugin.root_device == torch.device("xla")
assert trainer.training_type_plugin.root_device == torch.device("xla", index=1)
model = BoringModelTPU()
trainer.fit(model)
assert "PT_XLA_DEBUG" not in os.environ