[Config] Round 5.1: the published-side readers ask the bags, and a platform fact gets one address (#37086)

This commit is contained in:
Cheng Wan
2026-08-30 02:18:33 -07:00
committed by GitHub
parent a6e4021368
commit 7e751153eb
148 changed files with 1585 additions and 1114 deletions
+12 -18
View File
@@ -20,6 +20,7 @@ from sglang.srt.arg_groups.overrides import (
_intel_xpu_page_constraint,
_mla_backend_page_constraints,
_mla_kv_cache_dtype_checks,
attention_backends_of,
declare_resolution,
mamba_extra_buffer_of,
model_config_of,
@@ -31,13 +32,8 @@ from sglang.srt.arg_groups.overrides import (
from sglang.srt.connector import ConnectorType
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import (
is_cuda,
is_hip,
is_sm90_supported,
is_sm100_or_sm110_supported,
is_sm100_supported,
is_sm120_supported,
parse_connector_type,
)
@@ -45,7 +41,6 @@ logger = logging.getLogger(__name__)
def handle_attention_backend_compatibility(server_args: Any):
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
model_config = model_config_of(server_args)
@@ -136,7 +131,7 @@ def handle_attention_backend_compatibility(server_args: Any):
prefill_backend, decode_backend = attention_backends_of(resolved_view(server_args))
if "trtllm_mha" in (prefill_backend, decode_backend):
if prefill_backend == "trtllm_mha" and not (
is_sm90_supported() or is_sm100_supported() or is_sm120_supported()
get_platform().is_sm90 or get_platform().is_sm100 or get_platform().is_sm120
):
raise ValueError(
"TRTLLM MHA backend for prefill requires Hopper (SM90), Blackwell (SM100), or SM120 GPUs. "
@@ -144,7 +139,7 @@ def handle_attention_backend_compatibility(server_args: Any):
)
if (
prefill_backend == "trtllm_mha"
and is_sm120_supported()
and get_platform().is_sm120
and (
cfg.kv_cache_dtype == "fp8_e4m3"
or (
@@ -158,14 +153,14 @@ def handle_attention_backend_compatibility(server_args: Any):
"fp8_e4m3 KV cache or skip-softmax."
)
if decode_backend == "trtllm_mha" and not (
is_sm90_supported() or is_sm100_supported() or is_sm120_supported()
get_platform().is_sm90 or get_platform().is_sm100 or get_platform().is_sm120
):
raise ValueError(
"TRTLLM MHA backend for decode is only supported on Hopper (SM90), Blackwell (SM100) and (SM120) GPUs. Please use a different decode backend."
)
if (
prefill_backend == "trtllm_mha"
and not is_sm100_supported()
and not get_platform().is_sm100
and (cfg.enable_prefill_context_parallel or cfg.attn_cp_size > 1)
):
raise ValueError(
@@ -227,7 +222,7 @@ def handle_linear_attn_backend(server_args: Any):
if (
cfg.linear_attn_decode_backend is None
and cfg.linear_attn_backend != "helion"
and is_sm100_supported()
and get_platform().is_sm100
and cfg.mamba_ssm_dtype == "bfloat16"
# Stage 4: flashinfer's recurrent_kda compiles the state slot stride
# as a free int64, so it reads the page-major/unified envelope-strided
@@ -273,7 +268,7 @@ def handle_linear_attn_backend(server_args: Any):
if (
decode == "flashinfer"
and cfg.mamba_ssm_dtype != "bfloat16"
and is_cuda()
and get_platform().is_cuda
and torch.cuda.get_device_capability()[0] >= 10
):
raise ValueError(
@@ -288,7 +283,7 @@ def handle_linear_attn_backend(server_args: Any):
if (
verify == "flashinfer"
and cfg.mamba_ssm_dtype != "bfloat16"
and is_cuda()
and get_platform().is_cuda
and torch.cuda.get_device_capability()[0] >= 10
):
raise ValueError(
@@ -304,7 +299,7 @@ def handle_linear_attn_backend(server_args: Any):
cuda_major = int(cuda_version.split(".")[0]) if cuda_version is not None else 0
if (
prefill == "flashinfer"
and is_cuda()
and get_platform().is_cuda
and torch.cuda.get_device_capability()[0] >= 10
and cuda_major < 13
):
@@ -454,7 +449,6 @@ def handle_multi_item_scoring(server_args: Any):
changing it silently could surprise users who intentionally picked
a non-flashinfer backend.
"""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
if not cfg.enable_mis:
@@ -568,7 +562,7 @@ def handle_deterministic_inference(server_args: Any):
raise ValueError(
f"Currently only {RADIX_SUPPORTED_DETERMINISTIC_ATTENTION_BACKEND} attention backends are supported for deterministic inference with absorbed-MLA models. But you're using {attention_backend}."
)
if attention_backend == "fa4" and not is_sm100_or_sm110_supported():
if attention_backend == "fa4" and not get_platform().is_sm100_or_sm110:
raise ValueError(
"Deterministic inference with absorbed-MLA models on the fa4 "
"attention backend requires SM100/SM110: it runs "
@@ -589,7 +583,7 @@ def handle_deterministic_inference(server_args: Any):
# Check TP size
if cfg.tp_size > 1:
if is_hip():
if get_platform().is_hip:
# AMD: use 1-stage all-reduce kernel which is inherently deterministic
# (each GPU reads all data from all GPUs, reduces locally in fixed order)
logger.info("AMD/ROCm: Using 1-stage all-reduce kernel (deterministic)")
@@ -7,6 +7,7 @@ import logging
from typing import Any
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
declare_resolution,
model_config_of,
resolved_view,
@@ -22,12 +23,10 @@ from sglang.srt.model_executor.cuda_graph_config import (
with_phase,
)
from sglang.srt.platforms import current_platform
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import (
is_cpu,
is_hip,
is_mps,
is_npu,
is_xpu,
parse_connector_type,
)
from sglang.srt.utils.hf_transformers_utils import check_gguf_file
@@ -111,7 +110,6 @@ def apply_cuda_graph_compatibility(server_args: Any):
prefill backend (this folds in the old
--enforce-piecewise-cuda-graph contract).
"""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
if (Phase.PREFILL, "backend") in server_args._cuda_graph_config_locked:
@@ -167,7 +165,11 @@ def disable_tc_piecewise_cudagraph_if_incompatible(server_args: Any):
("pipeline parallelism (pp_size > 1)", lambda: cfg.pp_size > 1),
(
"non-CUDA hardware (HIP/NPU/CPU/MPS/XPU)",
lambda: is_hip() or is_npu() or is_cpu() or is_mps() or is_xpu(),
lambda: get_platform().is_hip
or get_platform().is_npu
or is_cpu()
or is_mps()
or get_platform().is_xpu,
),
(
"OOT platform without piecewise support",
@@ -330,7 +332,6 @@ def disable_prefill_cuda_graph_for_deepseek_trtllm_mla(server_args: Any):
breakable) trtllm_mla falls back to FlashAttention for prefill and regresses
performance, so disable whichever prefill graph backend is in effect.
"""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
@@ -10,6 +10,7 @@ from sglang.srt.arg_groups.overrides import (
run_post_process_pass,
)
from sglang.srt.environ import envs
from sglang.srt.runtime_context import get_platform
if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
@@ -114,14 +115,13 @@ def apply_deepseek_v4_defaults(server_args: ServerArgs, model_arch: str) -> None
that field) and the validations.
"""
cfg = resolving_view(server_args)
from sglang.srt.utils import is_hip
# FlashMLA sparse prefill (SGLANG_OPT_FLASHMLA_SPARSE_PREFILL, default on)
# currently returns incorrect output for DeepSeek-V4-Flash on ROCm/HIP
# (MI355X), which breaks the disaggregation nightly. Keep the previous
# (dense prefill) behavior on ROCm until the sparse kernel is validated
# there;
if is_hip():
if get_platform().is_hip:
logger.warning(
"Disabling SGLANG_OPT_FLASHMLA_SPARSE_PREFILL by default on ROCm/HIP "
f"for {model_arch}; set it explicitly to override."
+2 -2
View File
@@ -15,7 +15,7 @@ from sglang.srt.arg_groups.overrides import (
run_post_process_pass,
)
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.utils.common import is_hip
from sglang.srt.runtime_context import get_platform
logger = logging.getLogger(__name__)
@@ -27,7 +27,7 @@ def handle_dllm_inference(server_args: Any):
# On AMD/HIP, disable cuda graph for DLLM (the attention_backend
# resolution moved to the pipeline: arg_groups/overrides.py
# _dllm_attention_backend, invoked below at its legacy slot).
if is_hip():
if get_platform().is_hip:
if (
cfg.cuda_graph_config.decode.backend != Backend.DISABLED
or cfg.cuda_graph_config.prefill.backend != Backend.DISABLED
+4 -10
View File
@@ -8,6 +8,7 @@ from sglang.srt.arg_groups.overrides import (
resolved_view,
resolving_view,
)
from sglang.srt.runtime_context import get_platform
if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
@@ -22,21 +23,14 @@ HISPARSE_ROCM_DSA_BACKENDS = {"tilelang", "aiter"}
HISPARSE_KV_CACHE_DTYPES = ("bfloat16", "fp8_e4m3")
def _is_hip() -> bool:
"""The one place this family asks about ROCm, and the seam the tests patch."""
from sglang.srt.utils.common import is_hip
return is_hip()
def _hisparse_default_backend(kv_cache_dtype: str) -> str:
if _is_hip():
if get_platform().is_hip:
return "tilelang"
return "flashmla_kv" if kv_cache_dtype == "fp8_e4m3" else "flashmla_sparse"
def _hisparse_allowed_backends(kv_cache_dtype: str) -> set[str]:
if _is_hip():
if get_platform().is_hip:
return HISPARSE_ROCM_DSA_BACKENDS
return HISPARSE_CUDA_DSA_BACKENDS_BY_DTYPE.get(
kv_cache_dtype, {"flashmla_sparse", "flashmla_kv", "flashinfer_sparse_mla"}
@@ -96,7 +90,7 @@ def validate_hisparse(server_args: ServerArgs) -> None:
hf_config = model_config_of(server_args).hf_config
is_v4_hisparse = is_deepseek_v4(hf_config)
is_hip = _is_hip()
is_hip = get_platform().is_hip
assert is_deepseek_dsa(hf_config) or is_v4_hisparse, (
"--enable-hisparse is only supported for DSA (DeepSeek Sparse Attention) "
"models (e.g., DeepSeek V3.2, GLM-5) and DeepSeek V4 now. "
+3 -4
View File
@@ -7,6 +7,7 @@ from sglang.srt.arg_groups.overrides import (
declare_resolution,
resolving_view,
)
from sglang.srt.runtime_context import get_platform
if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
@@ -17,7 +18,6 @@ logger = logging.getLogger(__name__)
def apply_kimi_k3_spec_backend_defaults(server_args: ServerArgs) -> None:
"""Apply speculative backend defaults for Kimi hybrid models."""
cfg = resolving_view(server_args)
from sglang.srt.utils import is_sm100_supported
if cfg.speculative_algorithm is None:
return
@@ -42,7 +42,7 @@ def apply_kimi_k3_spec_backend_defaults(server_args: ServerArgs) -> None:
if (
cfg.speculative_algorithm == "DSPARK"
and cfg.speculative_draft_attention_backend is None
and is_sm100_supported()
and get_platform().is_sm100
):
declare_resolution(
server_args,
@@ -58,7 +58,6 @@ def apply_kimi_k3_spec_backend_defaults(server_args: ServerArgs) -> None:
def apply_kimi_k3_linear_attn_defaults(server_args: ServerArgs) -> None:
"""KDA decode-fallback default for Kimi hybrid models (spec-independent)."""
cfg = resolving_view(server_args)
from sglang.srt.utils import is_sm100_supported
# Preempts the generic SM100+bf16 flashinfer switch (a GDN default): on
# KDA shapes the triton packed decode measures ~35% faster than
@@ -66,7 +65,7 @@ def apply_kimi_k3_linear_attn_defaults(server_args: ServerArgs) -> None:
if (
cfg.linear_attn_decode_backend is None
and cfg.mamba_ssm_dtype == "bfloat16"
and is_sm100_supported()
and get_platform().is_sm100
):
declare_resolution(
server_args,
+5 -13
View File
@@ -7,6 +7,7 @@ import logging
from typing import Any
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
declare_resolution,
resolved_view,
resolving_view,
@@ -14,12 +15,7 @@ from sglang.srt.arg_groups.overrides import (
)
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend
from sglang.srt.utils.common import (
is_blackwell_supported,
is_cuda,
is_sm100_supported,
is_sm120_supported,
)
from sglang.srt.runtime_context import get_platform
logger = logging.getLogger(__name__)
@@ -29,7 +25,7 @@ def handle_mxfp8_kv_cache_compatibility(server_args: Any) -> None:
cfg = resolving_view(server_args)
if cfg.kv_cache_dtype != "mxfp8":
return
if not is_blackwell_supported():
if not get_platform().is_blackwell:
raise ValueError(
"--kv-cache-dtype mxfp8 requires an SM100+ (Blackwell) GPU for the "
"block-scaled operands used by the FA4 MXFP8 attention path."
@@ -38,7 +34,6 @@ def handle_mxfp8_kv_cache_compatibility(server_args: Any) -> None:
def handle_kv4_compatibility(server_args: Any) -> None:
"""Check FP4 KV cache compatibility with the attention backend"""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
@@ -49,9 +44,9 @@ def handle_kv4_compatibility(server_args: Any) -> None:
prefill_backend, decode_backend = attention_backends_of(resolved_view(server_args))
attention_backend = resolved_view(server_args).attention_backend
if is_cuda():
if get_platform().is_cuda:
if cfg.kv_cache_dtype == "nvfp4" and not (
is_sm100_supported() or is_sm120_supported()
get_platform().is_sm100 or get_platform().is_sm120
):
raise RuntimeError(
"--kv-cache-dtype=nvfp4 requires Blackwell SM100 or SM120. "
@@ -123,7 +118,6 @@ def handle_prefill_only_disable_kv_cache(server_args: Any) -> None:
still None, backends haven't settled yet and the resolved (prefill,
decode) pair would be a stale (None, None).
"""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
@@ -199,7 +193,6 @@ def handle_cache_compatibility(server_args: Any) -> None:
def handle_unified_memory_pool(server_args: Any) -> None:
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
if not cfg.enable_unified_memory:
@@ -280,7 +273,6 @@ def handle_page_major_kv_layout(server_args: Any):
# The unified pool stores state in the page-major envelope-strided layout, so
# enabling it implies --enable-page-major-kv-layout — routing it through the
# single page-major path + stride-aware Triton asserts (set before the guard).
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
if cfg.enable_unified_memory:
+10 -14
View File
@@ -8,16 +8,9 @@ from typing import Any
from sglang.srt.arg_groups.overrides import (
resolving_view,
supports_mamba_cache_extra_buffer,
)
from sglang.srt.utils.common import (
is_cuda,
is_flashinfer_available,
is_hip,
is_musa,
is_npu,
is_sm100_supported,
is_xpu,
)
from sglang.srt.runtime_context import get_platform
logger = logging.getLogger(__name__)
@@ -41,13 +34,13 @@ def handle_mamba_backend(server_args: Any):
"Run with --mamba-ssm-dtype float16 or disable "
"--enable-mamba-cache-stochastic-rounding."
)
if not is_cuda():
if not get_platform().is_cuda:
raise ValueError(
"Stochastic rounding for the Mamba SSM cache is only "
"supported on NVIDIA CUDA platforms. Disable "
"--enable-mamba-cache-stochastic-rounding on this platform."
)
if cfg.mamba_backend == "triton" and not is_sm100_supported():
if cfg.mamba_backend == "triton" and not get_platform().is_sm100:
raise ValueError(
"Stochastic rounding for the Mamba SSM cache with "
"--mamba-backend triton requires SM100 with CUDA >= 12.8 "
@@ -67,7 +60,7 @@ def handle_mamba_backend(server_args: Any):
" Stochastic rounding with --mamba-backend flashinfer "
"requires FlashInfer Mamba and --mamba-ssm-dtype float16."
)
if is_flashinfer_available():
if get_platform().has_flashinfer:
try:
import flashinfer.mamba # noqa: F401
@@ -103,13 +96,16 @@ def handle_int8_mamba_checkpoint(server_args: Any):
def validate_mamba_extra_buffer(view, model_arch: str, *, mamba_cache_chunk_size_of):
from sglang.srt.arg_groups.overrides import supports_mamba_cache_extra_buffer
assert supports_mamba_cache_extra_buffer(
view, model_arch
), f"extra_buffer is not supported for {model_arch}; use no_buffer."
assert (
is_cuda() or is_musa() or is_npu() or is_hip() or is_xpu()
get_platform().is_cuda
or get_platform().is_musa
or get_platform().is_npu
or get_platform().is_hip
or get_platform().is_xpu
), "extra_buffer needs CUDA/MUSA/NPU/ROCm/XPU (FLA)."
if view.mamba_radix_cache_strategy == "extra_buffer_lazy":
# The PD-disagg decode pool is not wired for lazy slots.
+16 -17
View File
@@ -16,6 +16,7 @@ from sglang.srt.arg_groups.overrides import (
_hrm_text_attention_force,
_mamba_radix_cache_resolution,
_sparse_head_overlap_disable,
attention_backends_of,
collect_model_override_declarations,
declare_resolution,
mamba_cache_chunk_size,
@@ -33,16 +34,10 @@ from sglang.srt.connector import ConnectorType
from sglang.srt.environ import envs
from sglang.srt.hardware_backend.mlx.runtime import use_mlx
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import (
get_quantization_config,
is_cuda,
is_hip,
is_mps,
is_npu,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
is_xpu,
parse_connector_type,
)
@@ -50,7 +45,6 @@ logger = logging.getLogger(__name__)
def handle_model_specific_adjustments(server_args: Any):
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
from sglang.srt.configs.model_config import (
@@ -189,7 +183,9 @@ def handle_model_specific_adjustments(server_args: Any):
"shared layers would run sparse attention without indices."
)
if not is_npu() and not is_xpu(): # CUDA or ROCm GPU
if (
not get_platform().is_npu and not get_platform().is_xpu
): # CUDA or ROCm GPU
if cfg.enable_prefill_cp:
# The DSA CP field declarations moved to the override
# registry (arg_groups/overrides.py:
@@ -302,7 +298,7 @@ def handle_model_specific_adjustments(server_args: Any):
# latter awaiting the speculative-hook migration) stays below.
run_post_process_pass(server_args, _deepseek_moe_quant_resolution)
if is_hip():
if get_platform().is_hip:
if is_deepseek_dsa(hf_config):
# The fused top-k v2 kernel (topk_transform_512_v2) is a
# CUDA/Hopper-only path: its JIT source includes
@@ -336,7 +332,7 @@ def handle_model_specific_adjustments(server_args: Any):
validate_deepseek_v4_cp(server_args)
validate_deepseek_v4_mega_moe_token_budget(server_args)
if is_sm120_supported():
if get_platform().is_sm120:
# SM120 lacks tcgen05/TMEM: disable features that depend on
# DeepGEMM or require >99KB SMEM (topk_v2).
envs.SGLANG_OPT_FP8_WO_A_GEMM.set(False)
@@ -348,7 +344,7 @@ def handle_model_specific_adjustments(server_args: Any):
envs.SGLANG_FP8_PAGED_MQA_LOGITS_TORCH.set(True)
# Prefer TileLang over the Torch fallback.
envs.SGLANG_OPT_USE_TILELANG_INDEXER.set(True)
elif is_hip():
elif get_platform().is_hip:
envs.SGLANG_OPT_DEEPGEMM_HC_PRENORM.set(False)
envs.SGLANG_OPT_FP8_WO_A_GEMM.set(False)
envs.SGLANG_OPT_USE_JIT_INDEXER_METADATA.set(False)
@@ -395,7 +391,7 @@ def handle_model_specific_adjustments(server_args: Any):
if (
not resolved_view(server_args).enable_dp_attention
and cfg.nnodes == 1
and is_hip()
and get_platform().is_hip
):
# TODO (Hubert): Put this back later
# server_args.enable_aiter_allreduce_fusion = True
@@ -714,8 +710,8 @@ def handle_model_capability_adjustments(server_args: Any):
cfg.prefill_attention_backend or cfg.attention_backend
)
if (
is_cuda()
and (is_sm90_supported() or is_sm100_supported())
get_platform().is_cuda
and (get_platform().is_sm90 or get_platform().is_sm100)
and requested_prefill_backend in (None, "fa3", "fa4")
):
# Hopper/Blackwell's default FA backend can consume raw K/V
@@ -735,7 +731,10 @@ def handle_model_capability_adjustments(server_args: Any):
cfg.cuda_graph_config, Phase.DECODE, backend=Backend.DISABLED
),
)
if is_cuda() and cfg.cuda_graph_config.prefill.backend != Backend.DISABLED:
if (
get_platform().is_cuda
and cfg.cuda_graph_config.prefill.backend != Backend.DISABLED
):
declare_resolution(
server_args,
"_handle_model_capability_adjustments",
@@ -776,7 +775,7 @@ def handle_model_capability_adjustments(server_args: Any):
cfg.cuda_graph_config, Phase.PREFILL, **sizing
),
)
elif not is_cuda():
elif not get_platform().is_cuda:
# BCG is CUDA-only. Other graph backends do not support this
# encoder-style prefill, so retain the eager Triton path.
declare_resolution(
+3 -2
View File
@@ -25,7 +25,8 @@ from sglang.srt.arg_groups.overrides import (
from sglang.srt.connector import ConnectorType
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.utils.common import is_npu, parse_connector_type
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import parse_connector_type
logger = logging.getLogger(__name__)
@@ -243,7 +244,7 @@ def handle_a2a_moe(server_args: Any):
# The resolving view, not the field: `_a2a_backend_overrides` may have
# moved this already (waterfill forces `deepep`).
a2a_now = resolved_view(server_args).moe_a2a_backend
if (a2a_now == "none" and is_npu()) or a2a_now == "ascend_tp":
if (a2a_now == "none" and get_platform().is_npu) or a2a_now == "ascend_tp":
# FIXME (OrangeRedeng): for some reasons if pass "ascend_tp" accuracy drops to zero
declare_resolution(
server_args,
+104 -112
View File
@@ -46,30 +46,20 @@ from sglang.srt.environ import envs
from sglang.srt.hardware_backend.mlx.runtime import use_mlx
from sglang.srt.model_executor.cuda_graph_config import Backend
from sglang.srt.platforms import current_platform
from sglang.srt.runtime_context import (
get_context,
get_platform,
)
from sglang.srt.utils.common import (
cpu_has_amx_support,
get_device_capability,
get_device_name,
get_device_sm,
get_nvidia_driver_version,
get_quantization_config,
is_blackwell_supported,
is_cpu,
is_cuda,
is_flashinfer_available,
is_gfx95_supported,
is_hip,
is_hopper_with_cuda_12_3,
is_mnnvl_fabric_device,
is_mps,
is_musa,
is_no_spec_infer_or_topk_one,
is_npu,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
is_triton_kernels_available,
is_xpu,
xpu_has_xmx_support,
)
@@ -241,7 +231,6 @@ def run_post_process_pass(server_args: Any, fn: Callable[..., dict]) -> None:
``declare_late_resolution`` is -- post-publish changes go to the bags through
``get_context().override(...)``.
"""
from sglang.srt.runtime_context import get_context
declared = fn(ResolvedView(server_args, overlay=_declaration_overlay(server_args)))
if not isinstance(declared, dict):
@@ -280,17 +269,6 @@ def run_post_process_pass(server_args: Any, fn: Callable[..., dict]) -> None:
validate_declarations(server_args, [entry])
def _apply_fields(server_args: Any, fields: Dict[str, Any]) -> None:
"""Write fields on behalf of the pipeline (bypasses the strict bare-
assignment guard that protects post-resolution mutation)."""
object.__setattr__(server_args, "_internal_write", True)
try:
for field, value in fields.items():
setattr(server_args, field, value)
finally:
object.__setattr__(server_args, "_internal_write", False)
def declare_resolution(server_args: Any, source: str, **fields: Any) -> None:
"""Record a resolution write in the declaration stash.
@@ -331,7 +309,6 @@ def declare_late_resolution(server_args: Any, source: str, **fields: Any) -> Non
field write would desync them, which is what ``get_context().override`` is
for.
"""
from sglang.srt.runtime_context import get_context
try:
published = get_context().server_args
@@ -703,7 +680,7 @@ def _kimi_k3_overrides(server_args: Any, hf_config: Any) -> dict:
overrides["dcp_comm_backend"] = dcp_comm_backend
return overrides
if not (is_sm100_supported() and get_device_sm() in (100, 103)):
if not (get_platform().is_sm100 and get_platform().device_sm in (100, 103)):
return {}
backends_unset = is_attention_backend_not_set(cfg)
if cfg.speculative_algorithm != "DSPARK":
@@ -777,7 +754,7 @@ def _kimi_k3_moe_runner_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if cfg.moe_runner_backend != "auto":
return {}
if not (is_sm100_supported() and get_device_sm() in (100, 103, 107)):
if not (get_platform().is_sm100 and get_platform().device_sm in (100, 103, 107)):
return {}
if not _is_mxfp4_pack_quantized(hf_config):
return {}
@@ -815,7 +792,7 @@ def _deepseek_family_overrides(server_args: Any, hf_config: Any) -> dict:
if is_attention_backend_not_set(cfg):
overrides["attention_backend"] = "dsa"
logger.info("Use dsa attention backend for DeepSeek with DSA.")
if not is_npu() and not is_xpu(): # CUDA or ROCm GPU
if not get_platform().is_npu and not get_platform().is_xpu: # CUDA or ROCm GPU
if cfg.enable_prefill_cp:
logger.warning(
"Context parallel feature is still under experiment. It has only been verified on Hopper platform."
@@ -858,7 +835,7 @@ def _deepseek_family_overrides(server_args: Any, hf_config: Any) -> dict:
aiter_can_use_preshuffle_paged_mqa,
)
if is_hip() and not aiter_can_use_preshuffle_paged_mqa():
if get_platform().is_hip and not aiter_can_use_preshuffle_paged_mqa():
# Legacy ROCm DSA path: aiter's gluon paged-MQA kernel is
# unavailable (Triton<3.5 and AITER_ENABLE_AOT_GLUON_PA_MQA_LOGITS
# not set, or SGLANG_DSA_HIP_DISABLE_PRESHUFFLE=1 / SGLANG_USE_AITER=0).
@@ -873,7 +850,7 @@ def _deepseek_family_overrides(server_args: Any, hf_config: Any) -> dict:
logger.warning("Setting page size to 64 for DeepSeek DSA.")
else:
# DeepSeek V3/R1/V3.1
if is_sm100_supported():
if get_platform().is_sm100:
if (
cfg.attention_backend is None
and cfg.prefill_attention_backend is None
@@ -928,7 +905,7 @@ def _mimo_v2_overrides(server_args: Any, hf_config: Any) -> dict:
# On Blackwell "auto" falls through to the triton fused-MoE runner, ~12%
# slower at bs=1 decode. FP4 checkpoints use flashinfer_mxfp4 instead.
if (
is_sm100_supported()
get_platform().is_sm100
and cfg.moe_runner_backend == "auto"
and get_quantization_config(hf_config) == "fp8"
):
@@ -945,7 +922,7 @@ def _minimax_m2_overrides(server_args: Any, hf_config: Any) -> dict:
"Enable TF32 matmul for MiniMaxM2ForCausalLM model to improve gate gemm performance."
)
if (
is_sm100_supported()
get_platform().is_sm100
and cfg.moe_runner_backend == "auto"
and model_config_of(server_args).quantization == "modelopt_fp4"
):
@@ -973,7 +950,7 @@ def _minimax_m3_overrides(server_args: Any, hf_config: Any) -> dict:
overrides["quantization"] = quant_method
quant_resolved = quant_method
if is_hip():
if get_platform().is_hip:
if is_attention_backend_not_set(cfg):
overrides["attention_backend"] = "triton"
if cfg.moe_runner_backend == "auto" and quant_resolved == "mxfp8":
@@ -996,7 +973,7 @@ def _minimax_m3_overrides(server_args: Any, hf_config: Any) -> dict:
# accelerate the large prefill all-reduce.
if not aiter_fusion_resolved and not envs.SGLANG_M3_ALLOW_CUSTOM_AR.get():
overrides["disable_custom_all_reduce"] = True
elif is_sm100_supported():
elif get_platform().is_sm100:
if is_attention_backend_not_set(cfg):
if (
cfg.kv_cache_dtype == "fp8_e4m3"
@@ -1027,7 +1004,7 @@ def _minimax_m3_overrides(server_args: Any, hf_config: Any) -> dict:
f"{overrides.get('attention_backend', cfg.attention_backend)}, page_size={page_resolved}, "
f"moe_runner_backend={overrides.get('moe_runner_backend', cfg.moe_runner_backend)}."
)
elif is_sm90_supported():
elif get_platform().is_sm90:
if is_attention_backend_not_set(cfg):
overrides["attention_backend"] = "fa3"
page_resolved = cfg.page_size
@@ -1060,7 +1037,7 @@ def _minimax_m3_overrides(server_args: Any, hf_config: Any) -> dict:
elif (
cfg.kv_cache_dtype == "fp8_e4m3"
and overrides.get("attention_backend", cfg.attention_backend) == "trtllm_mha"
and is_sm100_supported()
and get_platform().is_sm100
):
if envs.SGLANG_DISABLE_M3_FP8_ATTN_GEMM.get():
logger.info(
@@ -1121,22 +1098,22 @@ def _gpt_oss_overrides(server_args: Any, hf_config: Any) -> dict:
overrides: Dict[str, Any] = {}
# Set attention backend for GPT-OSS
if is_attention_backend_not_set(cfg):
if is_sm100_supported():
if get_platform().is_sm100:
overrides["attention_backend"] = "trtllm_mha"
elif is_sm90_supported():
elif get_platform().is_sm90:
overrides["attention_backend"] = "fa3"
elif is_cpu() and cpu_has_amx_support():
elif is_cpu() and get_platform().has_amx:
overrides["attention_backend"] = "intel_amx"
elif is_xpu():
elif get_platform().is_xpu:
overrides["attention_backend"] = "intel_xpu"
elif is_hip():
elif get_platform().is_hip:
overrides["attention_backend"] = "aiter"
elif not (is_mps() and use_mlx()):
# Exempt MLX only -- it owns attention in its own runner. macOS
# without MLX still falls through to triton and fails fast below,
# rather than landing on torch_native (no sliding window, no sinks).
overrides["attention_backend"] = "triton"
if is_xpu():
if get_platform().is_xpu:
# Check for bf16 dtype on Intel XPU. Reads the pristine dtype request,
# which equals the legacy mid-branch read: dtype had no earlier writer
# for this arch.
@@ -1159,18 +1136,20 @@ def _gpt_oss_overrides(server_args: Any, hf_config: Any) -> dict:
overrides["dtype"] = "bfloat16"
if cfg.moe_runner_backend == "auto":
if is_sm100_supported() and is_mxfp4_quant_format:
if get_platform().is_sm100 and is_mxfp4_quant_format:
overrides["moe_runner_backend"] = "flashinfer_mxfp4"
logger.warning(
"Detected SM100 and MXFP4 quantization format for GPT-OSS model, enabling FlashInfer MXFP4 MOE kernel."
)
elif is_sm120_supported() and is_mxfp4_quant_format:
elif get_platform().is_sm120 and is_mxfp4_quant_format:
overrides["moe_runner_backend"] = "flashinfer_mxfp4"
logger.warning(
"Detected SM120 and MXFP4 quantization format for GPT-OSS model, "
"enabling FlashInfer CUTLASS MXFP4 MOE kernel."
)
elif (is_hip() and envs.SGLANG_USE_AITER.get()) and is_mxfp4_quant_format:
elif (
get_platform().is_hip and envs.SGLANG_USE_AITER.get()
) and is_mxfp4_quant_format:
overrides["moe_runner_backend"] = "auto"
logger.warning(
"Detected ROCm and MXFP4 quantization format for GPT-OSS model, enabling aiter MXFP4 MOE kernel."
@@ -1182,14 +1161,14 @@ def _gpt_oss_overrides(server_args: Any, hf_config: Any) -> dict:
## callers default to INTERLEAVE; opt this path out
## unless the user explicitly overrode it.
# envs.SGLANG_USE_AITER_MOE_GU_ITLV.set(False)
elif is_hip() and envs.SGLANG_USE_AITER.get():
elif get_platform().is_hip and envs.SGLANG_USE_AITER.get():
# For GPT-OSS bf16 on ROCm with aiter, use triton backend
# because aiter CK kernel doesn't support all GEMM dimensions
overrides["moe_runner_backend"] = "triton"
logger.warning(
"Detected ROCm with SGLANG_USE_AITER for GPT-OSS bf16 model, using triton MOE kernel."
)
elif is_musa() and envs.SGLANG_DEEPEP_BF16_DISPATCH.get():
elif get_platform().is_musa and envs.SGLANG_DEEPEP_BF16_DISPATCH.get():
overrides["moe_runner_backend"] = "deep_gemm"
logger.warning(
"Detected MUSA with SGLANG_DEEPEP_BF16_DISPATCH for bf16 model, using deep_gemm kernel."
@@ -1198,11 +1177,11 @@ def _gpt_oss_overrides(server_args: Any, hf_config: Any) -> dict:
cfg.ep_size == 1
and is_triton_kernels_available()
and cfg.quantization is None
and not (is_cpu() and cpu_has_amx_support())
and not (is_cpu() and get_platform().has_amx)
):
# The triton_kernels package segfaults on Blackwell (B200)
# with NVIDIA driver >= 595. Fall back to triton backend.
if is_blackwell_supported() and get_nvidia_driver_version() >= (595,):
if get_platform().is_blackwell and get_nvidia_driver_version() >= (595,):
overrides["moe_runner_backend"] = "triton"
logger.warning(
"Detected GPT-OSS model on Blackwell with driver >= 595, "
@@ -1225,11 +1204,11 @@ def _llama4_overrides(server_args: Any, hf_config: Any) -> dict:
overrides: Dict[str, Any] = {}
# Auto-select attention backend for Llama4 if not specified
if cfg.attention_backend is None:
if is_sm100_supported():
if get_platform().is_sm100:
backend, platform = "trtllm_mha", "sm100"
elif is_sm90_supported():
elif get_platform().is_sm90:
backend, platform = "fa3", "sm90"
elif is_hip():
elif get_platform().is_hip:
backend, platform = "aiter", "hip"
elif cfg.device == "xpu":
backend, platform = "intel_xpu", "xpu"
@@ -1239,7 +1218,7 @@ def _llama4_overrides(server_args: Any, hf_config: Any) -> dict:
f"Use {backend} as attention backend on {platform} for Llama4 model"
)
overrides["attention_backend"] = backend
if is_sm100_supported() and cfg.moe_runner_backend == "auto":
if get_platform().is_sm100 and cfg.moe_runner_backend == "auto":
if cfg.quantization in {"fp8", "modelopt_fp8"}:
overrides["moe_runner_backend"] = "flashinfer_trtllm"
logger.info(
@@ -1256,7 +1235,7 @@ def _llama4_overrides(server_args: Any, hf_config: Any) -> dict:
def _gemma4_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
overrides: Dict[str, Any] = {}
default_attention_backend = "trtllm_mha" if is_sm100_supported() else "triton"
default_attention_backend = "trtllm_mha" if get_platform().is_sm100 else "triton"
if is_attention_backend_not_set(cfg):
logger.info(
f"Use {default_attention_backend} as default attention backend for Gemma4"
@@ -1267,7 +1246,7 @@ def _gemma4_overrides(server_args: Any, hf_config: Any) -> dict:
# choose an unsupported backend later.
elif cfg.attention_backend is None:
overrides["attention_backend"] = default_attention_backend
if is_sm100_supported() and cfg.moe_runner_backend == "auto":
if get_platform().is_sm100 and cfg.moe_runner_backend == "auto":
if model_config_of(server_args).quantization == "modelopt_fp4":
overrides["quantization"] = "modelopt_fp4"
overrides["moe_runner_backend"] = "flashinfer_trtllm"
@@ -1311,7 +1290,7 @@ def _minicpm_sala_overrides(server_args: Any, hf_config: Any) -> dict:
overrides["disable_radix_cache"] = True
if envs.SGLANG_MINICPM_FORCE_DENSE.get():
dense_backends = {
"minicpm_flashattn": ("fa4" if is_blackwell_supported() else "fa3"),
"minicpm_flashattn": ("fa4" if get_platform().is_blackwell else "fa3"),
"minicpm_flashinfer": "flashinfer",
}
# Literal keys keep the written-field set statically derivable; a loop
@@ -1341,7 +1320,7 @@ def _minicpm_sala_overrides(server_args: Any, hf_config: Any) -> dict:
if is_attention_backend_not_set(cfg):
overrides["attention_backend"] = (
"minicpm_flashinfer"
if is_blackwell_supported()
if get_platform().is_blackwell
else "minicpm_flashattn"
)
return overrides
@@ -1350,7 +1329,7 @@ def _minicpm_sala_overrides(server_args: Any, hf_config: Any) -> dict:
@_register_for("MiniCPMV4_6ForConditionalGeneration")
def _minicpm_v4_6_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if is_sm100_supported() and cfg.attention_backend is None:
if get_platform().is_sm100 and cfg.attention_backend is None:
return {"attention_backend": "triton"}
return {}
@@ -1360,7 +1339,7 @@ def _minicpm_v4_6_overrides(server_args: Any, hf_config: Any) -> dict:
)
def _falcon_h1_jet_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if is_sm100_supported() and cfg.attention_backend is None:
if get_platform().is_sm100 and cfg.attention_backend is None:
return {"attention_backend": "triton"}
return {}
@@ -1371,7 +1350,7 @@ def _granite_moe_hybrid_overrides(server_args: Any, hf_config: Any) -> dict:
has_mamba = any(
layer_type == "mamba" for layer_type in getattr(hf_config, "layer_types", [])
)
if has_mamba and is_sm100_supported() and cfg.attention_backend is None:
if has_mamba and get_platform().is_sm100 and cfg.attention_backend is None:
return {"attention_backend": "flashinfer"}
return {}
@@ -1379,7 +1358,7 @@ def _granite_moe_hybrid_overrides(server_args: Any, hf_config: Any) -> dict:
@_register_for("Lfm2ForCausalLM", "Lfm2MoeForCausalLM")
def _lfm2_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if is_sm100_supported() and cfg.attention_backend is None:
if get_platform().is_sm100 and cfg.attention_backend is None:
return {"attention_backend": "flashinfer"}
return {}
@@ -1426,11 +1405,15 @@ def _deepseek_v4_overrides(server_args: Any, hf_config: Any) -> dict:
)
elif (
cfg.device == "cuda"
and not is_hip()
and not get_platform().is_hip
and cfg.moe_a2a_backend == "none"
and not envs.SGLANG_DSV4_FP4_DEQUANT.get()
and model_config.is_fp4_experts
and (is_sm90_supported() or is_sm100_supported() or is_sm120_supported())
and (
get_platform().is_sm90
or get_platform().is_sm100
or get_platform().is_sm120
)
):
overrides["moe_runner_backend"] = "flashinfer_mxfp4"
logger.info(
@@ -1481,7 +1464,7 @@ def _inkling_overrides(server_args: Any, hf_config: Any) -> dict:
# (mirrors the MiniMax-M3 SM100 fa4-default above); an explicit
# --attention-backend / --prefill/decode-attention-backend still wins.
if is_attention_backend_not_set(cfg):
inkling_attn_backend = "fa4" if is_sm100_supported() else "triton"
inkling_attn_backend = "fa4" if get_platform().is_sm100 else "triton"
overrides["attention_backend"] = inkling_attn_backend
logger.info(
f"Use {inkling_attn_backend} as the attention backend for Inkling "
@@ -1547,7 +1530,7 @@ def _nemotron_h_overrides(server_args: Any, hf_config: Any) -> dict:
elif (is_modelopt or model_config.quantization is None) and (
cfg.moe_runner_backend == "auto"
):
if is_sm100_supported() and cfg.moe_a2a_backend == "none":
if get_platform().is_sm100 and cfg.moe_a2a_backend == "none":
overrides["moe_runner_backend"] = "flashinfer_trtllm"
logger.info(
f"Use flashinfer_trtllm as MoE runner backend on sm100 for {model_arch}"
@@ -1557,8 +1540,8 @@ def _nemotron_h_overrides(server_args: Any, hf_config: Any) -> dict:
model_config.quantization in ("modelopt_fp4", "modelopt_mixed")
or quantization == "modelopt_fp4"
)
and is_cuda()
and (8, 0) <= get_device_capability() < (10, 0)
and get_platform().is_cuda
and (8, 0) <= get_platform().device_capability < (10, 0)
):
overrides["moe_runner_backend"] = "marlin"
logger.info(
@@ -1568,10 +1551,10 @@ def _nemotron_h_overrides(server_args: Any, hf_config: Any) -> dict:
else:
overrides["moe_runner_backend"] = "flashinfer_cutlass"
if is_blackwell_supported() and is_attention_backend_not_set(cfg):
if get_platform().is_blackwell and is_attention_backend_not_set(cfg):
if cfg.speculative_algorithm is not None:
speculative_algorithm = cfg.speculative_algorithm.upper()
if is_sm100_supported() and cfg.speculative_eagle_topk in (
if get_platform().is_sm100 and cfg.speculative_eagle_topk in (
None,
1,
):
@@ -1592,7 +1575,7 @@ def _nemotron_h_overrides(server_args: Any, hf_config: Any) -> dict:
and speculative_algorithm in ("EAGLE", "NEXTN", "DFLASH", "DSPARK")
):
overrides["speculative_draft_attention_backend"] = "flashinfer"
elif is_sm100_supported():
elif get_platform().is_sm100:
overrides["attention_backend"] = "trtllm_mha"
return overrides
@@ -1606,7 +1589,7 @@ def _nemotron_h_overrides(server_args: Any, hf_config: Any) -> dict:
)
def _qwen3_5_hybrid_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if not is_sm100_supported() or cfg.attention_backend is not None:
if not get_platform().is_sm100 or cfg.attention_backend is not None:
return {}
sm100_default_attn_backend = "triton"
# trtllm_mha requires speculative_eagle_topk == 1 and page_size > 1.
@@ -1647,7 +1630,11 @@ def _interns2_mobius_baseline_overrides(server_args: Any, hf_config: Any) -> dic
def _qwen3vl_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if is_hip() and envs.SGLANG_USE_AITER_UNIFIED_ATTN.get() and cfg.page_size is None:
if (
get_platform().is_hip
and envs.SGLANG_USE_AITER_UNIFIED_ATTN.get()
and cfg.page_size is None
):
logger.info(
"Setting page_size=16 for aiter unified attention on Qwen3VLForConditionalGeneration."
)
@@ -1666,7 +1653,7 @@ def _qwen3vl_overrides(server_args: Any, hf_config: Any) -> dict:
def _qwen3_moe_family_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
overrides: Dict[str, Any] = {}
if is_sm100_supported():
if get_platform().is_sm100:
quant_method = get_quantization_config(hf_config)
quantization = cfg.quantization
if (
@@ -1693,7 +1680,7 @@ def _qwen3_moe_family_overrides(server_args: Any, hf_config: Any) -> dict:
def _glm4_moe_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
overrides: Dict[str, Any] = {}
if is_sm100_supported():
if get_platform().is_sm100:
quantization_config = getattr(hf_config, "quantization_config", None)
quant_method = (
quantization_config.get("quant_method")
@@ -1734,9 +1721,9 @@ def _olmo2_overrides(server_args: Any, hf_config: Any) -> dict:
)
overrides["disable_hybrid_swa_memory"] = True
if cfg.attention_backend is None:
if is_cuda() and is_sm100_supported():
if get_platform().is_cuda and get_platform().is_sm100:
overrides["attention_backend"] = "trtllm_mha"
elif is_cuda() and get_device_sm() >= 80:
elif get_platform().is_cuda and get_platform().device_sm >= 80:
overrides["attention_backend"] = "fa3"
else:
overrides["attention_backend"] = "triton"
@@ -1751,10 +1738,10 @@ def _step3p_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
overrides: Dict[str, Any] = {}
if is_attention_backend_not_set(cfg):
if is_blackwell_supported():
if get_platform().is_blackwell:
logger.info("Auto-select fa4 attention backend for Step3p7 on Blackwell.")
overrides["attention_backend"] = "fa4"
elif is_sm90_supported():
elif get_platform().is_sm90:
logger.info("Auto-select fa3 attention backend for Step3p7 on Hopper.")
overrides["attention_backend"] = "fa3"
if cfg.speculative_algorithm == "EAGLE":
@@ -1904,7 +1891,7 @@ def _dsa_kv_cache_dtype_default(view: Any) -> dict:
return {}
if not is_deepseek_dsa(hf_config):
return {}
if is_npu() or is_xpu():
if get_platform().is_npu or get_platform().is_xpu:
return {}
import torch
@@ -1974,7 +1961,7 @@ def _dsa_split_backend_resolution(view: Any) -> dict:
return {}
if not is_deepseek_dsa(hf_config):
return {}
if is_npu() or is_xpu():
if get_platform().is_npu or get_platform().is_xpu:
return {}
import torch
@@ -1989,7 +1976,7 @@ def _dsa_split_backend_resolution(view: Any) -> dict:
model_arch == "GlmMoeDsaForCausalLM"
and major == 12
and kv_cache_dtype == "fp8_e4m3"
and not is_hip()
and not get_platform().is_hip
)
if is_glm_sm12_fp8:
@@ -2020,7 +2007,7 @@ def _dsa_split_backend_resolution(view: Any) -> dict:
)
return declared
if not user_set_prefill and not user_set_decode and is_hip():
if not user_set_prefill and not user_set_decode and get_platform().is_hip:
declared["dsa_prefill_backend"] = "tilelang"
declared["dsa_decode_backend"] = "tilelang"
elif kv_cache_dtype == "fp8_e4m3":
@@ -2039,7 +2026,9 @@ def _dsa_split_backend_resolution(view: Any) -> dict:
prefill = declared.get("dsa_prefill_backend", view.dsa_prefill_backend)
decode = declared.get("dsa_decode_backend", view.dsa_decode_backend)
_check_tilelang_dsa_fp8_kv(kv_cache_dtype, prefill, decode, hip=is_hip())
_check_tilelang_dsa_fp8_kv(
kv_cache_dtype, prefill, decode, hip=get_platform().is_hip
)
logger.warning(
f"Set DSA backends for {kv_cache_dtype} KV Cache: "
f"prefill={prefill}, decode={decode}."
@@ -2074,7 +2063,7 @@ def _deepseek_moe_quant_resolution(view: Any) -> dict:
if model_arch not in _DEEPSEEK_FAMILY_ARCHS:
return {}
overrides: Dict[str, Any] = {}
if is_sm100_supported():
if get_platform().is_sm100:
quant_method = get_quantization_config(hf_config)
quant_cfg = getattr(hf_config, "quantization_config", None) or {}
config_groups = quant_cfg.get("config_groups", {})
@@ -2160,7 +2149,7 @@ def _deepseek_spec_moe_resolution(view: Any) -> dict:
model_arch = hf_config.architectures[0]
if model_arch not in _DEEPSEEK_FAMILY_ARCHS:
return {}
if not is_hip():
if not get_platform().is_hip:
return {}
if not (
view.quantization == "modelopt_fp4"
@@ -2225,7 +2214,7 @@ def _deepseek_v4_kv_cache_dtype(view: Any) -> dict:
@_register_for("MuseGlimmerForConditionalGeneration", "MuseGlimmerForCausalLM")
def _muse_glimmer_fp4_gemm_runner_overrides(server_args: Any, hf_config: Any) -> dict:
cfg = resolving_view(server_args)
if is_sm120_supported() and cfg.fp4_gemm_runner_backend == "auto":
if get_platform().is_sm120 and cfg.fp4_gemm_runner_backend == "auto":
logger.info("Use marlin as FP4 GEMM runner backend on SM120 for Muse Glimmer")
return {"fp4_gemm_runner_backend": "marlin"}
return {}
@@ -2293,10 +2282,10 @@ def _flashinfer_allreduce_fusion_auto_enable(view: Any) -> dict:
if (
view.flashinfer_allreduce_fusion_backend is None
and model_arch in _FLASHINFER_ALLREDUCE_FUSION_ARCHS
and (is_sm90_supported() or is_sm100_supported())
and (get_platform().is_sm90 or get_platform().is_sm100)
and view.tp_size > 1
and not view.enable_dp_attention
and (view.nnodes == 1 or is_sm100_supported())
and (view.nnodes == 1 or get_platform().is_sm100)
and view.moe_a2a_backend == "none"
):
logger.info(
@@ -2324,7 +2313,7 @@ def _sampling_backend_default(view: Any) -> dict:
if view.sampling_backend is None:
return {
"sampling_backend": (
"flashinfer" if is_flashinfer_available() else "pytorch"
"flashinfer" if get_platform().has_flashinfer else "pytorch"
)
}
return {}
@@ -2384,7 +2373,7 @@ def _deterministic_attention_backend(view: Any) -> dict:
if view.attention_backend is None:
# User didn't specify attention backend, fallback based on GPU architecture
if is_sm100_supported() or is_sm120_supported():
if get_platform().is_sm100 or get_platform().is_sm120:
# Blackwell and newer architectures
if _deterministic_is_deepseek_model(view):
# fallback to triton for DeepSeek models because flashinfer
@@ -2517,7 +2506,7 @@ def _mla_kv_cache_dtype_checks(view: Any) -> dict:
view.attention_backend == "trtllm_mla"
or view.decode_attention_backend == "trtllm_mla"
):
if not is_blackwell_supported():
if not get_platform().is_blackwell:
raise ValueError(
"TRTLLM MLA backend is only supported on Blackwell GPUs (SM100/SM12x). Please use a different backend."
)
@@ -2529,7 +2518,7 @@ def _mla_kv_cache_dtype_checks(view: Any) -> dict:
view.attention_backend == "tokenspeed_mla"
or view.decode_attention_backend == "tokenspeed_mla"
):
if not is_blackwell_supported():
if not get_platform().is_blackwell:
raise ValueError(
"tokenspeed_mla backend is only supported on Blackwell GPUs (SM100/SM12x)."
)
@@ -2567,7 +2556,7 @@ def _cutedsl_prefill_backend_fill(view: Any) -> dict:
assert (
view.prefill_attention_backend != "cutedsl_mla"
), "CuteDSL MLA only supports decoding for now"
if not is_sm100_supported():
if not get_platform().is_sm100:
raise ValueError(
"CuteDSL MLA backend is only supported on Blackwell GPUs (SM100). Please use a different backend."
)
@@ -2605,7 +2594,7 @@ def _fa4_page_constraint(view: Any) -> dict:
or view.prefill_attention_backend == "fa4"
)
and not use_mla_backend(view)
and is_sm100_supported()
and get_platform().is_sm100
# EAGLE topk>1 spec runs the two-pass page-tree cascade, which the FA4
# CUTLASS kernel aborts on at page_size>1. That path only works at
# page_size==1, so skip the 128 auto-force for it and keep the default.
@@ -2623,7 +2612,7 @@ def _attention_backend_platform_fallbacks(view: Any) -> dict:
if (
view.attention_backend == "intel_amx"
and view.device == "cpu"
and not cpu_has_amx_support()
and not get_platform().has_amx
):
logger.warning(
"The current platform does not support Intel AMX, will fallback to torch_native backend."
@@ -2688,13 +2677,16 @@ def _page_size_default(view: Any) -> dict:
# ROCm AITER backend, so the auto-bump is gated on HIP; on other
# platforms the SHUFFLE 5D pool has no consumer kernels and the
# env var is silently ignored (see MHATokenToKVPool).
if is_hip() and envs.SGLANG_AITER_KV_CACHE_LAYOUT.get().lower() == "vectorized_5d":
if (
get_platform().is_hip
and envs.SGLANG_AITER_KV_CACHE_LAYOUT.get().lower() == "vectorized_5d"
):
logger.info(
"Setting page_size=64 as default for "
"SGLANG_AITER_KV_CACHE_LAYOUT=vectorized_5d."
)
return {"page_size": 64}
if not is_musa():
if not get_platform().is_musa:
return {"page_size": 1}
return {"page_size": 64}
@@ -2765,7 +2757,7 @@ def _moe_runner_backend_quant_constraints(view: Any) -> dict:
field) stay in the handler."""
moe_runner_backend = view.moe_runner_backend
if view.quantization == "nvfp4_online":
if not is_sm100_supported():
if not get_platform().is_sm100:
raise ValueError(
"--quantization nvfp4_online is supported only on "
"NVIDIA Blackwell SM100/SM103 GPUs."
@@ -2788,10 +2780,10 @@ def _moe_runner_backend_quant_constraints(view: Any) -> dict:
# 128-alignment round-up off flashinfer_trtllm, so the experts would silently
# load with gate and up exchanged. Leave the backend at "auto" and let
# create_moe_runner resolve it to ASCEND.
if view.quantization == "mxfp8" and not is_npu():
if view.quantization == "mxfp8" and not get_platform().is_npu:
from sglang.srt.server_args import MXFP8_MOE_RUNNER_BACKEND_CHOICES
is_gfx95_mxfp8 = is_hip() and is_gfx95_supported()
is_gfx95_mxfp8 = get_platform().is_hip and is_gfx95_supported()
allowed = list(MXFP8_MOE_RUNNER_BACKEND_CHOICES)
if is_gfx95_mxfp8:
allowed.append("triton")
@@ -2808,7 +2800,7 @@ def _moe_runner_backend_quant_constraints(view: Any) -> dict:
if (
moe_runner_backend == "auto"
and view.quantization == "modelopt_fp4"
and is_sm120_supported()
and get_platform().is_sm120
):
moe_runner_backend = "flashinfer_cutlass"
logger.info(
@@ -2946,13 +2938,13 @@ def _gguf_quantization(view: Any) -> dict:
def _dllm_attention_backend(view: Any) -> dict:
if view.dllm_algorithm is None:
return {}
if is_hip():
if get_platform().is_hip:
if view.attention_backend not in ["triton", "aiter"]:
logger.warning(
"Attention backend is set to triton for diffusion LLM inference on AMD GPUs"
)
return {"attention_backend": "triton"}
elif is_npu():
elif get_platform().is_npu:
if view.attention_backend != "ascend":
logger.warning(
"Attention backend is overridden to 'ascend' when running on NPU for diffusion LLM inference."
@@ -3094,7 +3086,7 @@ def get_default_attn_backend(server_args: Any, use_mla_backend: bool, model_conf
if not use_mla_backend:
# MHA architecture
if is_hopper_with_cuda_12_3() and is_no_spec_infer_or_topk_one(
if get_platform().is_hopper_with_cuda_12_3 and is_no_spec_infer_or_topk_one(
resolved_view(server_args)
):
# Note: flashinfer 0.6.1 caused performance regression on Hopper attention kernel
@@ -3102,7 +3094,7 @@ def get_default_attn_backend(server_args: Any, use_mla_backend: bool, model_conf
# ref: https://github.com/sgl-project/sglang/issues/17411
return "fa3"
elif (
is_sm100_supported()
get_platform().is_sm100
and is_no_spec_infer_or_topk_one(resolved_view(server_args))
and (
cfg.speculative_algorithm is None
@@ -3114,22 +3106,22 @@ def get_default_attn_backend(server_args: Any, use_mla_backend: bool, model_conf
if model_config.has_asymmetric_kv:
return "fa4"
return "trtllm_mha"
elif is_hip():
elif get_platform().is_hip:
return "aiter"
elif is_mps():
return "torch_native"
else:
# FlashInfer does not support attention sinks.
if is_flashinfer_available() and not model_config.has_attention_sinks:
if get_platform().has_flashinfer and not model_config.has_attention_sinks:
return "flashinfer"
return "triton"
else:
# MLA architecture
if is_hopper_with_cuda_12_3():
if get_platform().is_hopper_with_cuda_12_3:
return "fa3"
elif is_sm100_supported():
elif get_platform().is_sm100:
return "flashinfer"
elif is_hip():
elif get_platform().is_hip:
head_num = model_config.get_num_kv_heads(cfg.tp_size)
# TODO current aiter only support head number 16 or 128 head number
if head_num == 128 or head_num == 16:
@@ -21,7 +21,8 @@ from sglang.srt.arg_groups.overrides import (
from sglang.srt.connector import ConnectorType
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.utils.common import is_cuda, parse_connector_type
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import parse_connector_type
logger = logging.getLogger(__name__)
@@ -139,7 +140,7 @@ def handle_dcp_validation(server_args: Any):
"requires --dcp-size / --decode-context-parallel-size > 1, but "
f"got dcp_size={cfg.dcp_size}."
)
if cfg.dcp_comm_backend == "fi_a2a" and not is_cuda():
if cfg.dcp_comm_backend == "fi_a2a" and not get_platform().is_cuda:
raise ValueError(
"--dcp-comm-backend fi_a2a delegates the exchange to FlashInfer's "
"MNNVL All-to-All kernel, which requires an NVIDIA CUDA platform "
@@ -12,7 +12,8 @@ from sglang.srt.arg_groups.overrides import (
)
from sglang.srt.hardware_backend.mlx.runtime import use_mlx
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.utils.common import is_cuda, is_hip, is_host_cpu_arm64, is_npu
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import is_host_cpu_arm64
logger = logging.getLogger(__name__)
@@ -59,7 +60,7 @@ def handle_mps_backends(server_args: Any):
def handle_amd_specifics(server_args: Any):
if is_hip():
if get_platform().is_hip:
declare_resolution(
server_args, "_handle_amd_specifics", triton_attention_num_kv_splits=16
)
@@ -68,7 +69,9 @@ def handle_amd_specifics(server_args: Any):
def handle_nccl_pre_warm(server_args: Any):
# pre_warm_nccl is only used with CUDA or HIP hardware or NPU hardware
cfg = resolving_view(server_args)
if cfg.pre_warm_nccl and not (is_cuda() or is_hip() or is_npu()):
if cfg.pre_warm_nccl and not (
get_platform().is_cuda or get_platform().is_hip or get_platform().is_npu
):
logger.warning(
"pre_warm_nccl is only applicable for CUDA or HIP hardware or NPU hardware. "
"Ignoring pre_warm_nccl setting on current hardware."
@@ -80,7 +83,7 @@ def handle_symm_mem_device_support(server_args: Any):
cfg = resolving_view(server_args)
# The symm-mem allocator compiles a CUDA plugin and links -lnccl, so off
# CUDA/HIP (e.g. Ascend NPU) it fails deep in a build step rather than here.
if cfg.enable_symm_mem and not (is_cuda() or is_hip()):
if cfg.enable_symm_mem and not (get_platform().is_cuda or get_platform().is_hip):
logger.warning(
"--enable-symm-mem is not supported on non CUDA/HIP devices "
"(NCCL symmetric memory is unavailable). Disabling symmetric memory."
+11 -14
View File
@@ -18,16 +18,11 @@ from sglang.srt.arg_groups.overrides import (
)
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import (
configure_media_url_security,
get_device,
get_device_sm,
is_cuda,
is_hip,
is_mnnvl_fabric_device,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
)
from sglang.utils import is_in_ci
@@ -409,7 +404,7 @@ def handle_environment_variables(server_args: Any):
if cfg.enable_deterministic_inference:
envs.SGLANG_FLASHINFER_MOE_FUSED_FINALIZE.set("0")
if cfg.debug_cuda_graph:
if not (is_cuda() or is_hip()):
if not (get_platform().is_cuda or get_platform().is_hip):
logger.warning(
"--debug-cuda-graph is not supported on non CUDA/HIP devices. "
"Disabling breakable CUDA graph."
@@ -424,7 +419,7 @@ def handle_environment_variables(server_args: Any):
"All operations will run eagerly through the graph capture/replay path."
)
if cfg.enable_deepseek_v4_fp4_indexer and not (
is_sm100_supported() or is_sm120_supported()
get_platform().is_sm100 or get_platform().is_sm120
):
raise ValueError(
"--enable-deepseek-v4-fp4-indexer requires SM100 or SM120 GPUs with "
@@ -434,13 +429,15 @@ def handle_environment_variables(server_args: Any):
# it, mirroring the forward scale split: the ue8m0 path
# (DEEPGEMM_SCALE_UE8M0, true sm100, default on) or an sm90 opt-in
# fp32-scale path (use FP4 expert ckpt). Disable in every other case.
if is_cuda() and envs.SGLANG_OPT_FP8_WO_A_GEMM.get():
if get_platform().is_cuda and envs.SGLANG_OPT_FP8_WO_A_GEMM.get():
from sglang.srt.layers import deep_gemm_wrapper
sm = get_device_sm()
sm = get_platform().device_sm
explicit = envs.SGLANG_OPT_FP8_WO_A_GEMM.is_set()
supported = deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0 or (
deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM and is_sm90_supported() and explicit
deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM
and get_platform().is_sm90
and explicit
)
if not supported and explicit:
logger.warning(
@@ -788,7 +785,7 @@ def handle_multimodal_feature_transport(server_args: Any):
)
elif (
model_config_of(server_args).is_multimodal
and is_cuda()
and get_platform().is_cuda
and cfg.disaggregation_mode == "null"
):
# A full GPU pool always degrades to CPU transport per tensor.
@@ -849,7 +846,7 @@ def handle_multimodal_feature_transport(server_args: Any):
requested_transport = "cpu"
if requested_transport == "cuda_vmm":
if not is_cuda():
if not get_platform().is_cuda:
raise ValueError("--mm-feature-transport=cuda_vmm requires NVIDIA CUDA.")
if cfg.pp_size != 1:
raise ValueError(
@@ -875,7 +872,7 @@ def handle_multimodal_feature_transport(server_args: Any):
)
if requested_transport == "cuda_ipc":
if not is_cuda():
if not get_platform().is_cuda:
raise ValueError("--mm-feature-transport=cuda_ipc requires NVIDIA CUDA.")
if cfg.nnodes != 1:
raise ValueError(
@@ -7,6 +7,7 @@ from typing import TYPE_CHECKING, Optional
from sglang.srt.arg_groups.overrides import (
_speculative_moe_runner_default,
attention_backends_of,
declare_direct_writes,
declare_resolution,
model_config_of,
@@ -14,6 +15,7 @@ from sglang.srt.arg_groups.overrides import (
resolving_view,
run_post_process_pass,
)
from sglang.srt.runtime_context import get_platform
if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
@@ -563,7 +565,6 @@ def _resolve_dflash_draft_attention_backend(server_args: ServerArgs) -> None:
draft modes).
"""
cfg = resolving_view(server_args)
from sglang.srt.utils import is_hip
supported_draft_backends = (
"flashinfer",
@@ -574,11 +575,10 @@ def _resolve_dflash_draft_attention_backend(server_args: ServerArgs) -> None:
"ascend",
)
# Use triton on ROCm (no FlashInfer), flashinfer on CUDA.
fallback_backend = "triton" if is_hip() else "flashinfer"
fallback_backend = "triton" if get_platform().is_hip else "flashinfer"
draft_backend = cfg.speculative_draft_attention_backend
if draft_backend is None:
from sglang.srt.arg_groups.overrides import attention_backends_of
draft_backend, _ = attention_backends_of(resolved_view(server_args))
if draft_backend is None:
@@ -660,7 +660,6 @@ def _handle_frozen_kv_mtp(server_args: ServerArgs) -> None:
def _handle_eagle_family(server_args: ServerArgs) -> None:
cfg = resolving_view(server_args)
from sglang.srt.arg_groups.overrides import attention_backends_of
if (
cfg.speculative_algorithm == "STANDALONE"
@@ -17,7 +17,8 @@ from sglang.srt.arg_groups.overrides import (
from sglang.srt.distributed.device_communicators.mooncake_transfer_engine import (
parse_ib_device_config,
)
from sglang.srt.utils.common import is_hip, is_npu, torch_release
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import torch_release
from sglang.srt.utils.runai_utils import is_runai_obj_uri
logger = logging.getLogger(__name__)
@@ -164,7 +165,9 @@ def check_server_args(server_args: Any):
), "schedule_conservativeness must be non-negative"
if cfg.model_impl == "mindspore":
assert is_npu(), "MindSpore model impl is only supported on Ascend npu."
assert (
get_platform().is_npu
), "MindSpore model impl is only supported on Ascend npu."
# Check metrics labels
if (
@@ -410,7 +413,7 @@ def check_two_batch_overlap(server_args: Any):
cfg = resolving_view(server_args)
cp_tbo = (
is_hip()
get_platform().is_hip
and cfg.enable_dsa_prefill_context_parallel
and cfg.dsa_prefill_cp_mode == "round-robin-split"
)
+4 -2
View File
@@ -8,7 +8,10 @@ from transformers import CONFIG_MAPPING
from transformers.configuration_utils import PretrainedConfig
from sglang.srt.configs.mamba_utils import BaseLinearStateParams
from sglang.srt.runtime_context import get_exec
from sglang.srt.runtime_context import (
get_exec,
get_parallel,
)
class InklingModelConfig(PretrainedConfig):
@@ -210,7 +213,6 @@ class InklingModelConfig(PretrainedConfig):
@property
def mamba2_cache_params(self) -> Optional[InklingConvCacheParams]:
from sglang.srt.runtime_context import get_parallel
try:
tp_size = get_parallel().attn_tp_size
+3 -2
View File
@@ -30,8 +30,9 @@ from sglang.srt.configs.embedding_model_spec import resolve_embedding_model_spec
from sglang.srt.configs.linear_attn_model_registry import get_linear_attn_config
from sglang.srt.environ import envs
from sglang.srt.layers.quantization import QUANTIZATION_METHODS
from sglang.srt.runtime_context import get_platform
from sglang.srt.server_args import ServerArgs
from sglang.srt.utils import is_hip, is_sm100_supported, retry
from sglang.srt.utils import is_hip, retry
from sglang.srt.utils.hf_transformers_utils import (
get_config,
get_context_length,
@@ -1656,7 +1657,7 @@ class ModelConfig:
if self.quantization not in optimized_quantization_methods:
# Don't warn for MXFP4/MXFP8 on SM100 since they have optimized kernels
if not (
self.quantization in ["mxfp4", "mxfp8"] and is_sm100_supported()
self.quantization in ["mxfp4", "mxfp8"] and get_platform().is_sm100
):
logger.warning(
"%s quantization is not fully "
+5 -4
View File
@@ -23,7 +23,11 @@ import torch.distributed as dist
import zmq
from sglang.srt.managers.io_struct import sock_recv, sock_send, wrap_as_pickle
from sglang.srt.runtime_context import get_serving
from sglang.srt.runtime_context import (
get_parallel,
get_server_args,
get_serving,
)
# -------------------------------------- config base ------------------------------------------
@@ -1722,8 +1726,6 @@ class _SGLangPlugin(_FrameworkPlugin):
info = {}
from sglang.srt.runtime_context import get_parallel
try:
parallel = get_parallel()
info["tp_rank"] = parallel.tp_rank
@@ -1793,7 +1795,6 @@ class _SGLangPlugin(_FrameworkPlugin):
return None
try:
from sglang.srt.runtime_context import get_server_args
args = get_server_args()
if args is None:
@@ -168,7 +168,7 @@ class EncoderPreprocessor:
self.image_processor = AutoImageProcessor.from_pretrained(
get_serving().tokenizer_path or get_model().model_path,
trust_remote_code=get_model().trust_remote_code,
revision=server_args.revision,
revision=get_model().revision,
**image_processor_kwargs,
)
except Exception as e:
@@ -179,7 +179,7 @@ class EncoderPreprocessor:
self.video_processor = AutoVideoProcessor.from_pretrained(
get_serving().tokenizer_path or get_model().model_path,
trust_remote_code=get_model().trust_remote_code,
revision=server_args.revision,
revision=get_model().revision,
)
except Exception as e:
logger.warning(f"Failed to load video processor: {e}")
@@ -189,7 +189,7 @@ class EncoderPreprocessor:
_audio_proc = AutoProcessor.from_pretrained(
get_serving().tokenizer_path or get_model().model_path,
trust_remote_code=get_model().trust_remote_code,
revision=server_args.revision,
revision=get_model().revision,
)
if not hasattr(_audio_proc, "feature_extractor"):
logger.warning(
@@ -1736,7 +1736,7 @@ class MMReceiverBase(ABC):
self.tp_rank = tp_rank
self.tp_size = get_parallel().tp_size
self.tp_group = tp_group
self.nnodes = server_args.nnodes
self.nnodes = get_parallel().nnodes
self.hostname = get_local_ip_auto()
self.waiting_list: List[WaitingMMRequestBase] = []
self.waiting_by_rid: Dict[str, WaitingMMRequestBase] = {}
@@ -1838,19 +1838,19 @@ class MMReceiverBase(ABC):
extra_kwargs = {}
if getattr(server_args, "tokenizer_backend", None) is not None:
extra_kwargs["tokenizer_backend"] = server_args.tokenizer_backend
extra_kwargs["tokenizer_backend"] = get_serving().tokenizer_backend
_processor = get_processor(
get_serving().tokenizer_path,
tokenizer_mode=server_args.tokenizer_mode,
tokenizer_mode=get_serving().tokenizer_mode,
trust_remote_code=get_model().trust_remote_code,
revision=server_args.revision,
revision=get_model().revision,
image_processor_backend=resolve_image_processor_backend(get_mm()),
**extra_kwargs,
)
enable_adaptive_dispatch_to_encoder = (
server_args.enable_adaptive_dispatch_to_encoder
get_disagg().enable_adaptive_dispatch_to_encoder
)
mm_processor_kwargs = {}
if model_config is not None:
@@ -63,7 +63,11 @@ from sglang.srt.observability.trace import (
TraceReqContext,
trace_set_thread_info,
)
from sglang.srt.runtime_context import get_memory, get_schedule
from sglang.srt.runtime_context import (
get_memory,
get_observability,
get_schedule,
)
from sglang.srt.server_args import ServerArgs
from sglang.srt.utils.network import NetworkAddress
@@ -213,7 +217,7 @@ class MooncakeKVManager(StagingManagerMixin, CommonKVManager):
self.init_engine()
self.register_buffer_to_engine()
self.enable_staging = envs.SGLANG_DISAGG_STAGING_BUFFER.get()
self.enable_trace = server_args.enable_trace
self.enable_trace = get_observability().enable_trace
if self.disaggregation_mode == DisaggregationMode.PREFILL:
self.start_prefill_thread()
self.session_failures = defaultdict(int)
+12 -13
View File
@@ -29,6 +29,7 @@ from sglang.srt.environ import envs
from sglang.srt.layers.dp_attention import initialize_dp_attention
from sglang.srt.platforms import current_platform
from sglang.srt.runtime_context import (
get_disagg,
get_exec,
get_parallel,
get_serving,
@@ -82,12 +83,10 @@ def init_torch_distributed(
backend = _resolve_backend(device=device, server_args=server_args)
before_avail_memory = get_available_gpu_memory(device, ps.gpu_id)
if not server_args.enable_p2p_check:
if not get_parallel().enable_p2p_check:
monkey_patch_p2p_access_check()
dist_init_method = _resolve_dist_init_method(
server_args=server_args, dist_port=dist_port
)
dist_init_method = _resolve_dist_init_method(dist_port=dist_port)
_set_all_reduce_flags(server_args=server_args)
if not is_draft_worker:
@@ -135,7 +134,7 @@ def init_torch_distributed(
_prewarm_tp_lm_head_all_to_all()
maybe_wait_for_gated_launch(
host=server_args.host, port=server_args.gated_launch_port
host=get_serving().host, port=get_parallel().gated_launch_port
)
# Draft workers reuse the target pool config and may exist on only one PP stage;
@@ -177,7 +176,7 @@ def _resolve_backend(*, device: str, server_args: ServerArgs) -> str:
return backend
def _resolve_dist_init_method(*, server_args: ServerArgs, dist_port: int) -> str:
def _resolve_dist_init_method(*, dist_port: int) -> str:
# Allow external orchestrators (e.g. trainpi) to override the distributed
# init method. When set to "env://", torch uses MASTER_ADDR/MASTER_PORT
# env-vars and an externally-created TCPStore, completely avoiding port
@@ -185,8 +184,8 @@ def _resolve_dist_init_method(*, server_args: ServerArgs, dist_port: int) -> str
dist_init_method_override = envs.SGLANG_DISTRIBUTED_INIT_METHOD_OVERRIDE.get()
if dist_init_method_override:
dist_init_method = dist_init_method_override
elif server_args.dist_init_addr:
na = NetworkAddress.parse(server_args.dist_init_addr)
elif get_parallel().dist_init_addr:
na = NetworkAddress.parse(get_parallel().dist_init_addr)
dist_init_method = na.to_tcp()
else:
dist_init_method = NetworkAddress(
@@ -240,7 +239,7 @@ def _init_parallel_groups(
) -> None:
is_ep_joiner = server_args.is_ep_joiner
is_scale_joiner = server_args.is_ep_scale_joiner
rank_offset = server_args.ep_join_rank_offset if is_scale_joiner else 0
rank_offset = get_parallel().ep_join_rank_offset if is_scale_joiner else 0
world_size = (
rank_offset + tp_size * pp_size if is_scale_joiner else tp_size * pp_size
)
@@ -252,10 +251,10 @@ def _init_parallel_groups(
rank=rank,
local_rank=gpu_id,
distributed_init_method=dist_init_method,
timeout=server_args.dist_timeout,
timeout=get_parallel().dist_timeout,
moe_a2a_backend=get_exec().moe.moe_a2a_backend,
recovered_rank=is_ep_joiner,
max_world_size=server_args.max_ep_size,
max_world_size=get_parallel().max_ep_size,
)
initialize_model_parallel(
tensor_model_parallel_size=tp_size,
@@ -265,7 +264,7 @@ def _init_parallel_groups(
attention_context_model_parallel_size=attn_cp_size,
moe_data_model_parallel_size=moe_dp_size,
decode_context_parallel_size=dcp_size,
duplicate_tp_group=server_args.enable_pdmux,
duplicate_tp_group=get_disagg().enable_pdmux,
duplicate_attn_cp_group=(
is_hip()
and server_args.enable_two_batch_overlap
@@ -274,7 +273,7 @@ def _init_parallel_groups(
enable_symm_mem=get_exec().comm.enable_symm_mem,
recovered_rank=is_ep_joiner,
rank_offset=rank_offset,
max_world_size=server_args.max_ep_size,
max_world_size=get_parallel().max_ep_size,
)
_tag_groups_for_flashinfer_allreduce_only()
initialize_dp_attention(
@@ -16,6 +16,12 @@ import torch.distributed._symmetric_memory as symm_mem
import triton
import triton.language as tl
from sglang.srt.runtime_context import (
get_parallel,
get_schedule,
get_spec,
)
logger = logging.getLogger(__name__)
# Each thread moves _NUMEL_PER_THREAD bf16 via one 128-bit multimem op; the
@@ -423,7 +429,6 @@ def recommended_max_tokens(include_prefill: bool, floor: int = 0) -> int:
NCCL. Covers the spec-decode batch plus, if ``include_prefill``, a prefill
chunk. Returns ``floor`` if server args are unavailable."""
try:
from sglang.srt.runtime_context import get_schedule, get_spec
def g(value) -> int:
return value if isinstance(value, int) and value > 0 else 0
@@ -466,7 +471,6 @@ class MultimemAllGatherer:
# Lazy import avoids a module-load dependency on the distributed facade.
from sglang.srt.distributed import get_tp_group
from sglang.srt.distributed.parallel_state import in_the_same_node_as
from sglang.srt.runtime_context import get_parallel
tp_group = get_tp_group()
# Only probe node topology when the deployment can actually span
@@ -2869,7 +2869,6 @@ def patch_tensor_parallel_group(tp_group: GroupCoordinator):
Args:
tp_group (GroupCoordinator): the tp group coordinator
"""
from sglang.srt.runtime_context import get_parallel
global _TP_STATE_PATCHED
assert not _TP_STATE_PATCHED, "Should not call when it's already patched"
+2 -2
View File
@@ -17,13 +17,14 @@ from typing import Any, Deque, Dict, Optional, Sequence, Tuple
import torch
from torch.distributed import TCPStore
from sglang.srt.runtime_context import get_resources
logger = logging.getLogger(__name__)
def set_global_tcp_store(store: TCPStore) -> None:
"""Install the shared TCPStore created during distributed initialization;
the handle lives on ``ctx.resources``."""
from sglang.srt.runtime_context import get_resources
get_resources().tcp_store = store
logger.info("Global TCPStore has been set")
@@ -39,7 +40,6 @@ def get_global_tcp_store() -> Optional[TCPStore]:
Returns:
The global TCPStore instance, or None if not initialized yet.
"""
from sglang.srt.runtime_context import get_resources
store = get_resources().tcp_store
if store is None:
+1 -1
View File
@@ -319,7 +319,7 @@ class SchedulerDllmMixin:
if running_batch.batch_is_full:
if (
not self.enable_priority_preemption
or not adder.preempt_to_schedule(req, self.server_args)
or not adder.preempt_to_schedule(req)
):
break
+1 -1
View File
@@ -49,6 +49,7 @@ import uvloop
import zmq
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
resolved_view,
resolving_view,
)
@@ -1630,7 +1631,6 @@ class Engine(EngineScoreMixin, EngineBase):
def _set_envs_and_config(server_args: ServerArgs):
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
# Set global environments
+3 -2
View File
@@ -17,6 +17,7 @@ from pydantic import ValidationError
from sglang.srt.arg_groups.overrides import resolving_view
from sglang.srt.configs.embedding_model_spec import resolved_embedding_plan
from sglang.srt.runtime_context import (
describe_kv_events_publisher,
get_lora,
get_serving,
)
@@ -425,8 +426,8 @@ class RuntimeHandle:
def get_server_info(self) -> str:
result: Dict[str, Any] = self.tokenizer_manager.server_args.resolved_dict()
result.update(self.scheduler_info)
result["kv_events"] = (
self.tokenizer_manager.server_args.describe_kv_events_publisher()
result["kv_events"] = describe_kv_events_publisher(
self.tokenizer_manager.server_args
)
return json.dumps(msgspec_to_builtins(result), default=str)
+4 -3
View File
@@ -409,7 +409,7 @@ async def lifespan(fast_api_app: FastAPI):
if server_args.sidecar is not None:
from sglang.srt.entrypoints.sidecar import start_sidecar
sidecar = start_sidecar(server_args)
sidecar = start_sidecar()
# Execute the general warmup
warmup_thread = threading.Thread(
@@ -485,6 +485,7 @@ app.include_router(v1_loads_router)
from sglang.srt.entrypoints.elastic_ep import router as elastic_ep_router
from sglang.srt.runtime_context import (
describe_kv_events_publisher,
get_disagg,
get_exec,
get_lora,
@@ -832,8 +833,8 @@ async def server_info():
"version": __version__,
# Structured KV-event publisher descriptor for KV-aware routers.
# `None` when publishing is disabled or misconfigured; see
# `ServerArgs.describe_kv_events_publisher` for the precise contract.
"kv_events": server_args.describe_kv_events_publisher(),
# `runtime_context.describe_kv_events_publisher` for the contract.
"kv_events": describe_kv_events_publisher(server_args),
}
)
+3 -3
View File
@@ -114,10 +114,10 @@ class Sidecar:
kill_process_tree(self.proc.pid, wait_timeout=self.shutdown_timeout)
def start_sidecar(server_args) -> Sidecar:
module_name = server_args.sidecar
def start_sidecar() -> Sidecar:
module_name = get_serving().sidecar
assert module_name is not None
sidecar_args, shutdown_timeout = _parse_sidecar_args(server_args.sidecar_args)
sidecar_args, shutdown_timeout = _parse_sidecar_args(get_serving().sidecar_args)
endpoint = build_sidecar_endpoint(get_serving().host, get_serving().grpc_port)
proc = mp.get_context("spawn").Process(
name=f"sglang_sidecar_{module_name}",
+2 -9
View File
@@ -28,6 +28,8 @@ import torch.nn.functional as F
from sglang.srt.runtime_context import (
get_device,
get_exec,
get_parallel,
get_resources,
)
if TYPE_CHECKING:
@@ -38,7 +40,6 @@ logger = logging.getLogger(__name__)
def _prefer_same_node_experts() -> bool:
from sglang.srt.elastic_ep.elastic_ep import elastic_expanded_world_enabled
from sglang.srt.runtime_context import get_exec
return (
get_exec().moe.ep_join_mode != "scale" and not elastic_expanded_world_enabled()
@@ -185,8 +186,6 @@ class ExpertLocationMetadata:
logical_count = logical_count.unsqueeze(0)
logical_count = logical_count.to(get_device().device)
from sglang.srt.runtime_context import get_parallel
common = ExpertLocationMetadata._init_common(model_config)
if common is None:
@@ -224,7 +223,6 @@ class ExpertLocationMetadata:
@staticmethod
def _init_common(model_config: ModelConfig):
from sglang.srt.runtime_context import get_exec, get_parallel
model_config_for_expert_location = (
ModelConfigForExpertLocation.from_model_config(model_config)
@@ -273,7 +271,6 @@ class ExpertLocationMetadata:
logical_to_all_physical_map: torch.Tensor,
moe_ep_rank: Optional[int] = None,
):
from sglang.srt.runtime_context import get_exec
_, num_physical_experts = physical_to_logical_map.shape
@@ -481,13 +478,11 @@ def _normalize_layer_ids(
def get_global_expert_location_metadata():
from sglang.srt.runtime_context import get_resources
return get_resources().expert_location_metadata
def set_global_expert_location_metadata(value, allow_overwrite=False):
from sglang.srt.runtime_context import get_resources
resources = get_resources()
if not allow_overwrite:
@@ -541,7 +536,6 @@ def _compute_logical_to_all_physical_map(
ep_size: int,
moe_ep_rank: int,
):
from sglang.srt.runtime_context import get_exec, get_parallel
# This is rarely called, so we use for loops for maximum clarity
@@ -623,7 +617,6 @@ def compute_logical_to_rank_dispatch_physical_map(
ep_rank: int,
seed: int = 42,
):
from sglang.srt.runtime_context import get_parallel
r = random.Random(seed)
+2 -3
View File
@@ -23,6 +23,8 @@ from typing import Optional
import torch
from sglang.srt.runtime_context import get_resources
logger = logging.getLogger(__name__)
# Global per-layer LPLB solvers
@@ -58,19 +60,16 @@ def assert_lplb_supported_model(architecture: str) -> None:
def get_global_lplb_solver(layer_id: int) -> Optional[LPLBSolver]:
from sglang.srt.runtime_context import get_resources
return get_resources().lplb_solvers.get(layer_id)
def set_global_lplb_solver(layer_id: int, solver: LPLBSolver):
from sglang.srt.runtime_context import get_resources
get_resources().lplb_solvers[layer_id] = solver
def clear_global_lplb_solvers():
from sglang.srt.runtime_context import get_resources
get_resources().lplb_solvers.clear()
@@ -26,7 +26,11 @@ from sglang.srt.layers.utils.cp_utils import cp_all_gather_rerange_kv_cache
from sglang.srt.mem_cache.memory_pool import KVWriteLoc
from sglang.srt.mem_cache.swa_memory_pool import SWAKVPool
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.runtime_context import get_flags, get_spec
from sglang.srt.runtime_context import (
get_flags,
get_parallel,
get_spec,
)
from sglang.srt.speculative.spec_info import SpecInput, SpecInputType
from sglang.srt.utils import (
get_bool_env_var,
@@ -42,8 +46,6 @@ import logging
import numpy as np
from sglang.srt.runtime_context import get_parallel
logger = logging.getLogger(__name__)
FULL_ATTENTION_WINDOW = 2147483647
@@ -2,7 +2,10 @@ import logging
import warnings
from typing import TYPE_CHECKING
from sglang.srt.arg_groups.overrides import resolved_view
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
resolved_view,
)
from sglang.srt.configs.hybrid_arch import (
hybrid_gdn_config,
hybrid_lightning_config,
@@ -16,6 +19,7 @@ from sglang.srt.configs.linear_attn_model_registry import (
)
from sglang.srt.runtime_context import (
get_parallel,
get_platform,
get_spec,
)
from sglang.srt.utils import get_device_capability, is_hip, is_musa, is_npu
@@ -75,7 +79,6 @@ def create_trtllm_mla_backend(runner):
if not runner.use_mla_backend:
raise ValueError("trtllm_mla backend can only be used with MLA models.")
if get_parallel().dcp_enabled and get_spec().speculative_algorithm is not None:
from sglang.srt.arg_groups.overrides import attention_backends_of
_, decode_backend = attention_backends_of(resolved_view(runner.server_args))
if decode_backend == "trtllm_mla":
@@ -394,7 +397,6 @@ def attn_backend_wrapper(runner: "ModelRunner", full_attn_backend: "AttentionBac
from sglang.srt.utils import (
is_blackwell,
is_npu,
is_sm120_supported,
is_xpu,
)
@@ -433,7 +435,7 @@ def attn_backend_wrapper(runner: "ModelRunner", full_attn_backend: "AttentionBac
hybrid_backend_cls = HybridLinearAttnBackend
if hybrid_gdn_config(runner.model_config) is not None:
if is_blackwell():
if is_sm120_supported():
if get_platform().is_sm120:
allowed = {"triton", "trtllm_mha", "flashinfer"}
else:
allowed = {"triton", "trtllm_mha", "fa4"}
@@ -71,6 +71,7 @@ from sglang.srt.mem_cache.deepseek_v4_memory_pool import DeepSeekV4TokenToKVPool
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.runtime_context import (
get_parallel,
get_platform,
get_spec,
)
from sglang.srt.speculative.eagle_utils import per_step_draft_out_cache_loc
@@ -81,8 +82,7 @@ from sglang.srt.speculative.ragged_verify import (
read_ragged_verify_mode,
resolve_ragged_verify_layout,
)
from sglang.srt.utils import ceil_align, is_cuda, is_sm90_supported, is_xpu
from sglang.srt.utils.common import is_sm120_supported
from sglang.srt.utils import ceil_align, is_cuda, is_xpu
if TYPE_CHECKING:
from sgl_kernel.flash_mla import FlashMLASchedMeta
@@ -91,7 +91,6 @@ if TYPE_CHECKING:
from sglang.srt.model_executor.model_runner import ModelRunner
from sglang.srt.speculative.ragged_verify import RaggedVerifyLayout
_is_sm120 = is_sm120_supported()
_is_cuda = is_cuda()
_is_xpu = is_xpu()
@@ -147,7 +146,7 @@ def _pad_last_dim(x: T, multiples_of: int = PAGE_INDEX_ALIGNED_SIZE) -> T:
def _create_flashmla_metadata():
if _is_sm120 or _is_xpu:
if get_platform().is_sm120 or _is_xpu:
return None
import sgl_kernel.flash_mla as flash_mla
@@ -574,7 +573,7 @@ class DeepseekV4AttnBackend(
model_runner.server_args, "dsv4_prefill_backend", "auto"
)
if use_dsv4_q8kv8_sparse_prefill(self.dsv4_prefill_backend):
if not is_sm90_supported():
if not get_platform().is_sm90:
raise ValueError(
"DeepSeek-V4 flashmla_sparse_q8 prefill requires SM90 CUDA GPUs."
)
@@ -708,7 +707,7 @@ class DeepseekV4AttnBackend(
# The SM120 FP4 kernel schedules split_kv=128, while the generic
# JIT metadata planner encodes split_kv=256.
force_deep_gemm_metadata=(
self.enable_deepseek_v4_fp4_indexer and _is_sm120
self.enable_deepseek_v4_fp4_indexer and get_platform().is_sm120
),
use_prefill_cuda_graph=use_prefill_cuda_graph,
)
@@ -1380,7 +1379,7 @@ class DeepseekV4AttnBackend(
return
assert isinstance(metadata, DSV4Metadata)
use_sparse_prefill = not _is_sm120 and (
use_sparse_prefill = not get_platform().is_sm120 and (
num_qo_tokens > _LARGE_INDEXER_QUERY_THRESHOLD
or envs.SGLANG_OPT_FLASHMLA_SPARSE_PREFILL.get()
)
@@ -1761,7 +1760,7 @@ class DeepseekV4AttnBackend(
# sparse_prefill_fwd does not support SM120.
if (
forward_batch.forward_mode.is_extend_without_speculative()
and not _is_sm120
and not get_platform().is_sm120
and (
q.shape[0] > _LARGE_INDEXER_QUERY_THRESHOLD
or envs.SGLANG_OPT_FLASHMLA_SPARSE_PREFILL.get()
@@ -1787,7 +1786,7 @@ class DeepseekV4AttnBackend(
attn_sink=attn_sink,
)
if _is_sm120:
if get_platform().is_sm120:
from sglang.kernels.ops.attention.flash_mla_sm120 import (
flash_mla_with_kvcache_sm120,
)
@@ -2,7 +2,8 @@ from __future__ import annotations
from enum import Enum
from sglang.srt.utils import is_hip, is_sm100_supported
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import is_hip
class DSAPagedMQALogitsBackend(Enum):
@@ -34,7 +35,7 @@ class DSAPagedMQALogitsBackend(Enum):
if value == "aiter":
raise ValueError("dsa_paged_mqa_logits_backend='aiter' requires ROCm.")
if value == "cutedsl":
if not is_sm100_supported():
if not get_platform().is_sm100:
raise ValueError(
"dsa_paged_mqa_logits_backend='cutedsl' requires SM100 (Blackwell)."
)
@@ -16,8 +16,10 @@ import torch
from sglang.srt.configs.model_config import get_dsa_index_topk, is_deepseek_dsa
from sglang.srt.runtime_context import (
get_buffer,
get_exec,
get_parallel,
get_platform,
get_spec,
)
@@ -73,13 +75,11 @@ from sglang.srt.layers.utils.cp_utils import (
cp_split_and_rebuild_position,
)
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.runtime_context import get_buffer
from sglang.srt.utils import (
get_bool_env_var,
is_cuda,
is_gfx95_supported,
is_hip,
is_sm100_supported,
print_warning_once,
)
@@ -670,7 +670,7 @@ class DeepseekSparseAttnBackend(
forward_mode.is_target_verify()
and next_n
and next_n >= 2
and is_sm100_supported()
and get_platform().is_sm100
):
return cache_seqlens_int32.view(-1, 1).expand(-1, next_n).contiguous()
if forward_mode.is_target_verify() or forward_mode.is_draft_extend_v2():
@@ -1497,7 +1497,7 @@ class DeepseekSparseAttnBackend(
paged_mqa_ctx_lens_2d = None
if (
self.speculative_num_draft_tokens >= 2
and is_sm100_supported()
and get_platform().is_sm100
and metadata.paged_mqa_ctx_lens_2d is not None
and metadata.paged_mqa_ctx_lens_2d.dim() == 2
and metadata.paged_mqa_ctx_lens_2d.size(0) == bs
@@ -40,10 +40,13 @@ from sglang.srt.model_executor.runner_backend_utils.breakable_cuda_graph.context
from sglang.srt.model_executor.runner_backend_utils.tc_piecewise_cuda_graph import (
is_in_tc_piecewise_cuda_graph,
)
from sglang.srt.runtime_context import get_exec, get_parallel
from sglang.srt.runtime_context import (
get_exec,
get_parallel,
get_platform,
)
from sglang.srt.state_capturer.indexer_topk import get_global_indexer_capturer
from sglang.srt.utils import add_prefix, is_cuda, is_hip, is_xpu
from sglang.srt.utils.common import is_sm120_supported
if TYPE_CHECKING:
from sglang.srt.layers.attention.base_attn_backend import AttentionBackend
@@ -714,7 +717,7 @@ class C4IndexerBackendMixin:
elif envs.SGLANG_OPT_USE_AITER_INDEXER.get():
fn = _aiter_fp8_paged_mqa_logits
elif envs.SGLANG_FP8_PAGED_MQA_LOGITS_TORCH.get():
if is_sm120_supported():
if get_platform().is_sm120:
fn = fp8_paged_mqa_logits_torch_sm120
else:
fn = fp8_paged_mqa_logits_torch
@@ -1,8 +1,10 @@
from __future__ import annotations
from sglang.srt.runtime_context import (
get_buffer,
get_exec,
get_parallel,
get_platform,
)
"""
@@ -44,7 +46,6 @@ from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMo
from sglang.srt.model_executor.runner_backend_utils.tc_piecewise_cuda_graph import (
is_in_tc_piecewise_cuda_graph,
)
from sglang.srt.runtime_context import get_buffer
from sglang.srt.speculative.spec_info import SpecInput, SpecInputType
from sglang.srt.speculative.spec_utils import (
draft_kv_indices_buffer_width,
@@ -55,7 +56,6 @@ from sglang.srt.utils import (
get_cuda_graph_max_batch_size,
get_int_env_var,
is_flashinfer_available,
is_sm100_supported,
next_power_of_2,
)
@@ -471,7 +471,7 @@ class FlashInferAttnBackend(AttentionBackend):
]
fmha_backend = "auto"
if is_sm100_supported():
if get_platform().is_sm100:
# Disable CUTLASS backend when piecewise cuda graph is enabled
# due to TMA descriptor initialization issues on SM100 GPUs.
if not check_cuda_graph_backend(Phase.PREFILL, Backend.TC_PIECEWISE):
@@ -1,9 +1,11 @@
from __future__ import annotations
from sglang.srt.runtime_context import (
get_buffer,
get_disagg,
get_exec,
get_parallel,
get_platform,
get_schedule,
)
@@ -41,7 +43,6 @@ from sglang.srt.model_executor.runner_backend_utils.breakable_cuda_graph import
from sglang.srt.model_executor.runner_backend_utils.tc_piecewise_cuda_graph import (
is_in_tc_piecewise_cuda_graph,
)
from sglang.srt.runtime_context import get_buffer
from sglang.srt.speculative.spec_info import SpecInput, SpecInputType
from sglang.srt.speculative.spec_utils import (
draft_kv_indices_buffer_width,
@@ -50,7 +51,6 @@ from sglang.srt.speculative.spec_utils import (
)
from sglang.srt.utils import (
is_flashinfer_available,
is_sm100_supported,
next_power_of_2,
)
@@ -277,7 +277,7 @@ class FlashInferMLAAttnBackend(AttentionBackend):
else:
self.q_indptr_decode = q_indptr_decode_buf
if is_sm100_supported():
if get_platform().is_sm100:
self.fmha_backend = "cutlass"
else:
self.fmha_backend = "auto"
@@ -17,8 +17,12 @@ from sglang.srt.layers.attention.minicpm.attention_adapter import (
)
from sglang.srt.layers.attention.minicpm.cache import attach_compressed_cache
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.runtime_context import get_parallel, get_schedule
from sglang.srt.utils import is_blackwell_supported, next_power_of_2
from sglang.srt.runtime_context import (
get_parallel,
get_platform,
get_schedule,
)
from sglang.srt.utils import next_power_of_2
if TYPE_CHECKING:
from sglang.srt.layers.radix_attention import RadixAttention
@@ -127,7 +131,7 @@ class MiniCPMSparseBackend(AttentionBackend):
use_flashinfer: bool,
):
super().__init__()
use_blackwell = is_blackwell_supported()
use_blackwell = get_platform().is_blackwell
if use_blackwell:
fa_impl_ver = 4
self.flash_attn_backend = FlashAttentionBackend(
@@ -21,6 +21,10 @@ from sglang.srt.layers.attention.base_attn_backend import (
)
from sglang.srt.mem_cache.memory_pool import MiniMaxSparseKVPool
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.runtime_context import (
get_parallel,
get_spec,
)
from sglang.srt.server_args import m3_fp8_attn_gemm_enabled
from sglang.srt.utils import is_npu
@@ -222,7 +226,6 @@ class MiniMaxSparseAttnBackend(AttentionBackend):
self._msa_dec_meta = None
if self.use_msa:
from sglang.srt.runtime_context import get_parallel
self.num_q_heads = (
runner.model_config.num_attention_heads // get_parallel().attn_tp_size
@@ -247,7 +250,6 @@ class MiniMaxSparseAttnBackend(AttentionBackend):
Phase,
check_cuda_graph_backend,
)
from sglang.srt.runtime_context import get_spec
spec = get_spec()
self.speculative_num_draft_tokens = spec.speculative_num_draft_tokens
@@ -56,7 +56,11 @@ from sglang.srt.layers.attention.trtllm_mla_backend import (
)
from sglang.srt.layers.dcp.layout import get_dcp_lens
from sglang.srt.layers.logits_processor import get_in_autotune_dummy_run
from sglang.srt.runtime_context import get_parallel, max_speculative_num_draft_tokens
from sglang.srt.runtime_context import (
get_parallel,
get_resources,
max_speculative_num_draft_tokens,
)
from sglang.srt.utils import is_flashinfer_available, is_tokenspeed_mla_available
if is_flashinfer_available():
@@ -87,7 +91,6 @@ def _get_tokenspeed_workspace(
kv_lora_rank: int,
max_q_len: int = _TOKENSPEED_MAX_Q_LEN,
) -> torch.Tensor:
from sglang.srt.runtime_context import get_resources
# DCP target verification gathers Q to the full head count before launching
# TokenSpeed; size for that launch shape, not the rank-local head count.
@@ -45,13 +45,17 @@ from sglang.srt.layers.radix_attention import AttentionType
from sglang.srt.mem_cache.memory_pool import KVWriteLoc
from sglang.srt.mem_cache.swa_memory_pool import SWAKVPool
from sglang.srt.model_executor.forward_batch_info import ForwardBatch, ForwardMode
from sglang.srt.runtime_context import get_buffer, get_spec
from sglang.srt.runtime_context import (
get_buffer,
get_parallel,
get_platform,
get_spec,
)
from sglang.srt.speculative.ragged_verify import (
build_ragged_target_verify_geometry,
resolve_ragged_verify_layout,
)
from sglang.srt.utils import is_flashinfer_available
from sglang.srt.utils.common import is_sm90_supported, is_sm120_supported
logger = logging.getLogger(__name__)
@@ -222,10 +226,10 @@ class TRTLLMHAAttnBackend(FlashInferAttnBackend):
# TRTLLM-GEN:
# KV bf16: q_type = bf16, out_type=model_runner.dtype
# KV fp8: q_type = fp8, out_type=model_runner.dtype
self.is_xqa_impl = is_sm90_supported() or is_sm120_supported()
self.is_xqa_impl = get_platform().is_sm90 or get_platform().is_sm120
# fmha_v2 prefill kernel supports SM90 and SM120
self.use_fmha_v2 = is_sm90_supported() or is_sm120_supported()
self.use_fmha_v2 = get_platform().is_sm90 or get_platform().is_sm120
# trtllm-gen serves page_size >= 128 only through its dynamic
# tokens-per-page kernels, which exist solely for GQA with equal QK/V
@@ -234,7 +238,6 @@ class TRTLLMHAAttnBackend(FlashInferAttnBackend):
# "Missing TRTLLM-GEN kernel" error during CUDA-graph capture.
# XQA (SM90/SM120 decode) has native page-128 kernels; no check needed.
if self.page_size >= 128 and not self.is_xqa_impl:
from sglang.srt.runtime_context import get_parallel
attn_tp_size = get_parallel().attn_tp_size
num_q_heads = config.num_attention_heads // attn_tp_size
+8 -3
View File
@@ -17,12 +17,17 @@ from sglang.kernels.ops.layernorm.norm import (
)
from sglang.srt.environ import envs
from sglang.srt.models.utils import apply_qk_norm
from sglang.srt.runtime_context import get_context, get_exec, get_mm, get_parallel
from sglang.srt.runtime_context import (
get_context,
get_exec,
get_mm,
get_parallel,
get_platform,
)
from sglang.srt.utils import (
cpu_has_amx_support,
get_bool_env_var,
get_device_capability,
is_blackwell_supported,
is_cpu,
is_cuda,
is_hip,
@@ -1268,7 +1273,7 @@ class VisionAttention(nn.Module):
backend = "xpu_attn"
else:
backend = "sdpa"
if backend == "fa3" and is_blackwell_supported():
if backend == "fa3" and get_platform().is_blackwell:
raise ValueError("The 'fa3' backend is not supported on Blackwell GPUs")
return backend
+9 -5
View File
@@ -73,7 +73,13 @@ from sglang.srt.model_executor.cuda_graph_config import (
check_cuda_graph_backend,
)
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.runtime_context import get_exec, get_forward, get_parallel, get_spec
from sglang.srt.runtime_context import (
get_exec,
get_forward,
get_parallel,
get_platform,
get_spec,
)
from sglang.srt.speculative.spec_info import SpeculativeAlgorithm
from sglang.srt.utils import (
get_bool_env_var,
@@ -82,14 +88,12 @@ from sglang.srt.utils import (
is_gfx95_supported,
is_hip,
is_npu,
is_sm90_supported,
is_sm100_supported,
)
_is_cuda = is_cuda()
_is_flashinfer_available = is_flashinfer_available()
_is_sm90_supported = _is_cuda and is_sm90_supported()
_is_sm100_supported = _is_cuda and is_sm100_supported()
_is_sm90_supported = _is_cuda and get_platform().is_sm90
_is_sm100_supported = _is_cuda and get_platform().is_sm100
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and is_hip()
_is_gfx95_supported = is_gfx95_supported()
_is_npu = is_npu()
+1 -1
View File
@@ -22,6 +22,7 @@ from typing import TYPE_CHECKING, Any, Dict, Optional
import torch
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
resolved_view,
resolving_view,
)
@@ -46,7 +47,6 @@ if TYPE_CHECKING:
def supports_prefill_cp_bcg(server_args: ServerArgs) -> bool:
"""Return whether the selected prefill-CP configuration supports BCG."""
from sglang.srt.arg_groups.overrides import attention_backends_of
cfg = resolving_view(server_args)
resolved = resolved_view(server_args)
@@ -19,11 +19,11 @@ from sglang.srt.environ import envs
from sglang.srt.layers.deep_gemm_wrapper.configurer import ENABLE_JIT_DEEPGEMM
from sglang.srt.model_executor.forward_batch_info import ForwardMode
from sglang.srt.runtime_context import (
get_device,
get_disagg,
get_parallel,
get_schedule,
)
from sglang.srt.server_args import ServerArgs
from sglang.srt.utils import ceil_align, ceil_div, get_available_gpu_memory, is_musa
logger = logging.getLogger(__name__)
@@ -51,7 +51,7 @@ os.environ["DG_JIT_CACHE_DIR"] = envs.SGLANG_DG_CACHE_DIR.get()
os.environ["DG_JIT_USE_NVRTC"] = os.getenv("SGL_DG_USE_NVRTC", "0")
def update_deep_gemm_config(gpu_id: int, server_args: ServerArgs):
def update_deep_gemm_config(gpu_id: int):
global _BUILTIN_M_LIST
global _DO_COMPILE_ALL
global _IS_FIRST_RANK_ON_NODE
@@ -96,7 +96,7 @@ def update_deep_gemm_config(gpu_id: int, server_args: ServerArgs):
m_max = min(1024 * 128, m_max)
_BUILTIN_M_LIST += list(range(1, m_max + 1))
_IS_FIRST_RANK_ON_NODE = server_args.base_gpu_id == gpu_id
_IS_FIRST_RANK_ON_NODE = get_device().base_gpu_id == gpu_id
# Check if is the first rank on node.
# Default each rank will try compile all Ms to
@@ -1,11 +1,11 @@
import logging
from sglang.srt.environ import envs
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import (
get_device_sm,
is_cuda,
is_musa,
is_sm100_supported,
)
logger = logging.getLogger(__name__)
@@ -34,6 +34,6 @@ def _compute_enable_deep_gemm():
ENABLE_JIT_DEEPGEMM = _compute_enable_deep_gemm()
DEEPGEMM_BLACKWELL = ENABLE_JIT_DEEPGEMM and is_sm100_supported()
DEEPGEMM_BLACKWELL = ENABLE_JIT_DEEPGEMM and get_platform().is_sm100
DEEPGEMM_SCALE_UE8M0 = DEEPGEMM_BLACKWELL
DEEPGEMM_NEED_TMA_ALIGNED_SCALES = not (DEEPGEMM_SCALE_UE8M0 or _is_musa)
@@ -12,7 +12,6 @@ from sglang.srt.layers.deep_gemm_wrapper.configurer import ( # noqa: F401
DEEPGEMM_SCALE_UE8M0,
ENABLE_JIT_DEEPGEMM,
)
from sglang.srt.server_args import ServerArgs
logger = logging.getLogger(__name__)
@@ -245,13 +244,13 @@ def tf32_hc_prenorm_gemm(
deep_gemm.tf32_hc_prenorm_gemm(x, fn, out, sqrsum, num_splits=num_splits)
def update_deep_gemm_config(gpu_id: int, server_args: ServerArgs):
def update_deep_gemm_config(gpu_id: int):
# deep_gemm.set_pdl can initialize CUDA state, so run it only after the
# scheduler/TP worker has been forked and assigned a GPU.
if envs.SGLANG_DEEPGEMM_PDL.get() and hasattr(deep_gemm, "set_pdl"):
deep_gemm.set_pdl(True)
compile_utils.update_deep_gemm_config(gpu_id, server_args)
compile_utils.update_deep_gemm_config(gpu_id)
@contextmanager
+3 -10
View File
@@ -34,7 +34,10 @@ from sglang.srt.runtime_context import (
get_device,
get_exec,
get_flags,
get_forward,
get_parallel,
get_resources,
get_stream,
)
from sglang.srt.utils import get_bool_env_var, is_cpu, is_hip
@@ -166,7 +169,6 @@ class _DpGatheredBufferWrapper:
@classmethod
def set_metadata(cls, hidden_size: int, dtype: torch.dtype, device: torch.device):
from sglang.srt.runtime_context import get_flags
dp = get_flags().dp
dp.buffer_hidden_size = hidden_size
@@ -190,7 +192,6 @@ class _DpGatheredBufferWrapper:
@classmethod
def get_global_dp_buffer(cls, group: GroupCoordinator) -> torch.Tensor:
from sglang.srt.runtime_context import get_flags
dp = get_flags().dp
with use_symmetric_memory(group, disabled=not cls._dp_max_padding):
@@ -203,7 +204,6 @@ class _DpGatheredBufferWrapper:
@classmethod
def get_local_dp_buffer(cls, group: GroupCoordinator) -> torch.Tensor:
from sglang.srt.runtime_context import get_flags
dp = get_flags().dp
with use_symmetric_memory(group, disabled=not cls._dp_max_padding):
@@ -236,19 +236,16 @@ class _DpGatheredBufferWrapper:
@classmethod
def get_dp_hidden_size(cls) -> int:
from sglang.srt.runtime_context import get_flags
return get_flags().dp.buffer_hidden_size
@classmethod
def get_dp_dtype(cls) -> torch.dtype:
from sglang.srt.runtime_context import get_flags
return get_flags().dp.buffer_dtype
@classmethod
def get_dp_device(cls) -> torch.device:
from sglang.srt.runtime_context import get_flags
return get_flags().dp.buffer_device
@@ -313,13 +310,11 @@ def set_is_extend_in_batch(is_extend_in_batch: bool):
# Sticky within the thread: every ForwardBatch construction writes it,
# graph runners force False around capture; readers are the EP
# dispatchers on the same (single) forward thread.
from sglang.srt.runtime_context import get_forward
get_forward().set("is_extend_in_batch", is_extend_in_batch)
def get_is_extend_in_batch() -> bool:
from sglang.srt.runtime_context import get_forward
return get_forward().is_extend_in_batch
@@ -909,7 +904,6 @@ def dp_reduce_scatter_tensor(output: torch.Tensor, input: torch.Tensor):
# deadlock on the RCCL communicator), each overlapping the other's compute.
# ---------------------------------------------------------------------------
def get_dp_tbo_comm_stream() -> torch.cuda.Stream:
from sglang.srt.runtime_context import get_stream
return get_stream("dp_tbo_comm")
@@ -921,7 +915,6 @@ def get_dp_tbo_comm_stream() -> torch.cuda.Stream:
# ("...create internal OS-specific events"). Reuse one event per (kind, subbatch)
# and just re-record it (mirrors the mori CommStreamPool event reuse).
def _tbo_event(key) -> torch.cuda.Event:
from sglang.srt.runtime_context import get_resources
pool = get_resources().tbo_event_pool
ev = pool.get(key)
@@ -13,13 +13,16 @@ from sglang.srt.distributed import (
get_tp_group,
)
from sglang.srt.distributed.parallel_state import in_the_same_node_as
from sglang.srt.runtime_context import get_exec, get_parallel
from sglang.srt.runtime_context import (
get_exec,
get_parallel,
get_platform,
get_resources,
)
from sglang.srt.utils import (
ceil_align,
get_cuda_driver_bindings,
is_flashinfer_available,
is_sm90_supported,
is_sm100_supported,
)
from sglang.srt.utils.custom_op import register_custom_op
@@ -38,27 +41,27 @@ _flashinfer_allreduce_supports_trigger_completion = False
def _mnnvl_supported(is_multi_node: bool) -> bool:
"""Whether the mnnvl backend is usable on the current system."""
if is_sm100_supported():
if get_platform().is_sm100:
return True
return is_sm90_supported() and not is_multi_node
return get_platform().is_sm90 and not is_multi_node
def _resolve_backend(backend: str, is_multi_node: bool = False) -> str:
"""Resolve the requested FlashInfer allreduce fusion backend."""
if not (is_sm90_supported() or is_sm100_supported()):
if not (get_platform().is_sm90 or get_platform().is_sm100):
raise ValueError(
"FlashInfer allreduce fusion requires SM90 or SM10X NVIDIA GPUs."
)
if backend == "auto":
if is_multi_node:
if is_sm100_supported():
if get_platform().is_sm100:
return "mnnvl"
raise ValueError(
"FlashInfer allreduce fusion does not support multi-node on "
"non-Blackwell systems."
)
if is_sm100_supported():
if get_platform().is_sm100:
return "mnnvl"
return "trtllm"
@@ -630,7 +633,6 @@ class FlashInferWorkspaceManager:
def _get_workspace_manager(use_attn_tp_group: bool) -> FlashInferWorkspaceManager:
"""The per-group fusion workspace manager; the instances live on
``ctx.resources`` (one per comm group, created lazily)."""
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
name = (
@@ -1018,7 +1020,6 @@ def pre_initialize_workspaces(
def cleanup_flashinfer_workspace():
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
for name in (
@@ -12,6 +12,8 @@ from typing import TYPE_CHECKING
import torch
import torch.distributed as dist
from sglang.srt.runtime_context import get_spec
if TYPE_CHECKING:
from torch.distributed import ProcessGroup
@@ -149,7 +151,6 @@ class FlashInferMNNVLCuteDSLARFusion:
) = _import_kernel_backend()
# Only fused finalize launches have a completed shared-expert handoff;
# standalone AllReduce kernels retain the safe load ordering.
from sglang.srt.runtime_context import get_spec
if get_spec().speculative_algorithm is None:
self.workspace_config = _with_early_finalize_shared_load(default_config)
+1 -1
View File
@@ -25,6 +25,7 @@ import torch
import sglang.srt.runtime_context as ctx
from sglang.kernels.jit.utils import cache_once
from sglang.srt.environ import envs
from sglang.srt.runtime_context import get_parallel
if TYPE_CHECKING:
from sglang.srt.distributed.device_communicators.custom_all_reduce_v2 import (
@@ -84,7 +85,6 @@ def _get_state() -> Optional[_State]:
CustomAllReduceV2,
)
from sglang.srt.distributed.parallel_state import get_tp_group
from sglang.srt.runtime_context import get_parallel
if get_parallel().tp_size <= 1:
return None
+1 -2
View File
@@ -16,6 +16,7 @@ from typing import TYPE_CHECKING
import torch
from sglang.srt.environ import envs
from sglang.srt.runtime_context import get_parallel
if TYPE_CHECKING:
from sglang.srt.layers.linear import RowParallelLinear
@@ -33,7 +34,6 @@ def _init() -> bool:
_INITIALIZED = True
if not envs.SGLANG_K3_GEMM_AR.get():
return False
from sglang.srt.runtime_context import get_parallel
world_size = get_parallel().tp_size
if not (2 <= world_size <= 8):
@@ -57,7 +57,6 @@ def maybe_wrap_o_proj(o_proj: RowParallelLinear) -> None:
return
from sglang.kernels.ops.kimi_k3 import gemm_ar as mod
from sglang.srt.distributed.parallel_state import get_tp_group
from sglang.srt.runtime_context import get_parallel
parallel = get_parallel()
world_size = parallel.tp_size
+1 -1
View File
@@ -17,6 +17,7 @@ import torch
from sglang.srt.environ import envs
from sglang.srt.layers import k3_ar_fusion
from sglang.srt.runtime_context import get_exec, get_parallel
if TYPE_CHECKING:
from sglang.srt.distributed.device_communicators.custom_all_reduce_v2 import (
@@ -64,7 +65,6 @@ def _init_state() -> Optional[_State]:
from sglang.srt.distributed.device_communicators.custom_all_reduce_v2 import (
CustomAllReduceV2,
)
from sglang.srt.runtime_context import get_exec, get_parallel
from sglang.srt.utils.common import get_device_sm
a2a = get_exec().moe.moe_a2a_backend
+5 -4
View File
@@ -4,7 +4,8 @@ from typing import Optional, Tuple
import torch
from sglang.srt.utils import is_cuda, is_sm90_supported, is_sm100_supported
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import is_cuda
_is_cuda = is_cuda()
if _is_cuda:
@@ -145,7 +146,7 @@ def cutlass_fused_experts_fp8(
if use_mxfp8:
assert es_up and es_down, "MXFP8 requires expert-specialization for both GEMMs"
assert is_sm100_supported(), "MXFP8 requires SM100"
assert get_platform().is_sm100, "MXFP8 requires SM100"
assert k % 32 == 0, "MXFP8 requires hidden size to be divisible by 32"
assert n % 32 == 0, "MXFP8 requires intermediate size to be divisible by 32"
assert w1_scale.dtype == torch.uint8, "MXFP8 w1_scale must be uint8"
@@ -222,7 +223,7 @@ def cutlass_fused_experts_fp8(
a_sf_layout = torch.empty((num_experts, 5), device=device, dtype=torch.int)
w_sf_layout = torch.empty((num_experts, 5), device=device, dtype=torch.int)
if is_sm90_supported() and es_up:
if get_platform().is_sm90 and es_up:
es_fp8_blockwise_scaled_grouped_mm(
c1,
rep_a_q,
@@ -288,7 +289,7 @@ def cutlass_fused_experts_fp8(
else:
intemediate_q, a2_scale = sglang_per_token_group_quant_fp8(intermediate, 128)
if is_sm90_supported() and es_down:
if get_platform().is_sm90 and es_down:
es_fp8_blockwise_scaled_grouped_mm(
c2,
intemediate_q,
@@ -19,10 +19,10 @@ from triton_kernels.numerics import InFlexData
from triton_kernels.swiglu import swiglu_fn
from triton_kernels.tensor import FP4
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import is_cuda
from sglang.srt.utils.common import is_sm120_supported
if is_sm120_supported():
if get_platform().is_sm120:
# use the regular gather/scatter implementation for unsupported devices.
update_opt_flags_constraints({"is_persistent": False})
@@ -19,6 +19,7 @@ from sglang.srt.layers.moe.moe_runner.base import (
register_pre_permute,
)
from sglang.srt.layers.moe.utils import MoeRunnerBackend
from sglang.srt.runtime_context import get_parallel
from sglang.srt.utils import get_bool_env_var, get_int_env_var
if TYPE_CHECKING:
@@ -172,7 +173,6 @@ def _mori_decode_recv_bound(recv_rows: int, topk: int) -> int:
get_dp_global_num_tokens,
get_is_extend_in_batch,
)
from sglang.srt.runtime_context import get_parallel
if get_is_extend_in_batch():
return 0
@@ -12,6 +12,7 @@ from sglang.srt.layers.moe.utils import (
MoeRunnerBackendLike,
RoutingMethodType,
)
from sglang.srt.runtime_context import get_forward
if TYPE_CHECKING:
from sglang.srt.layers.moe.moe_runner.triton import (
@@ -29,7 +30,6 @@ if TYPE_CHECKING:
def moe_output_buffer_ctx(buf: torch.Tensor):
"""Provide the MoE output buffer for the current forward scope."""
from sglang.srt.runtime_context import get_forward
return get_forward().scoped(moe_output_buffer=buf)
@@ -30,7 +30,11 @@ from sglang.srt.layers.moe.moe_runner.base import (
register_pre_permute,
)
from sglang.srt.layers.moe.utils import MoeRunnerBackend, get_moe_a2a_backend
from sglang.srt.runtime_context import get_exec, get_flags
from sglang.srt.runtime_context import (
get_exec,
get_flags,
get_parallel,
)
from sglang.srt.utils import (
ceil_div,
dispose_tensor,
@@ -1077,7 +1081,6 @@ def pre_permute_flashinfer_to_deep_gemm(
"""Feed one-sided A2A output into DeepGEMM with fused expert remapping."""
from sglang.srt.layers.moe.token_dispatcher.standard import StandardDispatchOutput
from sglang.srt.runtime_context import get_parallel
if dispatch_output.hidden_states.dtype != torch.bfloat16:
raise TypeError(
@@ -65,6 +65,8 @@ from enum import Enum, IntEnum, auto
import torch
import torch.distributed as dist
from sglang.srt.runtime_context import get_resources
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and is_hip()
logger = logging.getLogger(__name__)
@@ -180,8 +182,6 @@ class DeepEPBuffer:
def _state(cls):
from types import SimpleNamespace
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
state = buffers.get("deepep_ep_state")
if state is None:
@@ -21,6 +21,10 @@ from sglang.srt.layers.moe.utils import (
DeepEPv2Fp8ScaleFormat,
get_deepep_v2_fp8_scale_format,
)
from sglang.srt.runtime_context import (
get_exec,
get_resources,
)
logger = logging.getLogger(__name__)
@@ -112,7 +116,6 @@ def _ensure_fp8_quant_available() -> None:
def _get_allow_hybrid_mode() -> bool:
from sglang.srt.runtime_context import get_exec
return get_exec().moe.deepep_v2_mode == "hybrid"
@@ -139,8 +142,6 @@ class DeepEPv2Buffer:
def _state(cls):
from types import SimpleNamespace
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
state = buffers.get(cls._STATE_KEY)
if state is None:
@@ -20,6 +20,7 @@ from sglang.srt.layers.moe.token_dispatcher.base import (
)
from sglang.srt.layers.moe.topk import TopKOutput
from sglang.srt.layers.moe.utils import DeepEPMode
from sglang.srt.runtime_context import get_resources
from sglang.srt.utils import get_int_env_var
logger = logging.getLogger(__name__)
@@ -64,8 +65,6 @@ class EPBuffer:
def _state(cls):
from types import SimpleNamespace
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
state = buffers.get("mooncake_ep_state")
if state is None:
@@ -23,7 +23,10 @@ from sglang.srt.layers.moe.token_dispatcher.deepep import (
)
from sglang.srt.layers.moe.topk import TopKOutput
from sglang.srt.layers.moe.utils import DeepEPMode
from sglang.srt.runtime_context import get_parallel
from sglang.srt.runtime_context import (
get_parallel,
get_resources,
)
try:
from nixl_ep import Buffer
@@ -53,8 +56,6 @@ class NixlEPBuffer:
def _state(cls):
from types import SimpleNamespace
from sglang.srt.runtime_context import get_resources
buffers = get_resources().buffers
state = buffers.get("nixl_ep_state")
if state is None:
+6 -2
View File
@@ -37,7 +37,12 @@ import triton.language as tl
if TYPE_CHECKING:
from triton_kernels.tensor_details.ragged_tensor import RaggedTensorMetadata
from sglang.srt.runtime_context import get_exec, get_lora, get_parallel
from sglang.srt.runtime_context import (
get_exec,
get_lora,
get_parallel,
get_server_args,
)
try:
from triton_kernels.tensor import make_ragged_tensor_metadata
@@ -1523,7 +1528,6 @@ def _eplb_remap_enabled() -> bool:
# initial expert placement is non-trivial, or there are redundant physical
# experts. Otherwise the map is identity and the remap must be skipped (it is
# both unnecessary and not well-defined over the padded region of topk_ids).
from sglang.srt.runtime_context import get_server_args
try:
get_server_args() # probes that a config is published
+1 -3
View File
@@ -19,13 +19,13 @@ from sglang.srt.runtime_context import (
get_forward,
get_model,
get_parallel,
get_server_args,
get_spec,
)
from sglang.srt.utils import is_cuda, is_npu
_is_npu = is_npu()
from sglang.srt.runtime_context import get_server_args
from sglang.srt.utils.common import log_info_on_rank0
logger = logging.getLogger(__name__)
@@ -486,7 +486,6 @@ def is_shared_experts_fusion_disabled() -> bool:
)
moe = get_flags().moe
if moe.disable_shared_experts_fusion is None:
from sglang.srt.runtime_context import get_exec
return get_exec().moe.disable_shared_experts_fusion
return moe.disable_shared_experts_fusion
@@ -529,7 +528,6 @@ def install_shared_experts_fusion_decision(
Inside ``draft_model_build_scope`` the answer also lands on the speculative
leaf, so a flags dump afterwards shows both runners' decisions.
"""
from sglang.srt.runtime_context import get_exec
disabled = get_exec().moe.disable_shared_experts_fusion
if not disabled:
@@ -69,7 +69,8 @@ from sglang.srt.layers.quantization.unquant import (
UnquantizedFusedMoEMethod,
UnquantizedLinearMethod,
)
from sglang.srt.utils import is_cuda, is_hip, is_npu, is_sm100_supported, is_xpu
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import is_cuda, is_hip, is_npu, is_xpu
_is_cuda = is_cuda()
_is_npu = is_npu()
@@ -838,7 +839,7 @@ class CompressedTensorsConfig(QuantizationConfig):
triton_supported = self._is_wna16_triton_moe_supported(weight_quant)
use_blackwell_triton = (
moe_backend.is_auto()
and is_sm100_supported()
and get_platform().is_sm100
and triton_supported
)
if moe_backend.is_triton() and not triton_supported:
@@ -10,13 +10,13 @@ from sglang.srt.layers.moe.utils import get_moe_runner_backend
from sglang.srt.layers.quantization.compressed_tensors.schemes import (
CompressedTensorsMoEScheme,
)
from sglang.srt.layers.quantization.fp8_utils import is_blackwell_supported
from sglang.srt.layers.quantization.utils import (
prepare_static_weights_for_trtllm_fp4_moe,
reorder_w1w3_to_w3w1,
replace_parameter,
swizzle_blockscale,
)
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import set_weight_attrs
logger = logging.getLogger(__name__)
@@ -33,7 +33,7 @@ if TYPE_CHECKING:
class CompressedTensorsW4A4Nvfp4MoE(CompressedTensorsMoEScheme):
def __init__(self):
if not is_blackwell_supported():
if not get_platform().is_blackwell:
raise ValueError(
"Current platform does not support NVFP4"
" quantization. Please use Blackwell and"
@@ -42,7 +42,7 @@ import torch
from torch import Tensor
from sglang.srt.layers.quantization.kvfp4_tensor import E2M1_MAX
from sglang.srt.utils.common import is_sm100_supported
from sglang.srt.runtime_context import get_platform
class KVCacheAttentionPhase(str, Enum):
@@ -416,7 +416,7 @@ class NVFP4KVCacheMethod(KVCacheQuantMethodBase):
# The FP4 data type itself is identical on both architectures.
# Reference: TRT-LLM FP8QDQLinearMethod.process_weights_after_loading_fused_qkv_linear
# https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/_torch/modules/linear.py
if is_sm100_supported():
if get_platform().is_sm100:
k_scale *= E2M1_MAX
v_scale *= E2M1_MAX
k_scales_cpu[layer_id] = k_scale
@@ -6,11 +6,13 @@ from typing import Optional
import torch
from sglang.srt.runtime_context import get_exec
from sglang.srt.runtime_context import (
get_exec,
get_platform,
)
from sglang.srt.utils.common import (
get_device_capability,
is_cuda,
is_sm100_supported,
)
from sglang.srt.utils.custom_op import register_custom_op_from_extern
@@ -21,7 +23,7 @@ fp4_quantize = None
try:
from flashinfer import fp4_quantize as _flashinfer_fp4_quantize
_flashinfer_fp4_quantize_backend = "cute-dsl" if is_sm100_supported() else "cuda"
_flashinfer_fp4_quantize_backend = "cute-dsl" if get_platform().is_sm100 else "cuda"
def _round_up(x: int, y: int) -> int:
return ((x + y - 1) // y) * y
@@ -146,7 +148,7 @@ def initialize_fp4_gemm_config() -> None:
backend = get_exec().kernel.fp4_gemm_runner_backend
if backend == "auto":
if is_sm100_supported():
if get_platform().is_sm100:
backend = "flashinfer_cutedsl"
elif is_cuda() and (10, 0) > get_device_capability() >= (8, 0):
backend = "marlin"
+11 -10
View File
@@ -80,11 +80,13 @@ from sglang.srt.layers.quantization.utils import (
requantize_with_max_scale,
)
from sglang.srt.layers.utils import copy_or_rebind_param
from sglang.srt.runtime_context import get_parallel
from sglang.srt.runtime_context import (
get_parallel,
get_platform,
)
from sglang.srt.utils import (
cpu_has_amx_support,
get_bool_env_var,
is_blackwell_supported,
is_cpu,
is_cuda,
is_flashinfer_available,
@@ -92,9 +94,6 @@ from sglang.srt.utils import (
is_hip,
is_musa,
is_npu,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
is_xpu,
log_info_on_rank0,
mxfp8_block_convert_required,
@@ -402,7 +401,7 @@ class Fp8Config(QuantizationConfig):
if self.is_fp4_experts and get_moe_runner_backend().is_flashinfer_mxfp4():
# SM100 uses TRT-LLM; SM90 uses W4A16 and SM120 uses MXFP8xMXFP4.
if is_sm90_supported() or is_sm120_supported():
if get_platform().is_sm90 or get_platform().is_sm120:
from sglang.srt.layers.quantization.mxfp4_flashinfer_cutlass_moe import (
Mxfp4FlashinferCutlassMoEMethod,
)
@@ -793,7 +792,7 @@ class Fp8LinearMethod(LinearMethodBase):
scale_u8 = layer.weight_scale_inv.data
layer.weight_scale_inv_swizzled = None
if n % 64 != 0 or k % 128 != 0:
if not (is_blackwell_supported() and is_flashinfer_available()):
if not (get_platform().is_blackwell and is_flashinfer_available()):
raise RuntimeError(
f"--fp8-gemm-backend=deep_gemm cannot serve MXFP8 weight shape "
f"({n}, {k}) (needs N % 64 == 0 and K % 128 == 0), and this "
@@ -1094,7 +1093,9 @@ class Fp8MoEMethod(FusedMoEMethodBase):
), "cutlass_fp8 MoE requires CUDA 12.0+ with SM90 or CUDA 12.4+ with SM89"
assert self.block_quant, "cutlass_fp8 MoE requires block quantization"
assert (
is_sm100_supported() or is_sm90_supported() or is_sm120_supported()
get_platform().is_sm100
or get_platform().is_sm90
or get_platform().is_sm120
), "cutlass_fp8 MoE requires SM90, SM100, or SM120 GPUs"
@staticmethod
@@ -1700,7 +1701,7 @@ class Fp8MoEMethod(FusedMoEMethodBase):
layer.w13_weight_scale_inv.format_ue8m0 = True
layer.w2_weight_scale_inv.format_ue8m0 = True
if get_moe_a2a_backend().is_megamoe() and is_sm90_supported():
if get_moe_a2a_backend().is_megamoe() and get_platform().is_sm90:
from sglang.srt.layers.moe.mega_moe_sm90 import (
build_sm90_mega_moe_experts_weights,
)
@@ -1753,7 +1754,7 @@ class Fp8MoEMethod(FusedMoEMethodBase):
def _process_mxfp8_moe_weights(self, layer: Module, quantize: bool = True) -> None:
if not (
(_is_cuda and is_sm100_supported()) or (_is_hip and _is_gfx95_supported)
(_is_cuda and get_platform().is_sm100) or (_is_hip and _is_gfx95_supported)
):
raise RuntimeError(
"MXFP8 MoE quantization requires SM100 or ROCm gfx95 "
@@ -26,7 +26,11 @@ from sglang.kernels.ops.quantization.fp8_kernel import (
from sglang.srt.environ import envs
from sglang.srt.layers import deep_gemm_wrapper
from sglang.srt.layers.quantization.mxfp4_tensor import MXFP4QuantizeUtil
from sglang.srt.runtime_context import get_exec, get_parallel
from sglang.srt.runtime_context import (
get_exec,
get_parallel,
get_platform,
)
from sglang.srt.utils import (
ceil_align,
ceil_div,
@@ -35,15 +39,11 @@ from sglang.srt.utils import (
get_device_capability,
get_device_sm,
get_hip_version,
is_blackwell_supported,
is_cuda,
is_flashinfer_available,
is_gfx95_supported,
is_hip,
is_musa,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
is_xpu,
offloader,
)
@@ -56,9 +56,6 @@ _is_hip = is_hip()
_is_cuda = is_cuda()
_is_xpu = is_xpu()
_is_fp8_fnuz = is_fp8_fnuz()
_is_sm90_supported = is_sm90_supported()
_is_sm100_supported = is_sm100_supported()
_is_sm120_supported = is_sm120_supported()
_is_gfx95_supported = is_gfx95_supported()
_is_musa = is_musa()
@@ -381,7 +378,7 @@ FP8_GEMM_RUNNER_BACKEND: Fp8GemmRunnerBackend | None = None
@lru_cache(maxsize=1)
def flashinfer_per_tensor_fp8_supported() -> bool:
return is_flashinfer_available() and (
is_sm90_supported() or is_sm100_supported() or is_sm120_supported()
get_platform().is_sm90 or get_platform().is_sm100 or get_platform().is_sm120
)
@@ -433,7 +430,7 @@ def _fake_flashinfer_mxfp8_quantize(
return q_input, scale
if is_blackwell_supported() and is_flashinfer_available():
if get_platform().is_blackwell and is_flashinfer_available():
from flashinfer import SfLayout
from flashinfer import mm_mxfp8 as _raw_flashinfer_mm_mxfp8
from flashinfer import mxfp8_quantize as _raw_flashinfer_mxfp8_quantize
@@ -544,7 +541,7 @@ if is_blackwell_supported() and is_flashinfer_available():
)
if is_sm90_supported() and is_flashinfer_available():
if get_platform().is_sm90 and is_flashinfer_available():
# FlashInfer SM90 DeepGEMM with automatic swapAB optimization for small M
from flashinfer.gemm import fp8_blockscale_gemm_sm90
@@ -573,7 +570,7 @@ def resolve_mxfp8_dense_gemm_backend() -> Mxfp8DenseGemmBackend:
backend = get_fp8_gemm_runner_backend()
if backend.is_flashinfer_trtllm():
if not (_is_sm100_supported and is_flashinfer_available()):
if not (get_platform().is_sm100 and is_flashinfer_available()):
raise RuntimeError(
"MXFP8 dense GEMM requested via --fp8-gemm-backend=flashinfer_trtllm, "
"but that kernel requires SM100/SM103 GPUs and FlashInfer."
@@ -582,7 +579,7 @@ def resolve_mxfp8_dense_gemm_backend() -> Mxfp8DenseGemmBackend:
if backend.is_flashinfer_cutedsl():
if not (
is_blackwell_supported()
get_platform().is_blackwell
and is_flashinfer_available()
and _raw_flashinfer_mm_mxfp8.is_backend_supported(
"cute-dsl", get_device_sm()
@@ -595,7 +592,7 @@ def resolve_mxfp8_dense_gemm_backend() -> Mxfp8DenseGemmBackend:
return Mxfp8DenseGemmBackend.FLASHINFER_CUTEDSL
if backend.is_flashinfer_cutlass():
if not (is_blackwell_supported() and is_flashinfer_available()):
if not (get_platform().is_blackwell and is_flashinfer_available()):
raise RuntimeError(
"MXFP8 dense GEMM requested via --fp8-gemm-backend=flashinfer_cutlass, "
"but that kernel requires Blackwell GPUs and FlashInfer."
@@ -614,7 +611,7 @@ def resolve_mxfp8_dense_gemm_backend() -> Mxfp8DenseGemmBackend:
if _is_hip and _is_gfx95_supported:
return Mxfp8DenseGemmBackend.GFX95_DOT_SCALED
if is_blackwell_supported() and is_flashinfer_available():
if get_platform().is_blackwell and is_flashinfer_available():
if _raw_flashinfer_mm_mxfp8.is_backend_supported("cute-dsl", get_device_sm()):
return Mxfp8DenseGemmBackend.FLASHINFER_CUTEDSL
return Mxfp8DenseGemmBackend.FLASHINFER_CUTLASS
@@ -712,7 +709,7 @@ def _deepgemm_w8a8_mxfp8_linear_with_fallback(
def _dispatch_explicit_backend(backend: Fp8GemmRunnerBackend) -> Callable:
"""Dispatch based on explicitly selected backend."""
if backend.is_flashinfer_trtllm():
if not (is_sm100_supported() and is_flashinfer_available()):
if not (get_platform().is_sm100 and is_flashinfer_available()):
raise RuntimeError(
"FlashInfer FP8 GEMM requested via --fp8-gemm-backend=flashinfer_trtllm, "
"but FlashInfer is not available or not supported on this hardware. "
@@ -721,7 +718,7 @@ def _dispatch_explicit_backend(backend: Fp8GemmRunnerBackend) -> Callable:
return flashinfer_gemm_w8a8_block_fp8_linear_with_fallback
elif backend.is_flashinfer_cutlass():
if not (is_blackwell_supported() and is_flashinfer_available()):
if not (get_platform().is_blackwell and is_flashinfer_available()):
raise RuntimeError(
"FlashInfer FP8 GEMM requested via --fp8-gemm-backend=flashinfer_cutlass, "
"but FlashInfer is not available or not supported on this hardware. "
@@ -730,7 +727,7 @@ def _dispatch_explicit_backend(backend: Fp8GemmRunnerBackend) -> Callable:
return flashinfer_gemm_w8a8_block_fp8_linear_with_fallback
elif backend.is_flashinfer_deepgemm():
if not (is_sm90_supported() and is_flashinfer_available()):
if not (get_platform().is_sm90 and is_flashinfer_available()):
raise RuntimeError(
"FlashInfer DeepGEMM with swapAB requested via --fp8-gemm-backend=flashinfer_deepgemm, "
"but it's not available. This backend requires Hopper (SM90) GPUs and FlashInfer "
@@ -739,7 +736,7 @@ def _dispatch_explicit_backend(backend: Fp8GemmRunnerBackend) -> Callable:
return flashinfer_deepgemm_w8a8_block_fp8_linear_with_fallback
elif backend.is_cutlass():
if not is_sm120_supported():
if not get_platform().is_sm120:
raise RuntimeError(
"--fp8-gemm-backend=cutlass is deprecated on this hardware. "
"Please switch to DeepGEMM or FlashInfer TRTLLM on SM90/SM100."
@@ -782,9 +779,9 @@ def _dispatch_auto_backend() -> Callable:
if deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM:
return deepgemm_w8a8_block_fp8_linear_with_fallback
elif is_blackwell_supported() and is_flashinfer_available():
elif get_platform().is_blackwell and is_flashinfer_available():
return flashinfer_gemm_w8a8_block_fp8_linear_with_fallback
elif is_sm120_supported():
elif get_platform().is_sm120:
return cutlass_w8a8_block_fp8_linear_with_fallback
elif _use_aiter:
return aiter_w8a8_block_fp8_linear
@@ -797,7 +794,7 @@ def initialize_fp8_gemm_config() -> None:
global FP8_GEMM_RUNNER_BACKEND
backend = get_exec().kernel.fp8_gemm_runner_backend
if backend == "auto" and is_sm120_supported():
if backend == "auto" and get_platform().is_sm120:
backend = "cutlass"
backend = Fp8GemmRunnerBackend(backend)
@@ -1839,7 +1836,7 @@ def apply_fp8_linear(
use_cutlass_channelwise_gemm and envs.SGLANG_ENABLE_FP8_GEMM_CONFIG_TUNE.get()
)
native_scalar_a_scale = use_cutlass_channelwise_gemm and (
_is_sm90_supported or _is_sm100_supported or _is_sm120_supported
get_platform().is_sm90 or get_platform().is_sm100 or get_platform().is_sm120
)
if input_prequantized:
@@ -17,6 +17,8 @@ from enum import Enum
import torch
from sglang.srt.runtime_context import get_platform
class FP4KVCacheRecipe(Enum):
MXFP4 = 1 # KVFP4: block-wise scaling
@@ -175,14 +177,9 @@ class NVFP4KVQuantizeUtil:
block_scales: shape [B, M, N/16], dtype float8_e4m3fn
global_scale: passthrough
"""
from sglang.srt.utils import (
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
)
assert (
is_sm100_supported() or is_sm120_supported() or is_sm90_supported()
get_platform().is_sm100 or get_platform().is_sm120 or get_platform().is_sm90
), "NVFP4 KV cache quantize requires SM100/SM120 or SM90 fallback GPU"
b, m, n = tensor.shape
@@ -202,7 +199,7 @@ class NVFP4KVQuantizeUtil:
"NVFP4 global scale tensor must already be on the KV tensor device."
)
if is_sm100_supported() or is_sm120_supported():
if get_platform().is_sm100 or get_platform().is_sm120:
from flashinfer import nvfp4_kv_quantize
# nvfp4_kv_quantize takes global_scale directly (not inverted)
@@ -249,11 +246,6 @@ class NVFP4KVQuantizeUtil:
Returns:
Dequantized tensor of shape [B, M, N]
"""
from sglang.srt.utils import (
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
)
b, m, n_half = quant_tensor.shape
@@ -271,7 +263,7 @@ class NVFP4KVQuantizeUtil:
"NVFP4 global scale tensor must already be on the KV tensor device."
)
if is_sm100_supported() or is_sm120_supported():
if get_platform().is_sm100 or get_platform().is_sm120:
from flashinfer import nvfp4_kv_dequantize
quant_2d = quant_tensor.view(torch.uint8).reshape(b * m, n_half)
@@ -282,7 +274,7 @@ class NVFP4KVQuantizeUtil:
return output_2d.reshape(b, m, -1)
else:
assert (
is_sm90_supported()
get_platform().is_sm90
), "NVFP4 KV cache dequantize requires SM100/SM120 or SM90 fallback GPU"
# Pure PyTorch fallback for SM90
n = n_half * 2
@@ -42,7 +42,6 @@ from sglang.srt.layers.quantization.fp8_utils import (
can_auto_enable_marlin_fp8,
cutlass_fp8_supported,
flashinfer_per_tensor_fp8_supported,
is_blackwell_supported,
)
from sglang.srt.layers.quantization.kv_cache import BaseKVCacheMethod
from sglang.srt.layers.quantization.marlin_utils_fp4 import (
@@ -63,10 +62,10 @@ from sglang.srt.layers.quantization.utils import (
)
from sglang.srt.layers.radix_attention import RadixAttention
from sglang.srt.layers.utils import alias_or_bind_derived_param, copy_or_rebind_param
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils.common import (
get_device_capability,
is_cuda,
is_sm120_supported,
round_up,
set_weight_attrs,
)
@@ -151,7 +150,7 @@ def fp4_gemm(
)
if is_cuda() and (not is_sm120_supported()) and (fp4_quantize is not None):
if is_cuda() and (not get_platform().is_sm120) and (fp4_quantize is not None):
@register_fake_if_exists("sgl_kernel::scaled_fp4_quant")
def _sgl_kernel_scaled_fp4_quant_fake(
@@ -1796,7 +1795,7 @@ class ModelOptFp4LinearMethod(LinearMethodBase):
layer.weights_padding_cols = 0
return
if not is_blackwell_supported():
if not get_platform().is_blackwell:
raise ValueError(
"ModelOpt NVFP4 native dense GEMM backends require SM100+. "
"Use --fp4-gemm-backend marlin on SM80-SM90."
@@ -2196,7 +2195,7 @@ class ModelOptNvFp4FusedMoEMethod(FusedMoEMethodBase):
use_marlin_fallback = (8, 0) <= capability < (10, 0)
else:
use_marlin_fallback = moe_runner_backend.is_marlin()
if not is_blackwell_supported() and not use_marlin_fallback:
if not get_platform().is_blackwell and not use_marlin_fallback:
raise ValueError(
"Current platform does not support NVFP4"
" quantization with the selected MoE backend. Please use "
+13 -13
View File
@@ -49,7 +49,10 @@ from sglang.srt.layers.quantization.base_config import (
QuantizeMethodBase,
)
from sglang.srt.layers.quantization.utils import is_layer_skipped
from sglang.srt.runtime_context import get_exec
from sglang.srt.runtime_context import (
get_exec,
get_platform,
)
from sglang.srt.utils import (
cpu_has_amx_support,
get_device_capability,
@@ -57,9 +60,6 @@ from sglang.srt.utils import (
is_flashinfer_available,
is_gfx95_supported,
is_hip,
is_sm90_supported,
is_sm100_supported,
is_sm120_supported,
is_triton_kernels_available,
next_power_of_2,
round_up,
@@ -236,13 +236,13 @@ def _swizzle_mxfp4(quant_tensor, scale, num_warps):
mx_axis=-2, num_warps=num_warps
)
scale_layout_opts = {}
if is_sm100_supported():
if get_platform().is_sm100:
constraints = {
"is_persistent": True,
"epilogue_subtile": 1,
}
opt_flags.update_opt_flags_constraints(constraints)
elif is_sm90_supported():
elif get_platform().is_sm90:
constraints = {
"split_k": 1,
}
@@ -413,11 +413,11 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
# (FlashInfer PR #3084, post-0.6.10)
self._fi_kernel: Optional[str] = None
if self.use_flashinfer:
if is_sm100_supported():
if get_platform().is_sm100:
self._fi_kernel = "trtllm_sm100"
elif is_sm120_supported():
elif get_platform().is_sm120:
self._fi_kernel = "cutlass_sm120"
elif is_sm90_supported():
elif get_platform().is_sm90:
if not _FI_HAS_SM90_CUTLASS_MXFP4:
raise RuntimeError(
"moe_runner_backend=flashinfer_mxfp4 on SM90 requires the "
@@ -466,7 +466,7 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
# DeepGEMM fp8_fp4 grouped GEMM consumes the checkpoint layout
# directly (packed e2m1 K-major + ue8m0 g32 scales); no padding.
pass
elif is_sm100_supported():
elif get_platform().is_sm100:
if self.use_flashinfer:
# FlashInfer trtllm-gen FP4 kernel actual alignment:
# intermediate: scale shuffle needs M%128==0 → intermediate%64==0
@@ -614,9 +614,9 @@ class Mxfp4MoEMethod(FusedMoEMethodBase):
)
if (
not is_sm90_supported()
and not is_sm100_supported()
and not is_sm120_supported()
not get_platform().is_sm90
and not get_platform().is_sm100
and not get_platform().is_sm120
):
raise RuntimeError("MXFP4 Marlin requires SM90+.")
if not check_moe_marlin_supports_layer(layer, 32, allow_tile_padding=True):
@@ -14,8 +14,8 @@ import torch
from torch.nn import Module
from torch.nn.parameter import Parameter
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import is_flashinfer_available, log_info_on_rank0
from sglang.srt.utils.common import is_sm120_supported
# Suppress TRT-LLM CUTLASS trace logs without overriding user configuration.
os.environ.setdefault("TLLM_LOG_LEVEL", "INFO")
@@ -37,7 +37,7 @@ class Mxfp4FlashinferCutlassMoEMethod:
def __init__(self, fp8_method, prefix: str):
if not is_flashinfer_available():
raise RuntimeError("Mxfp4FlashinferCutlassMoEMethod requires FlashInfer.")
self._use_mxfp8_act_scaling = is_sm120_supported()
self._use_mxfp8_act_scaling = get_platform().is_sm120
self._fp8 = fp8_method
self.prefix = prefix
self._swiglu_limit_tensor: torch.Tensor | None = None
@@ -14,15 +14,18 @@ from sglang.srt.distributed.device_communicators.pynccl_allocator import (
)
from sglang.srt.layers.dp_attention import is_allocation_symmetric
from sglang.srt.layers.moe.utils import RoutingMethodType
from sglang.srt.runtime_context import get_exec
from sglang.srt.runtime_context import (
get_exec,
get_platform,
)
from sglang.srt.utils import (
is_flashinfer_available,
log_info_on_rank0,
set_weight_attrs,
)
from sglang.srt.utils.common import is_sm100_supported, next_power_of_2
from sglang.srt.utils.common import next_power_of_2
_MXFP8_QUANTIZE_BACKEND = "cute-dsl" if is_sm100_supported() else "cuda"
_MXFP8_QUANTIZE_BACKEND = "cute-dsl" if get_platform().is_sm100 else "cuda"
if is_flashinfer_available():
from flashinfer import shuffle_matrix_a, shuffle_matrix_sf_a
@@ -8,8 +8,8 @@ from torch.nn import Module
from sglang.srt.layers.moe.moe_runner.marlin import MarlinMoeQuantInfo
from sglang.srt.layers.moe.utils import MoeRunnerBackend
from sglang.srt.runtime_context import get_platform
from sglang.srt.utils import log_info_on_rank0, round_up, set_weight_attrs
from sglang.srt.utils.common import is_sm90_supported, is_sm120_supported
if TYPE_CHECKING:
from sglang.srt.layers.moe.token_dispatcher import CombineInput, DispatchOutput
@@ -142,7 +142,7 @@ class Mxfp4MarlinMoEMethod:
if getattr(layer, "_mega_moe_weights_built", False):
return
if not is_sm90_supported() and not is_sm120_supported():
if not get_platform().is_sm90 and not get_platform().is_sm120:
raise RuntimeError("MXFP4 Marlin requires SM90 or SM120.")
if not check_moe_marlin_supports_layer(layer, 32, allow_tile_padding=True):
@@ -34,6 +34,7 @@ from sglang.srt.layers.utils import copy_or_rebind_param
from sglang.srt.runtime_context import (
get_exec,
get_lora,
get_platform,
)
from sglang.srt.utils import (
cpu_has_amx_support,
@@ -160,10 +161,8 @@ def initialize_bf16_gemm_config(server_args: ServerArgs) -> None:
global _flashinfer_pr4266_run_direct_dense
global _enable_bf16_splitk_gemm
from sglang.srt.utils import is_sm100_supported
backend_str = server_args.bf16_gemm_backend
if backend_str == "auto" and is_sm100_supported():
if backend_str == "auto" and get_platform().is_sm100:
backend_str = (
"torch"
if get_exec().deterministic.enable_deterministic_inference
@@ -190,7 +189,7 @@ def initialize_bf16_gemm_config(server_args: ServerArgs) -> None:
"--bf16-gemm-backend cutedsl is batch-size dependent and cannot "
"be combined with --enable-deterministic-inference"
)
if not is_sm100_supported():
if not get_platform().is_sm100:
raise ValueError(
f"--bf16-gemm-backend {backend.value} requires "
"SM100/SM103 (Blackwell)"
+27 -25
View File
@@ -29,7 +29,9 @@ from sglang.srt.managers.utils import (
msgpack_decode_explained,
)
from sglang.srt.runtime_context import (
get_disagg,
get_mm,
get_model,
get_observability,
get_parallel,
get_serving,
@@ -179,7 +181,7 @@ class NativeMmHost:
self.server_args = server_args
self.model_config = model_config
# Worker threads == max concurrently-processed mm requests.
self.mm_workers = server_args.mm_processor_worker_num or self.AUTO_MM_WORKERS
self.mm_workers = get_mm().mm_processor_worker_num or self.AUTO_MM_WORKERS
# The mapping the Python TokenizerManager builds in
# init_tokenizer_and_processor. The caller's already-loaded HF
@@ -277,7 +279,7 @@ class NativeMmHost:
return (
get_parallel().tp_size > 1
and determine_tensor_transport_mode() != "default"
and not self.server_args.skip_tokenizer_init
and not get_serving().skip_tokenizer_init
)
@staticmethod
@@ -398,17 +400,17 @@ class RustServer:
"ingress has no equivalent). Launch without SGLANG_RUST_SERVER, or "
"drop --preferred-sampling-params and send those values per request."
)
http_addr = f"{get_serving().host}:{server_args.port}"
http_addr = f"{get_serving().host}:{get_serving().port}"
# Per-DP-rank HTTP port with client load balancing. `None` when DP is off,
# so the rank is not conflated with rank 0 of a one-rank group.
dp_rank = scheduler.ps.attn_dp_rank if scheduler.ps.dp_size > 1 else None
if dp_rank is not None:
http_addr = f"{get_serving().host}:{server_args.port + dp_rank}"
http_addr = f"{get_serving().host}:{get_serving().port + dp_rank}"
launch_cores, server_cores = cls._partition_cores(
mm_workers=(
(server_args.mm_processor_worker_num or NativeMmHost.AUTO_MM_WORKERS)
(get_mm().mm_processor_worker_num or NativeMmHost.AUTO_MM_WORKERS)
if scheduler.model_config.is_multimodal
else 0
)
@@ -763,26 +765,26 @@ class RustServer:
"null": ext.DisaggregationMode.Null,
"prefill": ext.DisaggregationMode.Prefill,
"decode": ext.DisaggregationMode.Decode,
}[sa.disaggregation_mode]
}[get_disagg().disaggregation_mode]
return ext.ServerArgs(
model_path=sa.model_path,
served_model_name=sa.served_model_name,
tokenizer_path=sa.tokenizer_path,
revision=sa.revision,
load_format=sa.load_format,
weight_version=sa.weight_version,
model_path=get_model().model_path,
served_model_name=get_serving().served_model_name,
tokenizer_path=get_serving().tokenizer_path,
revision=get_model().revision,
load_format=get_model().load_format,
weight_version=get_serving().weight_version,
host=get_serving().host,
port=sa.port,
port=get_serving().port,
log_level=get_observability().log_level,
log_level_http=sa.log_level_http,
chat_template=sa.chat_template,
tool_call_parser=sa.tool_call_parser,
reasoning_parser=sa.reasoning_parser,
stream_response_default_include_usage=sa.stream_response_default_include_usage,
tokenizer_worker_num=sa.tokenizer_worker_num,
detokenizer_worker_num=sa.detokenizer_worker_num,
skip_tokenizer_init=sa.skip_tokenizer_init,
incremental_streaming_output=sa.incremental_streaming_output,
log_level_http=get_observability().log_level_http,
chat_template=get_serving().chat_template,
tool_call_parser=get_serving().tool_call_parser,
reasoning_parser=get_serving().reasoning_parser,
stream_response_default_include_usage=get_serving().stream_response_default_include_usage,
tokenizer_worker_num=get_serving().tokenizer_worker_num,
detokenizer_worker_num=get_serving().detokenizer_worker_num,
skip_tokenizer_init=get_serving().skip_tokenizer_init,
incremental_streaming_output=get_serving().incremental_streaming_output,
disaggregation_mode=disaggregation_mode,
model_config=ext.ModelConfig(
context_len=mc.context_len,
@@ -800,11 +802,11 @@ class RustServer:
# `preferred_sampling_params` is deliberately absent: `launch`
# refuses to start when it is set, so the Rust server never needs it.
preferred_sampling_params=(
json.dumps(sa.preferred_sampling_params)
if sa.preferred_sampling_params is not None
json.dumps(get_serving().preferred_sampling_params)
if get_serving().preferred_sampling_params is not None
else None
),
allow_auto_truncate=sa.allow_auto_truncate,
allow_auto_truncate=get_serving().allow_auto_truncate,
enable_return_hidden_states=sa.enable_return_hidden_states,
# Not a `server_args` field: `TokenizerManager` derives it, and the
# rust ingress needs the same number for its total-token check.
+1 -1
View File
@@ -4,6 +4,7 @@ from sglang.srt.dllm.config import DllmConfig
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
from sglang.srt.runtime_context import (
get_disagg,
get_parallel,
get_schedule,
get_serving,
get_spec,
@@ -137,7 +138,6 @@ from sglang.srt.observability.req_time_stats import (
DPControllerReqTimeStats,
SchedulerReqTimeStats,
)
from sglang.srt.runtime_context import get_parallel
from sglang.srt.sampling.sampling_batch_info import SamplingBatchInfo
from sglang.srt.sampling.sampling_params import SamplingParams
from sglang.srt.utils import flatten_nested_list
@@ -5,7 +5,10 @@ from array import array
from sglang.srt.environ import envs
from sglang.srt.managers.prefill_delayer import PrefillDelayerSinglePassExecutor
from sglang.srt.runtime_context import get_disagg
from sglang.srt.runtime_context import (
get_disagg,
get_schedule,
)
from sglang.srt.utils import get_bool_env_var, is_hip
_ROUTING_KEY_POLICY_DEBUG_LOG = get_bool_env_var("SGLANG_ROUTING_KEY_POLICY_DEBUG_LOG")
@@ -61,7 +64,6 @@ from sglang.srt.mem_cache.multi_ended_allocator import (
UnifiedMambaTokenToKVPoolAllocator,
)
from sglang.srt.mem_cache.radix_cache import RadixCache, RadixKey, TreeNode
from sglang.srt.server_args import ServerArgs
if TYPE_CHECKING:
from sglang.srt.mem_cache.allocator import BaseTokenToKVPoolAllocator
@@ -1434,13 +1436,13 @@ class PrefillAdder:
return self.budget_state()
def preempt_to_schedule(self, req: Req, server_args: ServerArgs) -> bool:
def preempt_to_schedule(self, req: Req) -> bool:
"""
Preempt running requests to serve the new request if the priority threshold is met and token count sum is verified.
Returns True if preemption was committed, and the new request can be scheduled.
"""
# Iterate running requests to find preemptible requests
priority_sign = 1 if server_args.schedule_low_priority_values_first else -1
priority_sign = 1 if get_schedule().schedule_low_priority_values_first else -1
# NOTE: A request finishes in two phases:
# 1) update_finish_state + release_kv_cache (in process_batch_result)
+3 -2
View File
@@ -29,6 +29,7 @@ from typing import TYPE_CHECKING, Any, Deque, Dict, List, Optional, Set, Tuple,
from sglang.srt.runtime_context import (
attention_backends,
get_context,
get_device,
get_disagg,
get_exec,
@@ -41,6 +42,7 @@ from sglang.srt.runtime_context import (
get_schedule,
get_serving,
get_spec,
publish,
)
from sglang.srt.utils.common import suppress_noisy_warnings # isort: skip
@@ -292,7 +294,6 @@ from sglang.srt.observability.trace import process_tracing_init, trace_set_threa
from sglang.srt.parser.reasoning_parser import ReasoningParser
from sglang.srt.platforms import current_platform
from sglang.srt.plugins import load_plugins
from sglang.srt.runtime_context import get_context, get_spec, publish
from sglang.srt.sampling.sampling_batch_info import SamplingBatchInfo
from sglang.srt.sampling.sampling_params import TOP_K_ALL
from sglang.srt.server_args import PortArgs, ServerArgs, compute_world_size
@@ -3526,7 +3527,7 @@ class Scheduler(
if running_batch.batch_is_full:
if (
not self.enable_priority_preemption
or not adder.preempt_to_schedule(req, self.server_args)
or not adder.preempt_to_schedule(req)
):
break
@@ -6,7 +6,7 @@ socket so out-of-process load-aware routers (e.g. sgl-router's
router-side in-flight counter. The in-deployment counterpart lives in
`sglang.srt.managers.load_snapshot` (SHM / PUSH to node 0), which a router
that only knows the worker URL cannot subscribe to; the port is instead
advertised via `/server_info` (`ServerArgs.describe_kv_events_publisher`).
advertised via `/server_info` (`runtime_context.describe_kv_events_publisher`).
The payload is a compact tagged subset of `LoadSnapshot` so the wire
contract stays fixed as the snapshot grows.
@@ -240,7 +240,7 @@ class SchedulerMetricsReporter:
"""Initialize Forward Pass Metrics (FPM) publisher if configured."""
self.scheduler.enable_fpm = False
if (
self.scheduler.server_args.enable_forward_pass_metrics
get_observability().enable_forward_pass_metrics
and self.scheduler.ps.attn_tp_rank == 0
and self.scheduler.ps.pp_rank == self.scheduler.ps.pp_size - 1
):
@@ -254,7 +254,7 @@ class SchedulerMetricsReporter:
else 0
)
self.scheduler._fpm_worker_id = (
self.scheduler.server_args.forward_pass_metrics_worker_id
get_observability().forward_pass_metrics_worker_id
)
base_endpoint = get_observability().forward_pass_metrics_ipc_name
if base_endpoint is None:
+1 -1
View File
@@ -68,6 +68,7 @@ from sglang.srt.observability.metrics_collector import (
from sglang.srt.runtime_context import (
get_memory,
get_observability,
get_parallel,
get_serving,
)
@@ -104,7 +105,6 @@ class HiRadixCache(RadixCache):
# Filled by attach_hybrid_minimax_sparse_pool_to_hiradix_cache.
self.token_to_kv_pool_host = None
elif isinstance(self.kv_cache, MLATokenToKVPool):
from sglang.srt.runtime_context import get_parallel
_parallel = get_parallel()
self.token_to_kv_pool_host = MLATokenToKVPoolHost(
@@ -1342,9 +1342,9 @@ class KVCacheConfigurator:
PoolCls = HiSparseDSATokenToKVPool
from sglang.srt.mem_cache.sparsity import parse_hisparse_config
pool_kwargs["host_to_device_ratio"] = parse_hisparse_config(
self.server_args
).host_to_device_ratio
pool_kwargs["host_to_device_ratio"] = (
parse_hisparse_config().host_to_device_ratio
)
elif dsa_cp_layer_shard_rank is not None:
# DSA cache layer split: shard KV/indexer layers across CP ranks.
from sglang.srt.mem_cache.dsa_cache_layer_split import (
@@ -1759,7 +1759,7 @@ class KVCacheConfigurator:
parse_hisparse_config,
)
hisparse_cfg = parse_hisparse_config(self.server_args)
hisparse_cfg = parse_hisparse_config()
token_to_kv_pool_allocator = HiSparseTokenToKVPoolAllocator(
sizes.max_total_num_tokens,
page_size=get_schedule().page_size,
@@ -53,6 +53,7 @@ from typing import List, Optional
import torch
from sglang.srt.mem_cache.allocator.mamba import MambaSlotAllocator
from sglang.srt.runtime_context import get_exec
logger = logging.getLogger(__name__)
@@ -313,7 +314,6 @@ def maybe_init_int8_mamba_checkpoint_pool(
allocating, so an oversized ``--int8-mamba-ckpt-size`` fails with an actionable
message instead of a cryptic mid-allocation CUDA OOM.
"""
from sglang.srt.runtime_context import get_exec
try:
mamba = get_exec().mamba
@@ -51,6 +51,7 @@ from sglang.srt.mem_cache.multi_ended_allocator import (
from sglang.srt.mem_cache.radix_cache import RadixKey
from sglang.srt.mem_cache.utils import split_node_hash_value
from sglang.srt.runtime_context import (
get_parallel,
mamba_cache_chunk_size,
)
@@ -60,8 +61,6 @@ if TYPE_CHECKING:
import logging
from sglang.srt.runtime_context import get_parallel
logger = logging.getLogger(__name__)
# Debug-only invariant checks in the Mamba slot-donation path call tensor.item(),
@@ -9,6 +9,7 @@ import torch
from sglang.srt.environ import envs
from sglang.srt.mem_cache.storage.mmap import alloc_mmap
from sglang.srt.runtime_context import get_memory
logger = logging.getLogger(__name__)
@@ -104,7 +105,6 @@ def get_allocator_from_storage(allocator_type):
def get_allocator_type() -> str:
"""The host-allocator kind the published HiCache configuration asks for."""
from sglang.srt.runtime_context import get_memory
backend = get_memory().hicache_storage_backend
if backend == "shm":
@@ -15,6 +15,7 @@ from sglang.srt.mem_cache.sparsity.core.sparse_coordinator import (
SparseConfig,
SparseCoordinator,
)
from sglang.srt.runtime_context import get_memory
logger = logging.getLogger(__name__)
@@ -58,7 +59,7 @@ def _create_backend_adaptor(
raise ValueError(f"Unknown attention backend: {backend}")
def _parse_sparse_config(server_args) -> SparseConfig:
def _parse_sparse_config() -> SparseConfig:
"""Parse hierarchical sparse config from JSON string.
Required fields with defaults: top_k (2048), device_buffer_size (2*top_k),
@@ -66,7 +67,7 @@ def _parse_sparse_config(server_args) -> SparseConfig:
Optional fields (default None): algorithm, backend, min_sparse_prompt_len,
page_size. All remaining fields go to sparse_extra_config.
"""
extra_config_str = server_args.hisparse_config
extra_config_str = get_memory().hisparse_config
if extra_config_str is not None:
try:
extra_config = json.loads(extra_config_str)
@@ -111,9 +112,9 @@ def _parse_sparse_config(server_args) -> SparseConfig:
)
def parse_hisparse_config(server_args) -> SparseConfig:
"""Parse hisparse config from server_args, returning defaults if no config provided."""
return _parse_sparse_config(server_args)
def parse_hisparse_config() -> SparseConfig:
"""The hisparse config as resolved, with defaults where none was given."""
return _parse_sparse_config()
def create_sparse_coordinator(
@@ -122,10 +123,9 @@ def create_sparse_coordinator(
token_to_kv_pool,
start_layer: int,
end_layer: int,
server_args,
**kwargs,
) -> SparseCoordinator:
config = _parse_sparse_config(server_args)
config = _parse_sparse_config()
algorithm = _create_sparse_algorithm(config, device, **kwargs)
backend_adaptor = _create_backend_adaptor(
config.backend, device, algorithm, req_to_token_pool
@@ -82,7 +82,11 @@ from sglang.srt.observability.metrics_collector import (
StorageMetrics,
StorageMetricsCollector,
)
from sglang.srt.runtime_context import get_memory, get_observability
from sglang.srt.runtime_context import (
get_memory,
get_model,
get_observability,
)
from sglang.srt.session.streaming_session import StreamingSession
from sglang.srt.utils.common import ceil_align
@@ -432,7 +436,7 @@ class UnifiedRadixCache(BasePrefixCache):
)
self.buffer_pipeline = BufferModePipeline(
cache=self,
max_context_len=server_args.context_length or 0,
max_context_len=get_model().context_length or 0,
swa_window_pages=(
swa.full_window_pages
if swa is not None and self.tree_core.has_swa_host_pool
@@ -26,6 +26,8 @@ import json
from dataclasses import dataclass, field, replace
from typing import Any, Dict, List, Optional
from sglang.srt.runtime_context import get_exec
class Phase:
"""The two phases of model forward."""
@@ -201,7 +203,6 @@ def check_cuda_graph_backend(phase: str, backend: str) -> bool:
"""True if cuda_graph_config[phase].backend == backend on the
published config. Returns False if the config has not been published
yet (e.g. unit tests, early startup)."""
from sglang.srt.runtime_context import get_exec
try:
cfg = get_exec().graph.cuda_graph_config
@@ -444,7 +444,7 @@ class ModelRunner:
# Update deep gemm configure
if deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM:
deep_gemm_wrapper.update_deep_gemm_config(gpu_id, server_args)
deep_gemm_wrapper.update_deep_gemm_config(gpu_id)
# For hisparse (must be set before initialize() so CUDA graph capture can see it)
self.hisparse_coordinator = None
@@ -542,7 +542,7 @@ class ModelRunner:
self._rearm_eplb_after_elastic_scale()
def init_msprobe(self):
self.msprobe_debugger = misc_utils.create_msprobe_debugger(self.server_args)
self.msprobe_debugger = misc_utils.create_msprobe_debugger()
def init_weight_updater(self):
self.weight_updater = WeightUpdater(
@@ -910,7 +910,7 @@ class ModelRunner:
)
from sglang.srt.mem_cache.sparsity import parse_hisparse_config
hisparse_cfg = parse_hisparse_config(self.server_args)
hisparse_cfg = parse_hisparse_config()
hisparse_top_k = getattr(
self.model_config.hf_text_config, "index_topk", hisparse_cfg.top_k
)
@@ -26,6 +26,7 @@ from sglang.srt.model_loader.remote_instance_weight_loader_utils import (
)
from sglang.srt.platforms import current_platform
from sglang.srt.runtime_context import (
get_context,
get_exec,
get_model,
get_observability,
@@ -72,7 +73,6 @@ def maybe_downgrade_dtype_for_legacy_gpu(*, model_config: ModelConfig) -> None:
logger.info(
"Compute capability below sm80. Use float16 due to lack of bfloat16 support."
)
from sglang.srt.runtime_context import get_context
# Device-driven, so every runner in the process resolves the same way;
# the per-runner truth is model_config.dtype, this is the record.
@@ -11,13 +11,13 @@ from sglang.srt.configs.model_config import (
from sglang.srt.runtime_context import (
attention_backends,
get_context,
get_observability,
get_schedule,
)
from sglang.srt.server_args import CHUNKED_PREFIX_CACHE_SUPPORTED_ATTENTION_BACKENDS
if TYPE_CHECKING:
from sglang.srt.configs.model_config import ModelConfig
from sglang.srt.server_args import ServerArgs
logger = logging.getLogger(__name__)
@@ -48,8 +48,8 @@ def maybe_disable_chunked_prefix_cache(
logger.info("Chunked prefix cache is turned on.")
def create_msprobe_debugger(server_args: ServerArgs) -> Optional[Any]:
if server_args.msprobe_dump_config is None:
def create_msprobe_debugger() -> Optional[Any]:
if get_observability().msprobe_dump_config is None:
return None
try:
@@ -62,7 +62,7 @@ def create_msprobe_debugger(server_args: ServerArgs) -> Optional[Any]:
return None
seed_all(mode=True)
return PrecisionDebugger(config_path=server_args.msprobe_dump_config)
return PrecisionDebugger(config_path=get_observability().msprobe_dump_config)
def resolve_pp_proxy_topk_size(
@@ -373,7 +373,7 @@ class DefaultPoolConfigurator(MemoryPoolConfigurator):
if memory_config.enable_hisparse:
from sglang.srt.mem_cache.sparsity import parse_hisparse_config
indexer_ratio = parse_hisparse_config(kvc.server_args).host_to_device_ratio
indexer_ratio = parse_hisparse_config().host_to_device_ratio
from sglang.srt.mem_cache.kv_cache_configurator import (
_should_elide_dsa_index_k,
@@ -794,9 +794,7 @@ class DSV4PoolConfigurator(MemoryPoolConfigurator):
if get_memory().enable_hisparse:
from sglang.srt.mem_cache.sparsity import parse_hisparse_config
self.c4_shrink_factor = parse_hisparse_config(
kvc.server_args
).host_to_device_ratio
self.c4_shrink_factor = parse_hisparse_config().host_to_device_ratio
else:
self.c4_shrink_factor = 1
assert self.c4_shrink_factor >= 1
@@ -27,6 +27,7 @@ import torch
from sglang.srt.model_executor.runner_backend_utils.breakable_cuda_graph.context import (
is_in_breakable_cuda_graph,
)
from sglang.srt.runtime_context import get_flags
# Detect whether the current forward pass is in capture mode.
is_capture_mode = False
@@ -84,7 +85,6 @@ def _set_capture_dsa_variant(variant: Optional[str]) -> None:
@contextmanager
def model_capture_mode():
global is_capture_mode
from sglang.srt.runtime_context import get_flags
# Disable dispose_tensor() during capture: freeing mid-capture records data_ptr()==0 into the graph.
is_capture_mode = True

Some files were not shown because too many files have changed in this diff Show More