Skip to content

Enable breakable prefill CUDA graph for DP attention - #30898

Merged
merrymercy merged 3 commits into
mainfrom
prefill-bcg-dp-attention
Jul 13, 2026
Merged

merrymercy merged 3 commits into
mainfrom
prefill-bcg-dp-attention

Conversation

@merrymercy

@merrymercy merrymercy commented Jul 11, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Allow breakable prefill CUDA graph replay to use consistent DP padding across ranks.
  • Preserve non-padded token accounting through prefill graph capture and replay.
  • Carry prefill logprob metadata through breakable CUDA graph replay.

Testing

  • python3 -m py_compile python/sglang/srt/managers/scheduler_components/dp_attn.py python/sglang/srt/model_executor/cuda_graph_buffer_registry.py python/sglang/srt/model_executor/forward_batch_info.py python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py python/sglang/srt/model_executor/runner_utils/buffers.py python/sglang/srt/server_args.py test/registered/unit/model_executor/test_cuda_graph_buffer_registry.py
  • with-proxy uv run pre-commit run --files python/sglang/srt/managers/scheduler_components/dp_attn.py python/sglang/srt/model_executor/cuda_graph_buffer_registry.py python/sglang/srt/model_executor/forward_batch_info.py python/sglang/srt/model_executor/runner/prefill_cuda_graph_runner.py python/sglang/srt/model_executor/runner_utils/buffers.py python/sglang/srt/server_args.py test/registered/unit/model_executor/test_cuda_graph_buffer_registry.py
  • with-proxy uv run pytest test/registered/unit/model_executor/test_cuda_graph_buffer_registry.py -q

Original commits

  • 624a9b21af

CI States

Latest PR Test (Base): ❌ Run #29193679942
Latest PR Test (Extra): ❌ Run #29193679875

@merrymercy

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 11, 2026
@merrymercy
merrymercy force-pushed the prefill-bcg-dp-attention branch from 69a2b75 to 9387a50 Compare July 12, 2026 09:09

@merrymercy merrymercy left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

@merrymercy

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py:

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/dp_attn/test_dp_attention_bcg_kl.py

@merrymercy
merrymercy force-pushed the prefill-bcg-dp-attention branch from 9387a50 to 39e6cf5 Compare July 12, 2026 09:46
@merrymercy

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py:

🚀 2-gpu-h100 (1 test): ❌ View workflow run

cd test/ && python3 registered/dp_attn/test_dp_attention_bcg_kl.py

@merrymercy
merrymercy force-pushed the prefill-bcg-dp-attention branch from 39e6cf5 to 439c4bb Compare July 12, 2026 09:51
@merrymercy

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/dp_attn/test_dp_attention_bcg_kl.py:

🚀 2-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/dp_attn/test_dp_attention_bcg_kl.py

@merrymercy merrymercy added the run-ci-extra CI: also run the extra suite (requires run-ci) label Jul 12, 2026
@merrymercy

Copy link
Copy Markdown
Collaborator Author

will try to fast merge this without passing all CI.

since some CIs are flaky and the previous same content passed all CIs
#30185 (comment)

@merrymercy

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/models_e2e/test_mimo_v2_flash.py

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test/registered/models_e2e/test_mimo_v2_flash.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/models_e2e/test_mimo_v2_flash.py

@merrymercy

Copy link
Copy Markdown
Collaborator Author

/rerun-test test_disaggregation_hybrid_attention.py test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-test test_disaggregation_hybrid_attention.py test_deepseek_v4_flash_fp4_b200_cp.py:

🚀 8-gpu-h200 (1 test): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_hybrid_attention.py

🚀 4-gpu-b200 (1 test): ❌ View workflow run

cd test/ && python3 registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

Allow breakable prefill CUDA graph replay to use consistent DP padding, preserve non-padded token accounting, and carry logprob metadata through replay.

Co-authored-by: Lianmin Zheng <[email protected]>
@merrymercy
merrymercy force-pushed the prefill-bcg-dp-attention branch from 6d9658c to 908d534 Compare July 12, 2026 13:02
@merrymercy
merrymercy merged commit b94ac87 into main Jul 13, 2026
524 of 569 checks passed
@merrymercy
merrymercy deleted the prefill-bcg-dp-attention branch July 13, 2026 00:10
@nvpohanh

Copy link
Copy Markdown
Collaborator

cc @YAMY1234 for vis

alisonshao added a commit that referenced this pull request Jul 14, 2026
TestDSV4FlashFP4BreakableCudaGraphB200.test_determinism_temp_zero is
flaky in per-commit CI ('Paris.' != 'Paris'): under this recipe (TP4/DP4/
DeepEP/DP-attention) a single request leaves the other DP ranks idle, and
#30898's idle-rank path replays the breakable prefill CUDA graph with a
fabricated dummy extend whose hidden states vary run to run, perturbing
the real request's logits through the shared EP grouped GEMMs at capture
buckets 4/16 (bisected to #30898; hammer shows ~50% of identical temp-0
request pairs diverge).

Skip the test to unblock CI while a proper fix that keeps BCG enabled is
developed. A reserved-req_to_token-row attempt did not resolve the
nondeterminism, so the real source (likely the captured-metadata refresh
or grouped-GEMM composition on the dummy-extend rank) needs deeper work.
The other tests in the class (gsm8k accuracy, sanity, accept-length) still
run.
alisonshao added a commit that referenced this pull request Jul 14, 2026
# Prefill breakable CUDA graph requires every DP rank to run the SAME
# captured shape. Under SUM_LEN each rank pads to its own local token
# count and can select a different capture bucket, so the in-graph DP
# collectives (all_gather / reduce_scatter) mismatch across ranks and

@merrymercy merrymercy Jul 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is likely wrong. it is for some a2a backend, see #30450

@Promisewjx

Copy link
Copy Markdown
Contributor

Hi. One concern about the idle-rank handling on skewed batches.Once MAX_LEN is forced, the idle rank becomes a dummy request covering num_tokens, and num_token_non_padded is set to the padded count.

With global_num_tokens = [4096, 0, 0, 0] that costs:
Since the count is the padded value, _mask_topk_ids_padded_region masks nothing, so the dummy tokens are actually routed through the MoE all-to-all and computed by the experts. With 3 idle ranks the global expert workload becomes ~4x the real one.
I'd like to keep everything about the dummy request (bs=1 skeleton, padding, bucket, MAX_LEN) but leave num_token_non_padded at 0 for non-hybrid idle ranks. The eager attention ops already slice by num_token_non_padded_cpu, so the idle rank skips attention while still joining every DP / MoE collective with masked rows — the same mechanism partially-loaded ranks already use, and what decode idle ranks already do today (num_token_non_padded == 0 with full padded buffers). The attention entry points need an early return that zeroes the output buffers first, since they come from torch.empty.

Do you think I can submit the relevant pull request?

@merrymercy

Copy link
Copy Markdown
Collaborator Author

yes, please submit a pr and do comprehensive tests. If you can test with many a2a backend, we can consider accepting it.

@Promisewjx

Copy link
Copy Markdown
Contributor

ok,I will submit a pr soon.

@Promisewjx

Promisewjx commented Aug 7, 2026 via email

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fastfail deepseek run-ci CI: run the baseline test suite on this PR run-ci-extra CI: also run the extra suite (requires run-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants