Merge 1b8059cf610c1e89bd7798cab721145ea1fc50a6 into 48b1a0169a28582a8984402f82cf438d3bfa6aca

This commit is contained in:
li-lizhe 2026-09-04 10:56:31 +08:00 committed by GitHub
commit 1e150aef3c
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()