From 6fcbb3473eb26d6dc6d00021d1095b8fca8c3aa8 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Mon, 4 May 2026 19:50:54 -0400 Subject: [PATCH] tests: Gracefully handle missing set_device for mps mps backend doesn't have set_device, so if mps is available on test run, the test fails with: AttributeError: does not have the attribute 'set_device' --- tests/test_accelerator.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_accelerator.py b/tests/test_accelerator.py index ebab8a8c057..6ac346c0cc6 100644 --- a/tests/test_accelerator.py +++ b/tests/test_accelerator.py @@ -259,7 +259,9 @@ def noop(*args, **kwargs): pass with ( - patch(f"torch.{torch_device}.set_device", noop), + # Some backends such as MPS do not expose a module-level `set_device`. + # This test only exercises env var parsing, so a synthetic attribute is enough. + patch(f"torch.{torch_device}.set_device", noop, create=True), patch_environment(ACCELERATE_TORCH_DEVICE=f"{torch_device}:64"), ): accelerator = Accelerator()