From d43d0853dcf3a1db04302c7b527e92ace3ccfb55 Mon Sep 17 00:00:00 2001
From: AldarisX <aldaris@axnet.icu>
Date: 星期一, 07 四月 2025 21:20:31 +0800
Subject: [PATCH] add intel xpu support (#2468)

---
 funasr/auto/auto_model.py |   41 +++++------------------------------------
 1 files changed, 5 insertions(+), 36 deletions(-)

diff --git a/funasr/auto/auto_model.py b/funasr/auto/auto_model.py
index f5cbe01..d274fb9 100644
--- a/funasr/auto/auto_model.py
+++ b/funasr/auto/auto_model.py
@@ -182,7 +182,9 @@
         set_all_random_seed(kwargs.get("seed", 0))
 
         device = kwargs.get("device", "cuda")
-        if not torch.cuda.is_available() or kwargs.get("ngpu", 1) == 0:
+        if ((device =="cuda" and not torch.cuda.is_available())
+            or (device == "xpu" and not torch.xpu.is_available())
+            or kwargs.get("ngpu", 1) == 0):
             device = "cpu"
             kwargs["batch_size"] = 1
         kwargs["device"] = device
@@ -549,41 +551,8 @@
 
             # speaker embedding cluster after resorted
             if self.spk_model is not None and kwargs.get("return_spk_res", True):
-                # 1. 鍏堟鏌ユ椂闂存埑
-                has_timestamp = (
-                    hasattr(self.model, "internal_punc") or
-                    self.punc_model is not None or
-                    "timestamp" in result
-                )
-                
-                if not has_timestamp:
-                    logging.error("Need timestamp support...")
-                    return results_ret_list
-
-                # 2. 鍒濆鍖� punc_res
-                punc_res = None
-                
-                # 3. 鏍规嵁涓嶅悓鎯呭喌璁剧疆 punc_res
-                if hasattr(self.model, "internal_punc"):
-                    punc_res = [{
-                        "text": result["text"],
-                        "punc_array": result.get("punc_array", []),
-                        "timestamp": result.get("timestamp", [])
-                    }]
-                elif self.punc_model is not None:
-                    punc_res = self.inference(
-                        result["text"], 
-                        model=self.punc_model, 
-                        kwargs=self.punc_kwargs, 
-                        **cfg
-                    )
-                else:
-                    # 濡傛灉鍙湁鏃堕棿鎴筹紝鍒涘缓涓�涓熀鏈殑 punc_res
-                    punc_res = [{
-                        "text": result["text"],
-                        "punc_array": [],  # 绌虹殑鏍囩偣鏁扮粍
-                        "timestamp": result["timestamp"]
-                    }]
+                if raw_text is None:
+                    logging.error("Missing punc_model, which is required by spk_model.")
                 all_segments = sorted(all_segments, key=lambda x: x[0])
                 spk_embedding = result["spk_embedding"]
                 labels = self.cb_model(

--
Gitblit v1.9.1