Skip to content

[CP] Automatically enable BCG for supported prefill CP configurations - #44022

Merged
Fridge003 merged 8 commits into
sgl-project:mainfrom
Fridge003:codex/auto-enable-prefill-cp-bcg
Oct 14, 2026
Merged

Fridge003 merged 8 commits into
sgl-project:mainfrom
Fridge003:codex/auto-enable-prefill-cp-bcg

Conversation

@Fridge003

@Fridge003 Fridge003 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Supported prefill context-parallel configurations should select breakable CUDA graphs automatically. DSV4 is temporarily excluded because its CP BCG capture path does not shard token IDs consistently with hidden states for hash routing.

Modifications

  • Centralize supported (ContextParallelStrategyKind, CPAttentionBackendKind) pairs in layers/cp/bcg.py: zigzag + TRT-LLM MHA. Keep the DSV4 backend enum, but exclude interleave + DSV4 until the capture input-ID mismatch is fixed.

  • Keep automatic prefill BCG selection and compatibility checks in cuda_graph_hook.py::apply_prefill_cp_cuda_graph_default. The resolution pipeline invokes this hook immediately after context-parallel configuration resolves, only when enable_prefill_cp is enabled, retaining the existing CP=TP and PP=1 requirements and explicit user backend choices. parallel_hook.py is unchanged by this PR.

  • DSV4 remains disabled by default while it is absent from the supported set. Preserve other compatibility restrictions, PD role rules, and DeepEP bucket alignment.

  • Remove the explicit BCG flags from the GPT-OSS CP test and delete test_dsv4_prefill_cp_bcg.py as requested.

  • Defer the CP-related BCG warning until apply_prefill_cp_cuda_graph_default finishes; warn only if the resulting prefill backend is not breakable. Early CP auto-disable remains silent so supported configurations do not log a misleading disable/enable sequence.

Accuracy Tests

  • 15 existing CP/CUDA Graph server-argument tests passed after restoring the server-args test file.
  • 24 existing CP strategy and BCG replay unit tests passed.
  • 10 resolution-hook registry tests passed.
  • Verified the relocated policy is AST-equivalent apart from import placement and its diagnostic source label; 3 temporary configuration regression tests passed without modifying repository tests.
  • All applicable pre-commit checks passed.
  • GPU inference/accuracy tests were not run locally (macOS development host).

Speed Tests and Profiling

Not run; no kernel or model-forward implementation changes.


CI States

Latest PR Test (Base): ❌ Run #38495427918
Latest PR Test (Extra): ❌ Run #38495428025
Latest PR Test (AMD ROCm 10): ❌ Run #38495428053

@Fridge003

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ❌ View workflow run

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

non_mechanical_provable: change resolution order so CP default selection precedes shared graph policies, and budget static memory from the resulting graph configuration.
@Fridge003

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ❌ View workflow run

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

@Fridge003

Copy link
Copy Markdown
Collaborator Author

/rerun-test test/registered/cp/test_gpt_oss_4gpu_mxfp4_cp.py test/registered/cp/test_deepseek_v4_flash_fp4_b200_cp.py

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

🚀 4-gpu-b200 (2 tests): ✅ View workflow run

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

@Fridge003
Fridge003 merged commit 536d065 into sgl-project:main Oct 14, 2026
105 of 121 checks passed
nvpohanh added a commit to akhilg-nv/sglang that referenced this pull request Oct 14, 2026
Resolve the modify/delete conflict on
test/registered/unit/layers/cp/test_dsv4_prefill_cp_bcg.py by keeping its
deletion from sgl-project#44022; the PR's one-line `trtllm_attn=False` mock edit there is
no longer needed. Also picks up the main commit required by the CI
maintenance rebase gate (c053fc7, sgl-project#21065).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@AMD-yanfeiwang

Copy link
Copy Markdown
Contributor

@Fridge003
Thanks for this PR and for pinning down the DSV4 input-ID issue so clearly. We ran into the same mismatch while porting #38603 to ROCm, and fixed it in the shared CP BCG path in #43819 (building on #40333). Sharing it here in case it helps.

Cause: unlike eager CP (cp_shard_model_inputs), the BCG capture path passed the global token-order input_ids to the body and never set input_ids_global, so DSV4's hash-routed MoE layers got ids that didn't match the CP-sharded hidden rows.

Fix: PrefillCPBCGInput now gives the captured body the same inputs as eager CP, from fixed-address buffers: CP-local input_ids and positions, and input_ids_global in eager CP's layout (rank-major for TP MoE, local for a2a). Nothing here is platform-specific.

ROCm results (DeepSeek-V4-Flash TP4, MI355X): without the fix, CP+BCG fails during graph capture with exactly this mismatch (hash_topk.py: input_ids.shape=[28], hidden_states.shape=[32, 4096]). With the fix it serves normally: GSM8K 0.9682 vs 0.9712 for eager CP (±0.005).

It would be great if CUDA and ROCm could share the same fix rather than diverge. Would you be open to this approach for CUDA as well? If so, #43819 can re-enable (INTERLEAVE, DSV4) for both platforms (it's currently ROCm-only), or we can split the shared fix into a small separate PR, whichever is easier for you to review. Happy to adjust either way.

AMD-yanfeiwang added a commit to AMD-yanfeiwang/sglang that referenced this pull request Oct 14, 2026
… for DSV4 on ROCm

sgl-project#44022 dropped (interleave, dsv4) from the supported CP BCG combinations
because the capture path did not shard input_ids with the hidden states for
DSV4 hash routing. This branch fills input_ids_global from the CP BCG input
buffers, so add the combination back on ROCm, where it is validated. CUDA
keeps it disabled until the same path is validated on B200.

Restore test_dsv4_prefill_cp_bcg.py with the DSV4 CP BCG checks and make the
supported-configuration check follow the platform.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants