Skip to content

[DeepEP] Eliminate unnecessary DP cudagraph padding #5557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions python/sglang/srt/model_executor/cuda_graph_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ def __init__(self, model_runner: ModelRunner):
self.speculative_algorithm = model_runner.server_args.speculative_algorithm
self.tp_size = model_runner.server_args.tp_size
self.dp_size = model_runner.server_args.dp_size
self.enable_deepep_moe = model_runner.server_args.enable_deepep_moe
self.moe_dense_fully_dp = (
model_runner.server_args.enable_deepep_moe
and model_runner.server_args.moe_dense_tp_size == 1
)

# Batch sizes to capture
self.capture_bs, self.compile_bs = get_batch_sizes_to_capture(model_runner)
Expand Down Expand Up @@ -301,7 +306,9 @@ def model_capture_mode(self):

def can_run(self, forward_batch: ForwardBatch):
if self.enable_dp_attention or self.enable_sp_layernorm:
total_global_tokens = sum(forward_batch.global_num_tokens_cpu)
reducer = max if self.moe_dense_fully_dp else sum
# DeepEP MoE layers uses a fixed shape with masking instead of gather tokens from DP ranks.
total_global_tokens = reducer(forward_batch.global_num_tokens_cpu)

is_bs_supported = forward_batch.can_run_dp_cuda_graph and (
total_global_tokens in self.graphs
Expand Down Expand Up @@ -484,8 +491,10 @@ def replay_prepare(self, forward_batch: ForwardBatch):

# Pad
if self.enable_dp_attention or self.enable_sp_layernorm:
reducer = max if self.moe_dense_fully_dp else sum
# DeepEP MoE layers uses a fixed shape with masking instead of gather tokens from DP ranks.
index = bisect.bisect_left(
self.capture_bs, sum(forward_batch.global_num_tokens_cpu)
self.capture_bs, reducer(forward_batch.global_num_tokens_cpu)
)
else:
index = bisect.bisect_left(self.capture_bs, raw_bs)
Expand Down
Loading