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

Fix failing mps tests #3145

Merged
merged 6 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions tests/ignite/distributed/comp_models/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import torch

from ignite.distributed.comp_models.base import _SerialModel, _torch_version_le_112, ComputationModel
from ignite.distributed.comp_models.base import _torch_version_le_112


@pytest.mark.skipif(
_torch_version_le_112 and torch.backends.mps.is_available(), reason="Temporary skip if MPS is available"
)
def test_serial_model():
_SerialModel.create_from_backend()
model = _SerialModel.create_from_context()
Expand All @@ -19,6 +17,8 @@ def test_serial_model():
assert model.get_node_rank() == 0
if torch.cuda.is_available():
assert model.device().type == "cuda"
elif _torch_version_le_112 and torch.backends.mps.is_available():
assert model.device().type == "mps"
pranavvp16 marked this conversation as resolved.
Show resolved Hide resolved
else:
assert model.device().type == "cpu"
assert model.backend() is None
Expand Down
7 changes: 2 additions & 5 deletions tests/ignite/distributed/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,13 @@ def _test_auto_model_optimizer(ws, device):
assert optimizer.backward_passes_per_step == backward_passes_per_step


@pytest.mark.skipif(
_torch_version_le_112 and torch.backends.mps.is_available(), reason="Temporary skip if MPS is available"
)
def test_auto_methods_no_dist():
_test_auto_dataloader(1, 1, batch_size=1)
_test_auto_dataloader(1, 1, batch_size=10, num_workers=2)
_test_auto_dataloader(1, 1, batch_size=10, sampler_name="WeightedRandomSampler")
_test_auto_dataloader(1, 1, batch_size=10, sampler_name="DistributedSampler")

_test_auto_model_optimizer(1, "cuda" if torch.cuda.is_available() else "cpu")
device = idist.device()
_test_auto_model_optimizer(1, device)


@pytest.mark.distributed
Expand Down
5 changes: 1 addition & 4 deletions tests/ignite/distributed/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,8 @@ def test_idist_parallel_n_procs_native(init_method, backend, get_fixed_dirname,


@pytest.mark.skipif("WORLD_SIZE" in os.environ, reason="Skip if launched as multiproc")
@pytest.mark.skipif(
_torch_version_le_112 and torch.backends.mps.is_available(), reason="Temporary skip if MPS is available"
)
def test_idist_parallel_no_dist():
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
device = idist.device()
with idist.Parallel(backend=None) as parallel:
parallel.run(_test_func, ws=1, device=device, backend=None, true_init_method=None)

Expand Down
8 changes: 5 additions & 3 deletions tests/ignite/distributed/utils/test_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
)


@pytest.mark.skipif(
_torch_version_le_112 and torch.backends.mps.is_available(), reason="Temporary skip if MPS is available"
)
def test_no_distrib(capsys):
assert idist.backend() is None
if torch.cuda.is_available():
assert idist.device().type == "cuda"
elif _torch_version_le_112 and torch.backends.mps.is_available():
assert idist.device().type == "mps"
else:
assert idist.device().type == "cpu"
assert idist.get_rank() == 0
Expand All @@ -43,6 +42,9 @@ def test_no_distrib(capsys):
assert "ignite.distributed.utils INFO: backend: None" in out[-1]
if torch.cuda.is_available():
assert "ignite.distributed.utils INFO: device: cuda" in out[-1]
elif _torch_version_le_112:
if torch.backends.mps.is_available():
assert "ignite.distributed.utils INFO: device: mps" in out[-1]
pranavvp16 marked this conversation as resolved.
Show resolved Hide resolved
else:
assert "ignite.distributed.utils INFO: device: cpu" in out[-1]
assert "ignite.distributed.utils INFO: rank: 0" in out[-1]
Expand Down
3 changes: 3 additions & 0 deletions tests/ignite/engine/test_create_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,15 @@ def _test_create_supervised_evaluator(
with_model_fn=with_model_fn,
)
x = torch.tensor([[1.0], [2.0]])
x.to(evaluator_device)
pranavvp16 marked this conversation as resolved.
Show resolved Hide resolved
y = torch.tensor([[3.0], [5.0]])
y.to(evaluator_device)
pranavvp16 marked this conversation as resolved.
Show resolved Hide resolved
if with_model_fn:
y += 0.01
data = [(x, y)]

if model_device == evaluator_device or ((model_device == "cpu") ^ (evaluator_device == "cpu")):
print("inside test")
pranavvp16 marked this conversation as resolved.
Show resolved Hide resolved
state = evaluator.run(data)

y_pred, y = state.output
Expand Down