mirror of
https://github.com/mudler/LocalAI.git
synced 2026-09-13 14:56:11 -04:00
The Intel backend installs PyTorch XPU wheels, but Qwen ASR only checked CUDA and MPS. Every Intel model therefore loaded on the CPU. Select XPU when available and place the model on xpu:0. Keep the existing CUDA, MPS, and CPU placement behavior. Assisted-by: Codex:GPT-5 [apply_patch] [gh] Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
19 lines
520 B
Python
19 lines
520 B
Python
def select_device(torch_module):
|
|
mps = getattr(getattr(torch_module, "backends", None), "mps", None)
|
|
if mps is not None and mps.is_available():
|
|
return "mps"
|
|
if torch_module.cuda.is_available():
|
|
return "cuda"
|
|
xpu = getattr(torch_module, "xpu", None)
|
|
if xpu is not None and xpu.is_available():
|
|
return "xpu"
|
|
return "cpu"
|
|
|
|
|
|
def device_map_for(device):
|
|
if device == "mps":
|
|
return None
|
|
if device in ("cuda", "xpu"):
|
|
return f"{device}:0"
|
|
return "cpu"
|