From 6840a7bbb2e6f3c5b00967f02d908648f9bd72fb Mon Sep 17 00:00:00 2001 From: JieXin Liang Date: Fri, 4 Jul 2025 02:49:32 +0800 Subject: [PATCH] [fix] put cpu in the first priority in get_device() (#7752) --- python/sglang/srt/utils.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index fdce18333..996a2f3b5 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -1443,6 +1443,15 @@ def is_habana_available() -> bool: @lru_cache(maxsize=8) def get_device(device_id: Optional[int] = None) -> str: + if is_cpu(): + if cpu_has_amx_support(): + logger.info("Intel AMX is detected, using CPU with Intel AMX support.") + else: + logger.warning( + "CPU device enabled, using torch native backend, low performance expected." + ) + return "cpu" + if hasattr(torch, "cuda") and torch.cuda.is_available(): if device_id is None: return "cuda" @@ -1471,15 +1480,6 @@ def get_device(device_id: Optional[int] = None) -> str: "Habana frameworks detected, but failed to import 'habana_frameworks.torch.hpu'." ) - if is_cpu(): - if cpu_has_amx_support(): - logger.info("Intel AMX is detected, using CPU with Intel AMX support.") - else: - logger.warning( - "CPU device enabled, using torch native backend, low performance expected." - ) - return "cpu" - raise RuntimeError("No accelerator (CUDA, XPU, HPU) is available.")