Merge 1b8059cf610c1e89bd7798cab721145ea1fc50a6 into 9bbd80ab33fa5085065164f8378e14e29c3af90f

This commit is contained in:
li-lizhe 2026-10-07 21:00:44 +08:00 committed by GitHub
commit dc81a6b9bf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -27,7 +27,15 @@ logging.config.dictConfig(uvicorn.config.LOGGING_CONFIG)
logger = logging.getLogger("uvicorn")
is_half = True
device = "cuda" if torch.cuda.is_available() else "cpu"
# Detect the current accelerator (CUDA, NPU, XPU, MPS, …) in a device-agnostic way.
# Using torch.accelerator (available since PyTorch 2.5) ensures the script works
# out of the box on Ascend NPU, Intel XPU, Apple MPS, etc. without hard-coding
# "cuda". Falls back to the traditional CUDA-or-CPU heuristic when torch.accelerator
# is not available (PyTorch < 2.5).
if hasattr(torch, "accelerator") and torch.accelerator.is_available():
device = str(torch.accelerator.current_accelerator())
else:
device = "cuda" if torch.cuda.is_available() else "cpu"
now_dir = os.getcwd()