[diffusion] refactor: centralize hardware platform detection and streamline environment variable management (#15842)

This commit is contained in:
Mick
2025-12-26 22:16:18 +08:00
committed by GitHub
parent cf34d0ab32
commit 8dc6f0fc4d
12 changed files with 260 additions and 365 deletions

View File

@@ -1,6 +1,5 @@
# Copied and adapted from: https://github.com/hao-ai-lab/FastVideo
import importlib
import ipaddress
import logging
import os
@@ -241,48 +240,6 @@ def get_zmq_socket(
# https://pytorch.org/docs/stable/notes/hip.html#checking-for-hip
@lru_cache(maxsize=1)
def is_hip() -> bool:
return torch.version.hip is not None
@lru_cache(maxsize=1)
def is_cuda():
return torch.cuda.is_available() and torch.version.cuda
@lru_cache(maxsize=1)
def is_cuda_alike():
return is_cuda() or is_hip()
@lru_cache(maxsize=1)
def is_blackwell():
if not is_cuda():
return False
return torch.cuda.get_device_capability()[0] == 10
@lru_cache(maxsize=1)
def is_sm120():
if not is_cuda():
return False
return torch.cuda.get_device_capability()[0] == 12
@lru_cache(maxsize=1)
def is_hpu() -> bool:
return hasattr(torch, "hpu") and torch.hpu.is_available()
@lru_cache(maxsize=1)
def is_xpu() -> bool:
return hasattr(torch, "xpu") and torch.xpu.is_available()
@lru_cache(maxsize=1)
def is_npu() -> bool:
return hasattr(torch, "npu") and torch.npu.is_available()
@lru_cache(maxsize=1)
@@ -295,11 +252,6 @@ def is_host_cpu_x86() -> bool:
)
@lru_cache(maxsize=1)
def is_cpu() -> bool:
return os.getenv("SGLANG_USE_CPU_ENGINE", "0") == "1" and is_host_cpu_x86()
# cuda
@@ -309,16 +261,6 @@ def set_cuda_arch():
os.environ["TORCH_CUDA_ARCH_LIST"] = f"{arch}{'+PTX' if arch == '9.0' else ''}"
def is_flashinfer_available():
"""
Check whether flashinfer is available.
As of Oct. 6, 2024, it is only available on NVIDIA GPUs.
"""
# if not get_bool_env_var("SGLANG_IS_FLASHINFER_AVAILABLE", default="true"):
# return False
return importlib.util.find_spec("flashinfer") is not None and is_cuda()
# env var managements
_warned_bool_env_var_keys = set()

View File

@@ -21,6 +21,7 @@ def broadcast_pyobj(
The `rank` here refer to the source rank on global process group (regardless
of dist_group argument).
"""
device = torch.device(
current_platform.device_type if not force_cpu_device else "cpu"
)

View File

@@ -18,8 +18,6 @@ from typing import Any, cast
import sglang.multimodal_gen.envs as envs
SGLANG_DIFFUSION_CONFIGURE_LOGGING = envs.SGLANG_DIFFUSION_CONFIGURE_LOGGING
SGLANG_DIFFUSION_LOGGING_CONFIG_PATH = envs.SGLANG_DIFFUSION_LOGGING_CONFIG_PATH
SGLANG_DIFFUSION_LOGGING_LEVEL = envs.SGLANG_DIFFUSION_LOGGING_LEVEL
SGLANG_DIFFUSION_LOGGING_PREFIX = envs.SGLANG_DIFFUSION_LOGGING_PREFIX