Repository: huggingface/transformers
Pull request: enable several cases on XPU

w/ this PR:
1. autoawq cases: 9 pass, 1 skip(should skip, since xpu doesn't support exllama, all optimized op will go through ipex backend), 2 fail
2. peft_integration cases: 2 pass, 1 fail(for bnb issue)
3. test_sdpa_can_dispatch_on_flash: 19 pass, 1 fail

fail cases:
tests/models/diffllama/test_modeling_diffllama.py::DiffLlamaModelTest::test_sdpa_can_dispatch_on_flash
tests/peft_integration/test_peft_integration.py::PeftIntegrationTester::test_peft_from_pretrained_kwargs
tests/quantization/autoawq/test_awq.py::AwqTest::test_quantized_model_bf16
tests/quantization/autoawq/test_awq.py::AwqTest::test_quantized_model_multi_gpu

We will follow 4 failure cases and submit fixing separate PRs.


Changed files:
filename: tests/models/falcon_mamba/test_modeling_falcon_mamba.py
patch: @@ -22,6 +22,7 @@
     require_bitsandbytes,
     require_torch,
     require_torch_accelerator,
+    require_torch_multi_accelerator,
     require_torch_multi_gpu,
     slow,
     torch_device,
@@ -517,7 +518,7 @@ def test_batched_generation(self):
 
         self.assertListEqual(out, EXPECTED_OUTPUT)
 
-    @require_torch_multi_gpu
+    @require_torch_multi_accelerator
     def test_training_kernel(self):
         model_id = "tiiuae/falcon-mamba-7b"
 

filename: tests/peft_integration/test_peft_integration.py
patch: @@ -35,7 +35,6 @@
     require_peft,
     require_torch,
     require_torch_accelerator,
-    require_torch_gpu,
     slow,
     torch_device,
 )
@@ -422,7 +421,7 @@ def test_delete_adapter(self):
                 self.assertNotIn("adapter_1", model.peft_config)
                 self.assertIn("adapter_2", model.peft_config)
 
-    @require_torch_gpu
+    @require_torch_accelerator
     @require_bitsandbytes
     def test_peft_from_pretrained_kwargs(self):
         """

filename: tests/quantization/autoawq/test_awq.py
patch: @@ -24,6 +24,7 @@
     require_intel_extension_for_pytorch,
     require_torch_accelerator,
     require_torch_gpu,
+    require_torch_multi_accelerator,
     require_torch_multi_gpu,
     slow,
     torch_device,
@@ -202,6 +203,7 @@ def test_quantized_model_bf16(self):
         output = quantized_model.generate(**input_ids, max_new_tokens=40)
         self.assertEqual(self.tokenizer.decode(output[0], skip_special_tokens=True), self.EXPECTED_OUTPUT_BF16)
 
+    @require_torch_gpu
     def test_quantized_model_exllama(self):
         """
         Simple test that checks if the quantized model is working properly with exllama backend
@@ -240,7 +242,7 @@ def test_save_pretrained(self):
             output = model.generate(**input_ids, max_new_tokens=40)
             self.assertEqual(self.tokenizer.decode(output[0], skip_special_tokens=True), self.EXPECTED_OUTPUT)
 
-    @require_torch_multi_gpu
+    @require_torch_multi_accelerator
     def test_quantized_model_multi_gpu(self):
         """
         Simple test that checks if the quantized model is working properly with multiple GPUs
@@ -275,7 +277,7 @@ def test_quantized_model_no_k_proj_quantized(self):
 
 
 @slow
-@require_torch_gpu
+@require_torch_accelerator
 @require_auto_awq
 @require_accelerate
 class AwqFusedTest(unittest.TestCase):

filename: tests/test_modeling_common.py
patch: @@ -3825,7 +3825,7 @@ def test_eager_matches_sdpa_inference(
                     )
 
     @require_torch_sdpa
-    @require_torch_gpu
+    @require_torch_accelerator
     @slow
     def test_sdpa_can_dispatch_on_flash(self):
         if not self.has_attentions:
@@ -3836,8 +3836,8 @@ def test_sdpa_can_dispatch_on_flash(self):
             self.skipTest(reason="This test requires an NVIDIA GPU with compute capability >= 8.0")
         elif device_type == "rocm" and major < 9:
             self.skipTest(reason="This test requires an AMD GPU with compute capability >= 9.0")
-        else:
-            self.skipTest(reason="This test requires a Nvidia or AMD GPU")
+        elif device_type not in ["cuda", "rocm", "xpu"]:
+            self.skipTest(reason="This test requires a Nvidia or AMD GPU, or an Intel XPU")
 
         torch.compiler.reset()