Repository: huggingface/transformers
Pull request: enable some falcon-mamba uts on xpu

enable some falcon-mamba uts on xpu.

@ydshieh @SunMarc pls help review, thx very much

Changed files:
filename: src/transformers/models/falcon_mamba/modeling_falcon_mamba.py
patch: @@ -170,8 +170,13 @@ def _lazy_load_causal_conv1d():
     if is_kernels_available():
         from kernels import get_kernel
 
-        _causal_conv1d_kernel = get_kernel("kernels-community/causal-conv1d")
-        _causal_conv1d_cache = (_causal_conv1d_kernel.causal_conv1d_update, _causal_conv1d_kernel.causal_conv1d_fn)
+        try:
+            _causal_conv1d_kernel = get_kernel("kernels-community/causal-conv1d")
+        except FileNotFoundError:
+            # no kernel binary match, fallback to slow path
+            _causal_conv1d_cache = (None, None)
+        else:
+            _causal_conv1d_cache = (_causal_conv1d_kernel.causal_conv1d_update, _causal_conv1d_kernel.causal_conv1d_fn)
     elif is_causal_conv1d_available():
         from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
 

filename: src/transformers/models/mamba/modeling_mamba.py
patch: @@ -65,8 +65,13 @@ def _lazy_load_causal_conv1d():
     if is_kernels_available():
         from kernels import get_kernel
 
-        _causal_conv1d_kernel = get_kernel("kernels-community/causal-conv1d")
-        _causal_conv1d_cache = (_causal_conv1d_kernel.causal_conv1d_update, _causal_conv1d_kernel.causal_conv1d_fn)
+        try:
+            _causal_conv1d_kernel = get_kernel("kernels-community/causal-conv1d")
+        except FileNotFoundError:
+            # no kernel binary match, fallback to slow path
+            _causal_conv1d_cache = (None, None)
+        else:
+            _causal_conv1d_cache = (_causal_conv1d_kernel.causal_conv1d_update, _causal_conv1d_kernel.causal_conv1d_fn)
     elif is_causal_conv1d_available():
         from causal_conv1d import causal_conv1d_fn, causal_conv1d_update
 

filename: tests/models/falcon_mamba/test_modeling_falcon_mamba.py
patch: @@ -23,6 +23,7 @@
     Expectations,
     cleanup,
     require_bitsandbytes,
+    require_deterministic_for_xpu,
     require_torch,
     require_torch_accelerator,
     require_torch_large_accelerator,
@@ -421,6 +422,7 @@ def test_generation_fp16(self):
 
         EXPECTED_OUTPUTS = Expectations(
             {
+                ("xpu", 3): "Hello today Iava,\n\nI am writing to you today to discuss the importance of maintaining a healthy lifestyle",
                 ("cuda", 7): "Hello today I am going to show you how to make a simple and easy to make paper plane.\nStep",
                 ("cuda", 8): 'Hello today Iava,\n\nI am writing to you today to discuss the importance of maintaining a healthy lifestyle',
             }
@@ -454,13 +456,13 @@ def test_generation_torch_compile(self):
 
         inputs = self.tokenizer(self.text, return_tensors="pt").to(torch_device)
         out = model.generate(**inputs, max_new_tokens=20, do_sample=False)
-        print(self.tokenizer.batch_decode(out, skip_special_tokens=False)[0])
 
         self.assertEqual(
             self.tokenizer.batch_decode(out, skip_special_tokens=False)[0],
             "Hello today Iava,\n\nI am writing to you today to discuss the importance of maintaining a healthy lifestyle",
         )
 
+    @require_deterministic_for_xpu
     def test_batched_generation(self):
         model_id = "tiiuae/falcon-mamba-7b"
         tok = AutoTokenizer.from_pretrained(model_id)
@@ -470,6 +472,10 @@ def test_batched_generation(self):
 
         EXPECTED_OUTPUTS = Expectations(
             {
+                ("xpu", 3): [
+                    'Hello today I will be talking about the “Theory of Relativity” by Albert Einstein.\nThe',
+                    'Hello my name is Younes and today I will be talking about the importance of the internet in our lives.\nThe internet is a global',
+                ],
                 ("cuda", 7): [
                     'Hello today I will be talking about the “Theory of Relativity” by Albert Einstein.\nThe',
                     'Hello my name is Younes and today I will be talking about the importance of the internet in our lives.\nThe internet is a global',
@@ -500,6 +506,10 @@ def test_batched_generation(self):
 
         EXPECTED_OUTPUTS = Expectations(
             {
+                ("xpu", 3): [
+                    ' I will be talking about the “Theory of Relativity” by Albert Einstein.\nThe',
+                    ' I will be talking about the importance of the internet in our lives.\nThe internet is a global',
+                ],
                 ("cuda", 7): [
                     ' I will be talking about the “Theory of Relativity” by Albert Einstein.\nThe',
                     ' I will be talking about the importance of the internet in our lives.\nThe internet is a global',