Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion funasr/auto/auto_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
from funasr.train_utils.load_pretrained_model import load_pretrained_model
from funasr.utils import export_utils
from funasr.utils import misc

def is_npu_available():
"""检查NPU是否可用。"""
try:
import torch_npu
return torch_npu.npu.is_available()
except ImportError:
return False

def _resolve_ncpu(config, fallback=4):
"""Return a positive integer representing CPU threads from config."""
Expand Down Expand Up @@ -199,6 +205,7 @@ def build_model(**kwargs):
if ((device =="cuda" and not torch.cuda.is_available())
or (device == "xpu" and not torch.xpu.is_available())
or (device == "mps" and not torch.backends.mps.is_available())
or (device == "npu" and not is_npu_available())
or kwargs.get("ngpu", 1) == 0):
device = "cpu"
kwargs["batch_size"] = 1
Expand Down