From 21a4a16b4bf2d87a45e86f2636341a1d2c0dcf5d Mon Sep 17 00:00:00 2001 From: abing Date: Thu, 17 Sep 2026 19:43:41 -0700 Subject: [PATCH] update code (cherry picked from commit 1453150a0bdf2cce425e9e2da83ef16b8e8f2859) --- .../sglang/srt/arg_groups/deepseek_v4_hook.py | 18 +++++++++++++++--- .../layers/attention/deepseek_v4_backend.py | 6 +++++- .../runner/prefill_cuda_graph_runner.py | 6 +++--- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/python/sglang/srt/arg_groups/deepseek_v4_hook.py b/python/sglang/srt/arg_groups/deepseek_v4_hook.py index 6f901263e..2d5c38ad9 100644 --- a/python/sglang/srt/arg_groups/deepseek_v4_hook.py +++ b/python/sglang/srt/arg_groups/deepseek_v4_hook.py @@ -263,9 +263,21 @@ def validate_deepseek_v41_features(server_args: ServerArgs) -> None: from sglang.srt.model_executor.cuda_graph_config import Backend, Phase, with_phase prefill_graph = cfg.cuda_graph_config.prefill - if prefill_graph.backend != Backend.DISABLED and prefill_graph.max_seq_len is None: - # The captured low-ratio indexer scores a static context width; 16k - # keeps it inside the candidate window at under 1 ms per layer. + cp_breakable_prefill = ( + cfg.enable_prefill_cp + and cfg.cp_strategy == "interleave" + and cfg.tp_size > 1 + and prefill_graph.backend == Backend.BREAKABLE + ) + if ( + prefill_graph.backend != Backend.DISABLED + and prefill_graph.max_seq_len is None + and not cp_breakable_prefill + ): + # The non-CP captured low-ratio indexer scores a static context width. + # CP BCG runs these sources eagerly with live prefix metadata, so this + # default would only force long-prefix CP batches back to eager. + # Explicit max_seq_len values still constrain both paths. declare_resolution( server_args, "validate_deepseek_v41_features", diff --git a/python/sglang/srt/layers/attention/deepseek_v4_backend.py b/python/sglang/srt/layers/attention/deepseek_v4_backend.py index 86bb2e580..d11eb406d 100644 --- a/python/sglang/srt/layers/attention/deepseek_v4_backend.py +++ b/python/sglang/srt/layers/attention/deepseek_v4_backend.py @@ -1580,8 +1580,12 @@ class DeepseekV4AttnBackend( @property def low_ratio_prefill_graph(self) -> bool: + """Whether ratio-1/2 sources use captured projections and indexer metadata.""" return ( - bool(self.low_ratios) and _has_dense_fp4_indexer() and _is_sm100_or_newer() + bool(self.low_ratios) + and _has_dense_fp4_indexer() + and _is_sm100_or_newer() + and get_parallel().attn_cp_size == 1 ) def can_run_prefill_cuda_graph(self, forward_batch: ForwardBatch) -> bool: diff --git a/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py b/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py index 17bfceb8b..48695bc62 100644 --- a/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py +++ b/python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py @@ -1336,9 +1336,9 @@ class PrefillCudaGraphRunner(BaseCudaGraphRunner): batch_max_context_len=batch_max_context_len, ): return False - if getattr(self, "enable_cp_bcg_capture", False) and is_cp_active( - forward_batch - ): + if getattr(self, "enable_cp_bcg_capture", False): + if not is_cp_active(forward_batch): + return False assert self.prefill_cp_bcg_input is not None if ( self.prefill_cp_bcg_input.select_replay_bucket_for_batch(