fix(tts-engines): select device via torch.accelerator in confucius4 and dots_tts

Both Confucius4 and DOTS-TTS engine sidecars hardcode device selection to
`torch.cuda.is_available()`, which returns False on Ascend NPU, Intel XPU,
and other non-CUDA accelerators — causing the models to silently run on CPU
(in fp32) instead of the available accelerator.

Replace with `torch.accelerator.current_accelerator().type`, the
device-agnostic API that auto-detects CUDA, NPU, XPU, MPS, and CPU. MPS is
excluded for Confucius4 (upstream untested on Apple Silicon). dtype stays
bf16 for any GPU-class accelerator and fp32 on CPU.

Also verified on Ascend 910B (torch 2.14, torch_npu, 4 NPU):
  before: cuda_available=False → device "cpu", precision "float32"
  after:  accelerator → confucius4 device="npu", dots_tts precision="bfloat16"
This commit is contained in:
li-lizhe
2026-09-06 09:24:39 +08:00
parent 53ff367c1f
commit ed6fca46a9
2 changed files with 4 additions and 2 deletions
+3 -1
View File
@@ -115,7 +115,9 @@ def _load_model(stdout):
import torch
from confuciustts.cli.inference import ConfuciusTTS # type: ignore[import-not-found]
device = "cuda" if torch.cuda.is_available() else "cpu"
device = torch.accelerator.current_accelerator().type # 'cuda', 'npu', 'mps', 'xpu', 'cpu'
if device == "mps":
device = "cpu" # ConfuciusTTS is untested on MPS; fall back to CPU for safety
_send(stdout, {"op": "progress", "stage": "loading_model", "percent": 50})
_model = ConfuciusTTS(config_path=_config_path(), device=device)
+1 -1
View File
@@ -115,7 +115,7 @@ def _load_runtime(stdout):
from dots_tts.runtime import DotsTtsRuntime # type: ignore[import-not-found]
repo = os.environ.get("OMNIVOICE_DOTS_TTS_MODEL", _DEFAULT_REPO)
default_precision = "bfloat16" if torch.cuda.is_available() else "float32"
default_precision = "bfloat16" if torch.accelerator.current_accelerator().type != "cpu" else "float32"
precision = os.environ.get("OMNIVOICE_DOTS_TTS_PRECISION", default_precision)
optimize = os.environ.get("OMNIVOICE_DOTS_TTS_OPTIMIZE", "0") == "1"