From 289cbcf482f3704bc48975e8627646da566cc423 Mon Sep 17 00:00:00 2001 From: ybyang <10629930+whybeyoung@users.noreply.github.com> Date: Tue, 17 Mar 2026 00:51:47 +0800 Subject: [PATCH] fix: support PP2+CP8+TP8 (PP with context parallelism) (#19548) --- python/sglang/srt/managers/scheduler_pp_mixin.py | 12 ++++++++++-- python/sglang/srt/server_args.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/managers/scheduler_pp_mixin.py b/python/sglang/srt/managers/scheduler_pp_mixin.py index 37cfd20b0..c296fe6ab 100644 --- a/python/sglang/srt/managers/scheduler_pp_mixin.py +++ b/python/sglang/srt/managers/scheduler_pp_mixin.py @@ -865,7 +865,7 @@ class SchedulerPPMixin: def _pp_send_pyobj_to_next_stage(self: Scheduler, data, async_send: bool = False): p2p_work = [] - if self.attn_tp_rank == 0: + if self.attn_tp_rank == 0 and self.attn_cp_rank == 0: dp_offset = self.attn_dp_rank * self.attn_tp_size p2p_work = point_to_point_pyobj( data, @@ -878,7 +878,7 @@ class SchedulerPPMixin: return p2p_work def _pp_recv_pyobj_from_prev_stage(self: Scheduler): - if self.attn_tp_rank == 0: + if self.attn_tp_rank == 0 and self.attn_cp_rank == 0: dp_offset = self.attn_dp_rank * self.attn_tp_size data = point_to_point_pyobj( [], @@ -898,6 +898,14 @@ class SchedulerPPMixin: src=self.attn_tp_group.ranks[0], ) + if self.attn_cp_size > 1: + data = broadcast_pyobj( + data, + self.attn_cp_group.rank, + self.attn_cp_cpu_group, + src=self.attn_cp_group.ranks[0], + ) + return data def _pp_prepare_tensor_dict( diff --git a/python/sglang/srt/server_args.py b/python/sglang/srt/server_args.py index ef7df1cfa..43c62b0be 100644 --- a/python/sglang/srt/server_args.py +++ b/python/sglang/srt/server_args.py @@ -1474,6 +1474,7 @@ class ServerArgs: assert ( self.tp_size == 8 ), "Current multi-machine CP support suffers from precision issues. So context parallel only support Single machine(tp_size == 8)" + self.attn_cp_size = self.tp_size logger.warning( f"Enable Context Parallel opt for deeeseekv3.2-DSA, Setting dp_size == {self.dp_size} and moe_dense_tp_size == {self.moe_dense_tp_size}, ep_size == {self.ep_size}, tp_size == {self.tp_size}, kv_cache_dtype == {self.kv_cache_dtype}, moe_a2a_backend {self.moe_a2a_backend} " @@ -2438,7 +2439,6 @@ class ServerArgs: assert ( self.tp_size % (self.dp_size * self.attn_cp_size) == 0 ), "tp_size must be divisible by dp_size * attn_cp_size" - assert self.pp_size == 1, "PP is not supported with context parallelism" if self.moe_dp_size > 1: # The tp_size is the world size, not the real tensor parallel size