(1/n)support context parallel with deepseekv3.2-DSA (#12065)

This commit is contained in:
lixiaolx
2025-11-17 12:12:25 +08:00
committed by GitHub
parent 7e626d12b7
commit d368c7451a
17 changed files with 1247 additions and 54 deletions

View File

@@ -39,6 +39,7 @@ from sglang.srt.distributed.parallel_state import (
graph_capture,
set_pdmux_status,
)
from sglang.srt.layers.attention.nsa.utils import is_nsa_enable_prefill_cp
from sglang.srt.layers.dp_attention import (
DpPaddingMode,
get_attention_tp_rank,
@@ -258,6 +259,7 @@ class CudaGraphRunner:
self.attn_tp_size = get_attention_tp_size()
self.attn_tp_rank = get_attention_tp_rank()
self.nsa_enable_prefill_cp = is_nsa_enable_prefill_cp()
self.deepep_adapter = DeepEPCudaGraphRunnerAdapter()
@@ -836,7 +838,7 @@ class CudaGraphRunner:
self.global_num_tokens_for_logprob_gpu.fill_(bs * self.num_tokens_per_bs)
if enable_num_token_non_padded(self.model_runner.server_args):
num_token_non_padded = forward_batch.num_token_non_padded
if self.require_gathered_buffer:
if self.require_gathered_buffer and not self.nsa_enable_prefill_cp:
tokens_per_rank = bs // self.attn_tp_size * self.num_tokens_per_bs
num_local_token_non_padded = torch.clamp(
num_token_non_padded - tokens_per_rank * self.attn_tp_rank,

View File

@@ -42,6 +42,7 @@ from sglang.srt.distributed.parallel_state import (
get_moe_expert_parallel_world_size,
get_tensor_model_parallel_world_size,
)
from sglang.srt.layers.attention.nsa.utils import NSAContextParallelMetadata
from sglang.srt.layers.attention.utils import create_flashinfer_kv_indices_triton
from sglang.srt.layers.dp_attention import (
DpPaddingMode,
@@ -102,6 +103,17 @@ class ForwardMode(IntEnum):
or self == ForwardMode.SPLIT_PREFILL
)
def is_context_parallel_extend(self, include_draft_extend_v2: bool = False):
return (
self == ForwardMode.EXTEND
or self == ForwardMode.MIXED
or (
self == ForwardMode.DRAFT_EXTEND_V2
if include_draft_extend_v2
else False
)
)
def is_decode(self):
return self == ForwardMode.DECODE
@@ -339,6 +351,9 @@ class ForwardBatch:
# For matryoshka embeddings
dimensions: Optional[list[int]] = None
# Record the split metadata of the sequence number of NSA context parallels.
nsa_cp_metadata: Optional[NSAContextParallelMetadata] = None
@classmethod
def init_new(
cls,