diff --git a/tests/hooks/test_group_offloading.py b/tests/hooks/test_group_offloading.py index 799da9b0999f..cfa7ad3a7235 100644 --- a/tests/hooks/test_group_offloading.py +++ b/tests/hooks/test_group_offloading.py @@ -356,6 +356,7 @@ def test_error_raised_if_streams_used_and_no_accelerator_device(self): onload_device=torch.device("cpu"), offload_type="leaf_level", use_stream=True ) + @pytest.mark.skipif(hasattr(torch.mps, "Stream"), reason="This PyTorch build exposes MPS streams.") def test_error_raised_if_streams_used_and_backend_has_no_streams(self): with pytest.raises(ValueError, match="backend implements streams, got `mps`"): self.model.enable_group_offload( @@ -646,8 +647,9 @@ def get_model(self): @pytest.mark.parametrize("offload_type", ["leaf_level", "block_level"]) @pytest.mark.skipif( - torch.device(torch_device).type not in ["cuda", "xpu"], - reason="Test requires a CUDA or XPU device.", + torch.device(torch_device).type not in {"cuda", "xpu", "mps"} + or not hasattr(torch.get_device_module(torch_device), "Stream"), + reason="Test requires a CUDA, XPU, or MPS device with stream support.", ) def test_conditional_modules_with_stream(self, offload_type: str): """Regression test: conditionally-executed modules must not cause device mismatch when using streams. diff --git a/tests/others/test_utils.py b/tests/others/test_utils.py index dd4ed7c6c1ae..6ee1b9702166 100755 --- a/tests/others/test_utils.py +++ b/tests/others/test_utils.py @@ -427,13 +427,16 @@ def test_unsupported_operations_raise_naming_the_backend(self): backend.mem_get_info() assert backend.Stream is torch.cpu.Stream, "undefined attributes forward to the backend module" backend.synchronize() - with pytest.raises(AttributeError, match="Stream"): - TorchDeviceBackend("mps").Stream() with CaptureLogger(torch_utils.logger) as cl: backend.reset_peak_memory_stats() assert backend.max_memory_allocated() == 0, "cpu keeps no memory statistics" assert "no memory statistics" in cl.out, f"no-op memory calls should warn, got: {cl.out}" + @pytest.mark.skipif(hasattr(torch.mps, "Stream"), reason="This PyTorch build exposes MPS streams.") + def test_missing_mps_stream_error_names_the_backend(self): + with pytest.raises(AttributeError, match=r"torch\.mps.*Stream"): + TorchDeviceBackend("mps").Stream() + def test_memory_statistics_on_the_host_accelerator(self): if get_device() == "cpu": pytest.skip("memory statistics need an accelerator")