[CP V1 Deprecation 2/5] Make strategy prefill CP canonical (#36223)

This commit is contained in:
Baizhou Zhang
2026-09-03 20:24:19 -07:00
committed by GitHub
parent 59799a3687
commit ff1285cc28
9 changed files with 240 additions and 279 deletions
@@ -168,21 +168,24 @@ def validate_deepseek_v4_cp(server_args: ServerArgs) -> None:
f"DeepSeekV4 only supports interleave CP strategy, got {cfg.cp_strategy}"
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
enable_dsa_prefill_context_parallel=True,
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
enable_prefill_context_parallel=False,
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
dsa_prefill_cp_mode="round-robin-split",
)
if get_platform().is_hip or get_platform().is_npu:
# Protected platform implementations still consume the legacy runtime
# fields. Generic backends use enable_prefill_cp/cp_strategy directly.
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
enable_dsa_prefill_context_parallel=True,
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
enable_prefill_context_parallel=False,
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
dsa_prefill_cp_mode="round-robin-split",
)
declare_resolution(
server_args,
"validate_deepseek_v4_cp",
+49 -29
View File
@@ -31,35 +31,36 @@ def handle_context_parallelism(server_args: Any):
cfg = resolving_view(server_args)
if parse_connector_type(cfg.model_path) != ConnectorType.INSTANCE:
from sglang.srt.configs.model_config import is_deepseek_dsa
from sglang.srt.layers.cp.utils import CP_V2_DEFAULT_MODEL_CLASSES
model_config = model_config_of(server_args)
hf_config = model_config.hf_config
model_arch = hf_config.architectures[0]
if model_arch in CP_V2_DEFAULT_MODEL_CLASSES:
is_dsa_default_model = is_deepseek_dsa(hf_config)
# DSA CP-v2 currently supports only the interleave strategy.
enable_default_cp_v2 = not is_dsa_default_model or (
cfg.enable_prefill_cp and cfg.cp_strategy == "interleave"
)
if enable_default_cp_v2 and not envs.SGLANG_ENABLE_CP_V2.is_set():
envs.SGLANG_ENABLE_CP_V2.set(True)
platform = get_platform()
if (
cfg.enable_prefill_cp
and model_arch in ("MiMoV2ForCausalLM", "MiMoV2FlashForCausalLM")
and envs.SGLANG_ENABLE_CP_V2.get()
and model_arch == "DeepseekV32ForCausalLM"
and cfg.cp_strategy == "zigzag"
and not (platform.is_hip or platform.is_npu)
):
raise ValueError(
"DeepSeek V3.2 prefill CP does not support --cp-strategy "
"zigzag; use interleave."
)
if cfg.enable_prefill_cp and model_arch in (
"MiMoV2ForCausalLM",
"MiMoV2FlashForCausalLM",
):
if cfg.cp_strategy != "zigzag":
raise ValueError("MiMo V2 CP-v2 only supports --cp-strategy zigzag.")
raise ValueError(
"MiMo V2 prefill CP only supports --cp-strategy zigzag."
)
if (
model_config.is_multimodal
and not cfg.language_only
and not cfg.language_model_only
):
raise ValueError(
"MiMo V2 CP-v2 only supports text inference; add --language-only."
"MiMo V2 prefill CP only supports text inference; add "
"--language-only."
)
if cfg.enable_prefill_cp and cfg.cp_strategy is None:
@@ -559,43 +560,62 @@ def handle_eplb_and_dispatch(server_args: Any):
assert resolved_view(server_args).ep_size > 1
def handle_legacy_cp_arguments(server_args: Any):
def handle_platform_cp_compatibility(server_args: Any):
cfg = resolving_view(server_args)
platform = get_platform()
is_protected_platform = platform.is_hip or platform.is_npu
if not is_protected_platform:
if (
server_args.enable_prefill_context_parallel
or server_args.enable_dsa_prefill_context_parallel
):
raise ValueError(
"Legacy prefill context-parallel options are supported only "
"by protected HIP or Ascend NPU paths. Use "
"--enable-prefill-cp with --cp-strategy."
)
return
legacy_mode_to_strategy = {
"in-seq-split": "zigzag",
"round-robin-split": "interleave",
}
strategy_to_legacy_mode = {
"zigzag": "in-seq-split",
"interleave": "round-robin-split",
}
if cfg.enable_prefill_context_parallel or cfg.enable_dsa_prefill_context_parallel:
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_platform_cp_compatibility",
enable_prefill_cp=True,
)
if cfg.enable_prefill_context_parallel and cfg.cp_strategy is None:
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_platform_cp_compatibility",
cp_strategy=legacy_mode_to_strategy[cfg.prefill_cp_mode],
)
if cfg.enable_dsa_prefill_context_parallel and cfg.cp_strategy is None:
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_platform_cp_compatibility",
cp_strategy=legacy_mode_to_strategy[cfg.dsa_prefill_cp_mode],
)
def handle_legacy_cp_runtime_compatibility(server_args: Any):
"""Project canonical CP settings for runtime consumers removed by PR3."""
cfg = resolving_view(server_args)
if cfg.enable_prefill_context_parallel and cfg.enable_dsa_prefill_context_parallel:
return
if not cfg.enable_prefill_cp or cfg.cp_strategy is None:
return
strategy_to_legacy_mode = {
"zigzag": "in-seq-split",
"interleave": "round-robin-split",
}
mode = strategy_to_legacy_mode[cfg.cp_strategy]
use_dsa_legacy_aliases = cfg.enable_dsa_prefill_context_parallel or getattr(
resolved_view(server_args), "attention_backend", None
@@ -603,28 +623,28 @@ def handle_legacy_cp_arguments(server_args: Any):
if use_dsa_legacy_aliases:
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_legacy_cp_runtime_compatibility",
enable_dsa_prefill_context_parallel=True,
)
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_legacy_cp_runtime_compatibility",
enable_prefill_context_parallel=False,
)
else:
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_legacy_cp_runtime_compatibility",
enable_prefill_context_parallel=True,
)
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_legacy_cp_runtime_compatibility",
dsa_prefill_cp_mode=mode,
)
declare_resolution(
server_args,
"_handle_legacy_cp_arguments",
"_handle_legacy_cp_runtime_compatibility",
prefill_cp_mode=mode,
)
+8 -7
View File
@@ -146,8 +146,8 @@ def run_resolution_pipeline(server_args: Any) -> None:
handle_pd_disaggregation(server_args)
# Normalize deprecated CP aliases before validations or model-specific
# defaults inspect enable_prefill_cp/cp_strategy.
# Normalize protected-platform CP aliases before validations or
# model-specific defaults inspect enable_prefill_cp/cp_strategy.
from sglang.srt.arg_groups.parallel_hook import (
handle_context_parallelism,
handle_data_parallelism,
@@ -156,10 +156,11 @@ def run_resolution_pipeline(server_args: Any) -> None:
handle_elastic_ep,
handle_eplb_and_dispatch,
handle_expert_distribution_metrics,
handle_legacy_cp_arguments,
handle_legacy_cp_runtime_compatibility,
handle_platform_cp_compatibility,
)
handle_legacy_cp_arguments(server_args)
handle_platform_cp_compatibility(server_args)
from sglang.srt.arg_groups.kv_cache_hook import (
handle_cache_compatibility,
handle_kv4_compatibility,
@@ -286,9 +287,9 @@ def run_resolution_pipeline(server_args: Any) -> None:
# Normalize load balancing defaults.
handle_load_balance_method(server_args)
# Re-apply after model-specific defaults resolve attention_backend so
# canonical CP mirrors to the right legacy runtime aliases.
handle_legacy_cp_arguments(server_args)
# The old runtime distinguishes DSA from other CP paths through legacy
# fields, so project only after attention_backend has been resolved.
handle_legacy_cp_runtime_compatibility(server_args)
# Handle context parallelism.
handle_context_parallelism(server_args)
+3 -1
View File
@@ -677,7 +677,6 @@ class Envs:
# ===================================================================
# Distributed and model-parallel runtime
# ===================================================================
SGLANG_ENABLE_CP_V2 = EnvBool(False)
SGLANG_ONE_VISIBLE_DEVICE_PER_PROCESS = EnvBool(False)
# Comma-separated bundle indices for Ray Custom PG mode (e.g., "0,1,2,7").
SGLANG_RAY_BUNDLE_INDICES = EnvStr("")
@@ -1753,6 +1752,9 @@ _DEPRECATED_ENVS: Dict[str, _DeprecatedEnv] = {
note="Note the unit change: milliseconds -> seconds.",
),
# Removed without replacement.
"SGLANG_ENABLE_CP_V2": _DeprecatedEnv(
note="Strategy-based prefill context parallelism is now the only generic implementation."
),
"SGLANG_PER_TOKEN_GROUP_QUANT_8BIT_V2": _DeprecatedEnv(),
# Superseded by the unified JIT per_token_group_quant, the default CUDA path.
"SGLANG_OPT_USE_JIT_PER_TOKEN_GROUP_QUANT": _DeprecatedEnv(),
@@ -18,7 +18,7 @@ from sglang.srt.runtime_context import (
get_parallel,
process_model_config,
)
from sglang.srt.utils import get_bool_env_var, is_cuda, is_hip
from sglang.srt.utils import get_bool_env_var, is_cuda, is_hip, is_npu
from sglang.srt.utils.common import ceil_align, ceil_div
@@ -105,12 +105,11 @@ def should_use_dsa_fused_topk(seed_dsa_topk_from_draft_extend: bool) -> bool:
def is_dsa_enable_prefill_cp():
if not envs.SGLANG_ENABLE_CP_V2.get():
if is_hip() or is_npu():
return get_parallel().enable_dsa_prefill_context_parallel
# Derive from the runtime CP topology + model arch rather than the legacy
# flag under CP-v2: DSA prefill CP is active when the CP group is on for a
# DeepSeek Sparse Attention model.
# Generic prefill CP derives activation from the runtime topology and model
# architecture. Protected HIP/NPU paths continue to use their legacy field.
if get_parallel().attn_cp_size <= 1:
return False
from sglang.srt.configs.model_config import is_deepseek_dsa, is_deepseek_v4
+3 -16
View File
@@ -40,18 +40,6 @@ from sglang.srt.runtime_context import get_parallel
if TYPE_CHECKING:
from sglang.srt.model_executor.model_runner import ModelRunner
CP_V2_DEFAULT_MODEL_CLASSES = frozenset(
{
"DeepseekV32ForCausalLM",
"GlmMoeDsaForCausalLM",
"GptOssForCausalLM",
"MiMoV2FlashForCausalLM",
"MiMoV2ForCausalLM",
"Qwen3MoeForCausalLM",
"DeepseekV3ForCausalLM",
}
)
def is_glm_dsa_cache_layer_split_enabled(model_runner: "ModelRunner") -> bool:
"""Whether DSA GPU KV/indexer cache layers are sharded across CP ranks.
@@ -130,10 +118,10 @@ def get_layer_owner(local_layer_idx: int, shard_size: int, total_layers: int) ->
def enable_cp_v2() -> bool:
"""Return whether the CP-v2 path is enabled for this process."""
from sglang.srt.environ import envs
"""Return whether the strategy-based generic prefill CP path is available."""
from sglang.srt.utils import is_hip, is_npu
return bool(envs.SGLANG_ENABLE_CP_V2.get())
return not (is_hip() or is_npu())
def is_cp_v2_active(forward_batch) -> bool:
@@ -322,7 +310,6 @@ __all__ = [
"InterleaveContextParallelMetadata",
"ZigzagCPStrategy",
"ZigzagContextParallelMetadata",
"CP_V2_DEFAULT_MODEL_CLASSES",
"enable_cp_v2",
"get_cp_strategy",
"is_cp_v2_active",
-34
View File
@@ -4019,13 +4019,6 @@ class ServerArgs:
dest="cuda_graph_max_bs_prefill",
help="Deprecated alias for --cuda-graph-max-bs-prefill.",
)
parser.add_argument(
"--enable-dsa-prefill-context-parallel",
dest="enable_dsa_prefill_context_parallel",
action=DeprecatedStoreTrueAction,
new_flag="--enable-prefill-cp",
help="[Deprecated] Use --enable-prefill-cp instead.",
)
parser.add_argument(
"--enable-nsa-prefill-context-parallel",
dest="enable_dsa_prefill_context_parallel",
@@ -4047,20 +4040,6 @@ class ServerArgs:
new_flag="--enable-prefill-cp",
help="[Deprecated] Use --enable-prefill-cp instead.",
)
parser.add_argument(
"--dsa-prefill-cp-mode",
dest="dsa_prefill_cp_mode",
action=DeprecatedAliasStoreAction,
new_flag="--cp-strategy",
type=str,
default=ServerArgs.dsa_prefill_cp_mode,
choices=["in-seq-split", "round-robin-split"],
help=(
"[Deprecated] Use --cp-strategy {zigzag,interleave} instead. "
"'in-seq-split' maps to 'zigzag'; 'round-robin-split' maps to "
"'interleave'."
),
)
parser.add_argument(
"--nsa-prefill-cp-mode",
dest="dsa_prefill_cp_mode",
@@ -4071,19 +4050,6 @@ class ServerArgs:
choices=["in-seq-split", "round-robin-split"],
help="[Deprecated] Use --cp-strategy instead.",
)
parser.add_argument(
"--prefill-cp-mode",
dest="prefill_cp_mode",
action=DeprecatedAliasStoreAction,
new_flag="--cp-strategy",
type=str,
default=ServerArgs.prefill_cp_mode,
choices=["in-seq-split"],
help=(
"[Deprecated] Use --cp-strategy {zigzag,interleave} instead. "
"'in-seq-split' maps to 'zigzag'."
),
)
parser.add_argument(
"--enable-flashinfer-allreduce-fusion",
action="store_true",