From 5ab7a7c640c7305e435d14443a4c16b0d673b74c Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Wed, 16 Apr 2025 15:28:02 +0800 Subject: [PATCH] enable 5 cases on XPU (#37507) * make speecht5 test_batch_generation pass on XPU Signed-off-by: YAO Matrix * enable 4 GlmIntegrationTest cases on XPU Signed-off-by: YAO Matrix * fix style Signed-off-by: YAO Matrix * Update src/transformers/testing_utils.py Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com> --------- Signed-off-by: YAO Matrix Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com> --- src/transformers/testing_utils.py | 13 +++++++++++++ tests/models/glm/test_modeling_glm.py | 4 ++-- tests/models/speecht5/test_modeling_speecht5.py | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/transformers/testing_utils.py b/src/transformers/testing_utils.py index 48d4cd30ed..380194a023 100644 --- a/src/transformers/testing_utils.py +++ b/src/transformers/testing_utils.py @@ -1026,6 +1026,19 @@ def require_torch_large_gpu(test_case, memory: float = 20): )(test_case) +def require_torch_large_accelerator(test_case, memory: float = 20): + """Decorator marking a test that requires an accelerator with more than `memory` GiB of memory.""" + if torch_device != "cuda" and torch_device != "xpu": + return unittest.skip(reason=f"test requires a GPU or XPU with more than {memory} GiB of memory")(test_case) + + torch_accelerator_module = getattr(torch, torch_device) + + return unittest.skipUnless( + torch_accelerator_module.get_device_properties(0).total_memory / 1024**3 > memory, + f"test requires a GPU or XPU with more than {memory} GiB of memory", + )(test_case) + + def require_torch_gpu_if_bnb_not_multi_backend_enabled(test_case): """ Decorator marking a test that requires a GPU if bitsandbytes multi-backend feature is not enabled. diff --git a/tests/models/glm/test_modeling_glm.py b/tests/models/glm/test_modeling_glm.py index 852f9524eb..f4dc0ab81b 100644 --- a/tests/models/glm/test_modeling_glm.py +++ b/tests/models/glm/test_modeling_glm.py @@ -22,7 +22,7 @@ from transformers.testing_utils import ( is_flaky, require_flash_attn, require_torch, - require_torch_large_gpu, + require_torch_large_accelerator, require_torch_sdpa, slow, torch_device, @@ -309,7 +309,7 @@ class GlmModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, @slow -@require_torch_large_gpu +@require_torch_large_accelerator class GlmIntegrationTest(unittest.TestCase): input_text = ["Hello I am doing", "Hi today"] model_id = "THUDM/glm-4-9b" diff --git a/tests/models/speecht5/test_modeling_speecht5.py b/tests/models/speecht5/test_modeling_speecht5.py index 3655a188d8..34c5972cd4 100644 --- a/tests/models/speecht5/test_modeling_speecht5.py +++ b/tests/models/speecht5/test_modeling_speecht5.py @@ -1223,6 +1223,7 @@ class SpeechT5ForTextToSpeechIntegrationTests(unittest.TestCase): "Mismatch in waveform between standalone and integrated vocoder for single instance generation.", ) + @require_deterministic_for_xpu def test_batch_generation(self): model = self.default_model processor = self.default_processor