Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 17 additions & 30 deletions python/sglang/srt/arg_groups/attention_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,25 @@
from typing import Any

from sglang.srt.arg_groups.overrides import (
_attention_backend_default,
_attention_backend_dual_chunk,
_attention_backend_fa3_fp8_fallback,
_attention_backend_platform_fallbacks,
_cutedsl_prefill_backend_fill,
_deterministic_allreduce_fusion_disable,
_deterministic_attention_backend,
_deterministic_sampling_backend,
_fa4_page_constraint,
_intel_xpu_page_constraint,
_mla_backend_page_constraints,
_mla_kv_cache_dtype_checks,
declare_resolution,
mamba_extra_buffer_of,
model_config_of,
resolved_view,
resolving_view,
run_post_process_pass,
use_mla_backend,
)
from sglang.srt.connector import ConnectorType
from sglang.srt.environ import envs
Expand All @@ -29,28 +45,14 @@


def handle_attention_backend_compatibility(server_args: Any):
from sglang.srt.arg_groups.overrides import (
attention_backends_of,
model_config_of,
use_mla_backend,
)
from sglang.srt.arg_groups.overrides import attention_backends_of

cfg = resolving_view(server_args)
model_config = model_config_of(server_args)

# The attention_backend write clusters of this handler moved to the
# resolution pipeline (arg_groups/overrides.py), each invoked below at
# its legacy slot; the interleaved non-attention adjustments stay.
from sglang.srt.arg_groups.overrides import (
_attention_backend_default,
_attention_backend_dual_chunk,
_attention_backend_fa3_fp8_fallback,
_attention_backend_platform_fallbacks,
_fa4_page_constraint,
_intel_xpu_page_constraint,
_mla_backend_page_constraints,
run_post_process_pass,
)

# Split-backend override + default fill.
run_post_process_pass(server_args, _attention_backend_default)
Expand Down Expand Up @@ -122,14 +124,12 @@ def handle_attention_backend_compatibility(server_args: Any):
# The TRT-LLM / tokenspeed MLA kv-dtype validations moved to the
# resolution pipeline (arg_groups/overrides.py:
# _mla_kv_cache_dtype_checks), invoked here at their legacy slot.
from sglang.srt.arg_groups.overrides import _mla_kv_cache_dtype_checks

run_post_process_pass(server_args, _mla_kv_cache_dtype_checks)

# The CuteDSL MLA validation + prefill fill moved to the resolution
# pipeline (arg_groups/overrides.py: _cutedsl_prefill_backend_fill),
# invoked here at its legacy slot.
from sglang.srt.arg_groups.overrides import _cutedsl_prefill_backend_fill

run_post_process_pass(server_args, _cutedsl_prefill_backend_fill)

Expand Down Expand Up @@ -334,9 +334,6 @@ def handle_linear_attn_backend(server_args: Any):
"KDA, as the linear-attn decode backend; got "
f"--linear-attn-decode-backend={decode!r}."
)
from sglang.srt.arg_groups.overrides import (
mamba_extra_buffer_of,
)

if mamba_extra_buffer_of(resolved_view(server_args)):
raise ValueError(
Expand Down Expand Up @@ -505,7 +502,6 @@ def handle_multi_item_scoring(server_args: Any):


def handle_deterministic_inference(server_args: Any):
from sglang.srt.arg_groups.overrides import model_config_of
from sglang.srt.server_args import (
RADIX_SUPPORTED_DETERMINISTIC_ATTENTION_BACKEND,
)
Expand Down Expand Up @@ -538,21 +534,12 @@ def handle_deterministic_inference(server_args: Any):
# Moved to the resolution pipeline (arg_groups/overrides.py:
# _deterministic_allreduce_fusion_disable), invoked here at its
# legacy slot.
from sglang.srt.arg_groups.overrides import (
_deterministic_allreduce_fusion_disable,
run_post_process_pass,
)

run_post_process_pass(server_args, _deterministic_allreduce_fusion_disable)

# The forced-pytorch sampling write and the attention backend
# fill/validation moved to the resolution pipeline
# (arg_groups/overrides.py), invoked at their legacy slots.
from sglang.srt.arg_groups.overrides import (
_deterministic_attention_backend,
_deterministic_sampling_backend,
run_post_process_pass,
)

run_post_process_pass(server_args, _deterministic_sampling_backend)
is_deepseek_model = False
Expand Down
9 changes: 3 additions & 6 deletions python/sglang/srt/arg_groups/cuda_graph_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from sglang.srt.arg_groups.overrides import (
declare_resolution,
model_config_of,
resolved_view,
resolving_view,
)
Expand Down Expand Up @@ -110,7 +111,7 @@ 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, model_config_of
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:
Expand Down Expand Up @@ -153,7 +154,6 @@ def disable_tc_piecewise_cudagraph_if_incompatible(server_args: Any):
"""TcPiecewise (torch.compile + piecewise) is incompatible with
these configurations. Most are torch.compile / dynamo limitations.
"""
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)

Expand Down Expand Up @@ -244,7 +244,6 @@ def disable_breakable_cudagraph_if_incompatible(server_args: Any):
memory-saver rejection in its own __init__; config-time rules can be
added here as they're discovered.
"""
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)
from sglang.srt.configs.model_config import is_deepseek_v4
Expand Down Expand Up @@ -331,7 +330,7 @@ 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, model_config_of
from sglang.srt.arg_groups.overrides import attention_backends_of

cfg = resolving_view(server_args)

Expand Down Expand Up @@ -403,7 +402,6 @@ def apply_inkling_prefill_cuda_graph_default(server_args: Any):
auto-disabled for this multimodal arch, and declarative model overrides
materialize too late to steer cuda-graph resolution. Honors an explicit
--cuda-graph-backend-prefill / --disable-prefill-cuda-graph."""
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)
if (
Expand All @@ -425,7 +423,6 @@ def apply_inkling_prefill_cuda_graph_default(server_args: Any):


def apply_muse_glimmer_prefill_cuda_graph_max_bs_default(server_args: Any):
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)
if (
Expand Down
6 changes: 2 additions & 4 deletions python/sglang/srt/arg_groups/deepseek_v4_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
from typing import TYPE_CHECKING

from sglang.srt.arg_groups.overrides import (
_deepseek_v4_kv_cache_dtype,
declare_resolution,
resolving_view,
run_post_process_pass,
)
from sglang.srt.environ import envs

Expand Down Expand Up @@ -129,10 +131,6 @@ def apply_deepseek_v4_defaults(server_args: ServerArgs, model_arch: str) -> None
# The kv-cache dtype default moved to the resolution pipeline
# (arg_groups/overrides.py: _deepseek_v4_kv_cache_dtype), invoked here at
# its legacy slot.
from sglang.srt.arg_groups.overrides import (
_deepseek_v4_kv_cache_dtype,
run_post_process_pass,
)

run_post_process_pass(server_args, _deepseek_v4_kv_cache_dtype)

Expand Down
11 changes: 4 additions & 7 deletions python/sglang/srt/arg_groups/dllm_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
from typing import Any

from sglang.srt.arg_groups.overrides import (
_dllm_attention_backend,
_dllm_overlap_disable,
_dllm_page_size,
declare_resolution,
resolving_view,
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
Expand Down Expand Up @@ -46,12 +50,6 @@ def handle_dllm_inference(server_args: Any):
),
)

from sglang.srt.arg_groups.overrides import (
_dllm_attention_backend,
_dllm_overlap_disable,
run_post_process_pass,
)

run_post_process_pass(server_args, _dllm_attention_backend)
run_post_process_pass(server_args, _dllm_overlap_disable)

Expand All @@ -60,7 +58,6 @@ def handle_dllm_inference(server_args: Any):
# Invoked outside the radix gate: the alignment fill keeps its radix
# gate inside the pass, the block-size cap applies regardless (it
# replaces the unconditional scheduler-init fallback).
from sglang.srt.arg_groups.overrides import _dllm_page_size

run_post_process_pass(server_args, _dllm_page_size)

Expand Down
7 changes: 5 additions & 2 deletions python/sglang/srt/arg_groups/expert_pack_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
from pathlib import Path
from typing import Any

from sglang.srt.arg_groups.overrides import declare_resolution, resolving_view
from sglang.srt.arg_groups.overrides import (
declare_resolution,
model_config_of,
resolving_view,
)
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import (
Backend,
Expand All @@ -27,7 +31,6 @@

def handle_expert_pack(server_args: Any) -> None:
"""Normalize expert-pack settings and report all startup errors together."""
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)
if cfg.load_format != "expert_pack":
Expand Down
2 changes: 1 addition & 1 deletion python/sglang/srt/arg_groups/hicache_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from sglang.srt.arg_groups.overrides import (
declare_resolution,
resolving_view,
use_mla_backend,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -68,7 +69,6 @@ def handle_hicache_ratio_default(server_args: Any):


def resolve_hicache_dcp_compatibility(server_args: Any):
from sglang.srt.arg_groups.overrides import use_mla_backend

cfg = resolving_view(server_args)
if cfg.dcp_size <= 1 or not cfg.enable_hierarchical_cache:
Expand Down
11 changes: 5 additions & 6 deletions python/sglang/srt/arg_groups/hisparse_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import logging
from typing import TYPE_CHECKING

from sglang.srt.arg_groups.overrides import resolving_view
from sglang.srt.arg_groups.overrides import (
model_config_of,
resolved_view,
resolving_view,
)

if TYPE_CHECKING:
from sglang.srt.server_args import ServerArgs
Expand Down Expand Up @@ -46,7 +50,6 @@ def _hisparse_allowed_backends(kv_cache_dtype: str) -> set[str]:
def validate_hisparse_dsa_backend(
server_args: ServerArgs, attr: str, label: str
) -> None:
from sglang.srt.arg_groups.overrides import resolved_view

# Invoked after the DSA kv-cache-dtype / split-backend declarations:
# read the resolving state through the view.
Expand All @@ -65,7 +68,6 @@ def validate_hisparse_dsa_backend(


def validate_hisparse_kv_cache_dtype(server_args: ServerArgs) -> None:
from sglang.srt.arg_groups.overrides import resolved_view

kv_cache_dtype = resolved_view(server_args).kv_cache_dtype
if kv_cache_dtype in HISPARSE_KV_CACHE_DTYPES:
Expand All @@ -82,7 +84,6 @@ def validate_hisparse_kv_cache_dtype(server_args: ServerArgs) -> None:

def validate_hisparse(server_args: ServerArgs) -> None:
"""Validate --enable-hisparse constraints (model class, radix cache, DSA backend)."""
from sglang.srt.arg_groups.overrides import model_config_of

cfg = resolving_view(server_args)
if not cfg.enable_hisparse:
Expand Down Expand Up @@ -126,8 +127,6 @@ def validate_hisparse(server_args: ServerArgs) -> None:
)
return

from sglang.srt.arg_groups.overrides import resolved_view

if resolved_view(server_args).kv_cache_dtype not in (
"bfloat16",
"auto",
Expand Down
5 changes: 3 additions & 2 deletions python/sglang/srt/arg_groups/kv_cache_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
declare_resolution,
resolved_view,
resolving_view,
use_mla_backend,
)
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend
Expand Down Expand Up @@ -37,7 +38,7 @@ 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, use_mla_backend
from sglang.srt.arg_groups.overrides import attention_backends_of

cfg = resolving_view(server_args)

Expand Down Expand Up @@ -279,7 +280,7 @@ 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, use_mla_backend
from sglang.srt.arg_groups.overrides import attention_backends_of

cfg = resolving_view(server_args)
if cfg.enable_unified_memory:
Expand Down
9 changes: 3 additions & 6 deletions python/sglang/srt/arg_groups/memory_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

from sglang.srt.arg_groups.overrides import (
declare_resolution,
model_config_of,
post_capture_kv_sizing_planned,
resolved_view,
resolving_view,
use_mla_backend,
)
from sglang.srt.environ import envs
from sglang.srt.model_executor.cuda_graph_config import Backend
Expand Down Expand Up @@ -47,11 +50,6 @@ def handle_gpu_memory_settings(server_args: Any, gpu_mem):
generate_decode_cuda_graph_batch_sizes,
generate_prefill_cuda_graph_batch_sizes,
)
from sglang.srt.arg_groups.overrides import (
model_config_of,
post_capture_kv_sizing_planned,
use_mla_backend,
)

cfg = resolving_view(server_args)
# A copy, so an earlier declaration keeps the value it recorded.
Expand Down Expand Up @@ -278,7 +276,6 @@ def handle_gpu_memory_settings(server_args: Any, gpu_mem):


def reserve_for_graph_mb(server_args: Any) -> float:
from sglang.srt.arg_groups.overrides import use_mla_backend

cfg = resolving_view(server_args)
decode_cuda_graph_config = cfg.cuda_graph_config.decode
Expand Down
Loading
Loading