From d91858c2325f0f9df5564c46add9c5b63f3b620b Mon Sep 17 00:00:00 2001 From: Yao Matrix Date: Wed, 16 Apr 2025 17:23:06 +0800 Subject: [PATCH] enable 3 mpt test cases on XPU (#37546) * enable 3 mpt test cases on XPU Signed-off-by: YAO Matrix * fix style Signed-off-by: YAO Matrix --------- Signed-off-by: YAO Matrix Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com> --- tests/models/mpt/test_modeling_mpt.py | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/models/mpt/test_modeling_mpt.py b/tests/models/mpt/test_modeling_mpt.py index 896048538c..458e458dd2 100644 --- a/tests/models/mpt/test_modeling_mpt.py +++ b/tests/models/mpt/test_modeling_mpt.py @@ -17,7 +17,14 @@ import math import unittest from transformers import MptConfig, is_torch_available -from transformers.testing_utils import require_bitsandbytes, require_torch, require_torch_gpu, slow, torch_device +from transformers.testing_utils import ( + Expectations, + require_bitsandbytes, + require_torch, + require_torch_accelerator, + slow, + torch_device, +) from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester @@ -424,7 +431,7 @@ class MptModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, @slow -@require_torch_gpu +@require_torch_accelerator @require_bitsandbytes class MptIntegrationTests(unittest.TestCase): def test_generation_8k(self): @@ -439,7 +446,7 @@ class MptIntegrationTests(unittest.TestCase): input_text = "Hello" expected_output = "Hello, I'm a new user of the forum. I have a question about the \"Solaris" - inputs = tokenizer(input_text, return_tensors="pt") + inputs = tokenizer(input_text, return_tensors="pt").to(torch_device) outputs = model.generate(**inputs, max_new_tokens=20) decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True) @@ -455,9 +462,22 @@ class MptIntegrationTests(unittest.TestCase): ) input_text = "Hello" - expected_output = "Hello and welcome to the first episode of the new podcast, The Frugal Feminist.\n" + expected_outputs = Expectations( + { + ( + "xpu", + 3, + ): "Hello and welcome to the first ever episode of the new and improved, and hopefully improved, podcast.\n", + ("cuda", 7): "Hello and welcome to the first episode of the new podcast, The Frugal Feminist.\n", + ( + "cuda", + 8, + ): "Hello and welcome to the first day of the new release countdown for the month of May!\nToday", + } + ) + expected_output = expected_outputs.get_expectation() - inputs = tokenizer(input_text, return_tensors="pt") + inputs = tokenizer(input_text, return_tensors="pt").to(torch_device) outputs = model.generate(**inputs, max_new_tokens=20) decoded_output = tokenizer.decode(outputs[0], skip_special_tokens=True)