Skip to content
Open
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
6 changes: 4 additions & 2 deletions tests/hooks/test_group_offloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.
Expand Down
7 changes: 5 additions & 2 deletions tests/others/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down