[DeepEP v2] Let a model package supply its per-rank prefill dispatch bound (#41201)

Co-authored-by: Xingyu Liu <38244988+charlotte12l@users.noreply.github.com>
This commit is contained in:
metamergebot
2026-09-24 23:39:03 -07:00
committed by GitHub
co-authored by Xingyu Liu
parent ec070ec8c8
commit 9c8340a2e5
3 changed files with 85 additions and 28 deletions
+16 -4
View File
@@ -22,7 +22,10 @@ from sglang.srt.arg_groups.overrides import (
resolving_view,
run_post_process_pass,
)
from sglang.srt.configs.moe_model_registry import model_supports_deepep_v2
from sglang.srt.configs.moe_model_registry import (
model_deepep_v2_prefill_dispatch_tokens,
model_supports_deepep_v2,
)
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
@@ -541,6 +544,17 @@ def validate_deepep_v2_speculative_draft(server_args: Any) -> None:
)
def required_deepep_v2_prefill_tokens_per_rank(server_args: Any) -> int:
"""Largest prefill dispatch on one rank, after model-specific sharding."""
view = resolved_view(server_args)
tokens = max_prefill_buffer_tokens(server_args) or (view.max_prefill_tokens or 0)
return model_deepep_v2_prefill_dispatch_tokens(
hf_config=model_config_of(server_args).hf_config,
cfg=view,
default_tokens=tokens,
)
def validate_deepep_v2_dispatch_token_budget(server_args: Any) -> None:
"""Check the configured prefill and decode-graph buffer bounds."""
view = resolved_view(server_args)
@@ -549,9 +563,7 @@ def validate_deepep_v2_dispatch_token_budget(server_args: Any) -> None:
capacity = envs.SGLANG_DEEPEP_V2_NUM_MAX_DISPATCH_TOKENS_PER_RANK.get()
if view.disaggregation_mode != "decode":
prefill_tokens = max_prefill_buffer_tokens(server_args) or (
view.max_prefill_tokens or 0
)
prefill_tokens = required_deepep_v2_prefill_tokens_per_rank(server_args)
if prefill_tokens > capacity:
raise ValueError(
"DeepEP v2 per-rank prefill budget exceeds "
+55 -23
View File
@@ -1,47 +1,79 @@
"""Model eligibility and MXFP8 precision policy for the DeepEP v2 adapter.
"""Model eligibility, precision and prefill sizing for the DeepEP v2 adapter.
External model packages register architecture names before server-argument
validation, without adding private architecture names to SGLang core.
Only the primary architecture controls eligibility and precision.
Only the primary architecture selects the model policy.
"""
from __future__ import annotations
from typing import Any
from typing import Any, Callable
# Membership enables DeepEP v2; the value requests FP32 SiLU intermediates.
_DEEPEP_V2_MODELS: dict[str, bool] = {
"DeepseekV3ForCausalLM": False,
"DeepseekV4ForCausalLM": False,
"Qwen3MoeForCausalLM": False,
"Glm5NextForConditionalGeneration": False,
import msgspec
class _DeepEPv2ModelPolicy(msgspec.Struct, frozen=True):
silu_mul_keep_fp32: bool = False
prefill_dispatch_tokens: Callable[[Any, int], int] | None = None
_DEEPEP_V2_MODELS: dict[str, _DeepEPv2ModelPolicy] = {
"DeepseekV3ForCausalLM": _DeepEPv2ModelPolicy(),
"DeepseekV4ForCausalLM": _DeepEPv2ModelPolicy(),
"Qwen3MoeForCausalLM": _DeepEPv2ModelPolicy(),
"Glm5NextForConditionalGeneration": _DeepEPv2ModelPolicy(),
}
def register_deepep_v2_model(
architecture: str, *, silu_mul_keep_fp32: bool = False
architecture: str,
*,
silu_mul_keep_fp32: bool = False,
prefill_dispatch_tokens: Callable[[Any, int], int] | None = None,
) -> None:
"""Register a model architecture with validated DeepEP v2 semantics."""
"""Register a model architecture with validated DeepEP v2 semantics.
if (
architecture in _DEEPEP_V2_MODELS
and _DEEPEP_V2_MODELS[architecture] != silu_mul_keep_fp32
):
raise ValueError(f"Conflicting DeepEP v2 precision policy for {architecture}")
_DEEPEP_V2_MODELS[architecture] = silu_mul_keep_fp32
``prefill_dispatch_tokens(cfg, tokens)`` receives a read-only resolved
configuration and the prefill-buffer ceiling. It returns the maximum
tokens one rank dispatches, without changing scheduler/buffer settings.
Omitting it preserves the default, unsharded ceiling.
"""
policy = _DeepEPv2ModelPolicy(
silu_mul_keep_fp32=silu_mul_keep_fp32,
prefill_dispatch_tokens=prefill_dispatch_tokens,
)
if architecture in _DEEPEP_V2_MODELS and _DEEPEP_V2_MODELS[architecture] != policy:
raise ValueError(f"Conflicting DeepEP v2 model policy for {architecture}")
_DEEPEP_V2_MODELS[architecture] = policy
def _policy_of(hf_config: Any) -> _DeepEPv2ModelPolicy | None:
architectures = getattr(hf_config, "architectures", None) or ()
if not architectures:
return None
return _DEEPEP_V2_MODELS.get(architectures[0])
def model_supports_deepep_v2(hf_config: Any) -> bool:
"""Check model eligibility, independently of runtime layout and topology."""
architectures = getattr(hf_config, "architectures", None) or ()
architecture = architectures[0] if architectures else None
return architecture is not None and architecture in _DEEPEP_V2_MODELS
return _policy_of(hf_config) is not None
def model_requires_fp32_silu_mul(hf_config: Any) -> bool:
"""Whether this model opts into FP32 intermediates for DeepEP v2 MXFP8."""
architectures = getattr(hf_config, "architectures", None) or ()
architecture = architectures[0] if architectures else None
return architecture is not None and _DEEPEP_V2_MODELS.get(architecture, False)
policy = _policy_of(hf_config)
return policy is not None and policy.silu_mul_keep_fp32
def model_deepep_v2_prefill_dispatch_tokens(
hf_config: Any, cfg: Any, default_tokens: int
) -> int:
"""Apply the primary model's dispatch sizing, or keep the buffer ceiling."""
policy = _policy_of(hf_config)
if policy is None or policy.prefill_dispatch_tokens is None:
return default_tokens
return policy.prefill_dispatch_tokens(cfg, default_tokens)