Skip to content

[PD] Improve optimistic prefill - #30951

Merged
cctry merged 4 commits into
mainfrom
cctry/sglang/optimistic-prefill-sched
Jul 12, 2026
Merged

cctry merged 4 commits into
mainfrom
cctry/sglang/optimistic-prefill-sched

Conversation

@cctry

@cctry cctry commented Jul 12, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  1. Adaptive yield: an optimistic prefill no longer gives up at every chunk boundary but it yields only when a bootstrap-finished request is waiting for the batch.
  2. Reframe retry to attempt: counting total optimistic forward passes instead of requeue. Previously retry limit is 1 means the req has two forward opportunities before bootstrap finished.
  3. Park instead of retry: a request whose prefill finishes before bootstrap completes no longer releases and requeue. It parks in the inflight queue waiting for transfer.

Fixes along the way.

  • Chunks computed while pending now store their input logprobs.
  • reset_for_retract now clears temp_input_token_ids_logprobs_val/idx.
  • Scheduler prefill log now reports #optimistic-req per batch.

CI States

Latest PR Test (Base): ❌ Run #29210525648
Latest PR Test (Extra): ❌ Run #29210525451

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the optimistic prefill retry mechanism in the disaggregation scheduler, renaming retries to attempts and tracking attempt counts directly on the request object. The code review highlights two critical issues: first, an assert statement wrapping a function with side effects (finalize_bootstrap) that could be compiled out in optimized environments, along with a missing state update for pending_bootstrap; second, a double-increment bug on prefill_attempt_count that prematurely limits the number of allowed prefill attempts.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/disaggregation/prefill.py
Comment thread python/sglang/srt/disaggregation/prefill.py
@cctry
cctry force-pushed the cctry/sglang/optimistic-prefill-sched branch from 4ced72d to feae022 Compare July 12, 2026 21:55
@cctry

cctry commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

/tag-run-ci-label

@cctry

cctry commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-group disagg

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Jul 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⛔ disagg: Unknown test group disagg.

Known groups: 4-gpu-models, 8-gpu-models, amd, ascend, attention, backends, bench_fn, chunked_prefill, constrained_decoding, core, cp, cpu, cuda_graph, dcp, debug_utils, disaggregation, dllm, dp_attn, dp_engine, ep, eplb, eval, function_call, gb300, hicache, input_embedding, jit, kernels, kv_canary, layers, lora, mem_cache, mla, mlx, mock_model, model_loading, models, models_e2e, moe, musa, observability, openai_server, ops, page_major, perf, pp, prefill_only, profiling, quant, radix_cache, reasoning, rl, rotary, sampling, scheduler, scripted_runtime, sessions, spec, stress, tokenizer, unit, utils, vlm, xpu

@cctry

cctry commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun-group disaggregation

@github-actions

github-actions Bot commented Jul 12, 2026 •

Copy link
Copy Markdown
Contributor

Results for /rerun-group disaggregation:

🚀 4-gpu-gb300 (1 test): ✅ View workflow run

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

🚀 2-gpu-h100 (3 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_basic.py
cd test/ && python3 registered/disaggregation/test_disaggregation_decode_offload.py
cd test/ && python3 registered/disaggregation/test_disaggregation_optimistic_prefill.py

🚀 8-gpu-h20 (4 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_decode_radix_cache.py
cd test/ && python3 registered/disaggregation/test_disaggregation_different_tp.py
cd test/ && python3 registered/disaggregation/test_disaggregation_dp_attention.py
cd test/ && python3 registered/disaggregation/test_disaggregation_pp.py

🚀 8-gpu-h200 (2 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_dsv4.py
cd test/ && python3 registered/disaggregation/test_disaggregation_hisparse.py

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

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

🚀 1-gpu-5090 (2 tests): ✅ View workflow run

cd test/ && python3 registered/disaggregation/test_disaggregation_xpu.py
cd test/ && python3 registered/disaggregation/test_specv2_kvcache_offloading.py

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

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

@cctry

cctry commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

https://github.com/sgl-project/sglang/actions/runs/29210654951/job/86699353345
Only failed test is known to be flaky and tracked at #30946

@cctry
cctry merged commit c616d5a into main Jul 12, 2026
128 of 146 checks passed
@cctry
cctry deleted the cctry/sglang/optimistic-prefill-sched branch July 12, 2026 22:31
tanguofu pushed a commit to tanguofu/sglang that referenced this pull request Jul 25, 2026
- Document branch base (v0.5.16 tag fdebc93) and cherry-picked commits
- List v0.5.16 new fixes (sgl-project#31075, sgl-project#30951) and already-in-base PRs
- Add SGLang + PD Router Docker build commands with correct args
tanguofu pushed a commit to tanguofu/sglang that referenced this pull request Jul 25, 2026
- README: sgl-project#31075/sgl-project#30951 already in old base (not v0.5.16 new); sgl-project#29421 is
  fork-only custom patch; add full list of v0.5.16 new fixes (GLM-5.2/ROCm/
  spec-decoding/PD) verified via git merge-base --is-ancestor
- values-1p1d-batch1.yaml: remove incompatible --enable-mixed-chunk and
  --enable-hierarchical-cache --hicache-ratio 2.0; update spec-num-steps 2->3;
  add num-continuous-decode-steps 2 and optimistic-prefill-attempts 1 to match
  actual pod YAMLs
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
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