Skip to content

[Spec][PP] Launch extend microbatches before the spec output exchange - #40499

Merged
YAMY1234 merged 2 commits into
sgl-project:mainfrom
YAMY1234:pp-verify/pp-spec-extend-launch-first-main
Sep 21, 2026
Merged

YAMY1234 merged 2 commits into
sgl-project:mainfrom
YAMY1234:pp-verify/pp-spec-extend-launch-first-main

Conversation

@YAMY1234

@YAMY1234 YAMY1234 commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Under pipeline parallelism with speculative decoding (SGLANG_ENABLE_PP_SPEC=1), every non-last stage receives the previous result dict from the ring before launching its own forward. A verify round needs that order: it rebuilds its tree from the relayed accept results and host-syncs on the previous stage's proxy, which that stage only sends after its own exchange.

For extend (prefill) microbatches the order is not needed, and with pp_async_batch_depth=0 it is expensive: stage 0 cannot launch slot j+pp_size-1 until the last stage has finished slot j, so each stage runs at most pp_size-1 forwards per ring round trip. That caps every stage at (pp_size-1)/pp_size utilization (75% on PP4, 50% on PP2) regardless of layer balance, concurrency or CUDA graphs. The non-spec loop already launches first.

Measured per-step period matches sum(stage kernel time)/(pp_size-1) + CPU overhead on Qwen3.5-397B PP4 (387 vs 398-407 ms), DeepSeek-V4-Flash PP4 (196 vs 197-200 ms) and V4-Flash TP2xPP2 (404 vs 455 ms).

Modifications

  • scheduler_pp_mixin.py: _pp_exchange_outputs_before_forward() decides per microbatch. Extend microbatches launch first (as in the non-spec path); verify rounds and pp_async_batch_depth > 0 keep the exchange-first order; the last rank always launches first.
  • scheduler.py: after an extend round the worker returns batch.seq_lens itself as new_seq_lens; skip the redundant host copy, which otherwise blocks the scheduler on the forward stream until the whole forward has run.

Results (GB300, Qwen3.5-397B-A17B-FP8, TP1xPP4 + MTP, prefill-only ISL 8192 / OSL 1, C=64, chunk 32768)

arm tok/s/GPU (3 runs, median) per-stage step period
before 20,322 396 ms (p10-p90 312-450)
launch-order fix only 24,662 (+21%) 313 ms (p10-p90 310-315)
+ skip redundant seq_lens host copy (this PR) 25,205 (+24%) 306 ms (p10-p90 290-308)
DEP4 + MTP reference 20,157 396 ms

DeepSeek-V4-Flash TP1xPP4 + MTP (same workload, layer partition 11,11,11,10): 39,128 -> 45,882 tok/s/GPU (+17%), per-stage period 197 -> 160 ms. Same-config re-runs on Qwen3.8-Flash-Next (+31%), GLM-5.3-Flash (+35%), DeepSeek-V4-Flash + DSpark (+23%) and Kimi-K3 + DSpark (+30%, 2 nodes) show the gain is model-independent; TP2xPP2 arms gain +70% to +107% because their cap was 50%.

Rank 0 trace: result-dict receive moved from before the launch (128/128 steps, median 307 ms blocked) to after it (160/160 steps); compute-busy 67% -> 84%. Decode (verify) rounds are unchanged by construction.

Checklist

  • One regression case in test/registered/unit/managers/test_pp_cp_rank_offsets.py pins extend-launches-first / verify-exchanges-first (a silent revert would cost 25% throughput with every functional test green).
  • GPU throughput A/B above; PP4 + MTP output token count and request success unchanged.

CI States

Latest PR Test (Base): ✅ Run #35548730272
Latest PR Test (Extra): ❌ Run #35548730174
Latest PR Test (AMD ROCm 10): ❌ Run #35548730269

Under PP+spec every non-last stage received the previous outputs before
launching its forward. For a verify round that order is required (the
launch rebuilds its tree from the relay), but for extend microbatches it
makes stage 0 wait for the last stage's result of the microbatch launched
pp_size-1 slots earlier, so with pp_async_batch_depth=0 each stage runs
at most pp_size-1 forwards per ring round trip: (pp-1)/pp utilization,
i.e. 75% on PP4 and 50% on PP2 regardless of layer balance.

Extend microbatches consume nothing from the relay, so they now launch
first exactly like the non-spec loop; verify rounds keep the old order.
…round

In the non-overlap spec path an extend round returns batch.seq_lens
itself as new_seq_lens. Copying it back to the CPU is redundant and, since
the copy is enqueued behind the forward on the forward stream, it blocks
the scheduler until the whole forward has run. Only copy when the worker
produced a new tensor (verify rounds).
@YAMY1234
YAMY1234 force-pushed the pp-verify/pp-spec-extend-launch-first-main branch from 8e79550 to b04843d Compare September 21, 2026 00:45
@YAMY1234

Copy link
Copy Markdown
Collaborator Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Sep 21, 2026
@YAMY1234
YAMY1234 merged commit 0229025 into sgl-project:main Sep 21, 2026
366 of 410 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant