From e7759778e59520ca46dfcac56d82d6b723ef1ee5 Mon Sep 17 00:00:00 2001 From: JieXin Liang Date: Sun, 8 Jun 2025 06:13:45 +0800 Subject: [PATCH] [misc] add is_cpu() (#6950) --- python/sglang/srt/utils.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/python/sglang/srt/utils.py b/python/sglang/srt/utils.py index 26fb8d438..32c9f865a 100644 --- a/python/sglang/srt/utils.py +++ b/python/sglang/srt/utils.py @@ -25,6 +25,7 @@ import json import logging import os import pickle +import platform import random import re import resource @@ -158,6 +159,15 @@ def is_npu() -> bool: return hasattr(torch, "npu") and torch.npu.is_available() +def is_cpu() -> bool: + machine = platform.machine().lower() + return ( + machine in ("x86_64", "amd64", "i386", "i686") + and hasattr(torch, "cpu") + and torch.cpu.is_available() + ) + + def is_flashinfer_available(): """ Check whether flashinfer is available.