← Back to Pull requests

feat: model SGLang's prefill admission controls and shortest-prefill-first in replay #1148

Open
simone-chen opened this pull request with 650 lines diff across 8 files
View on GitHub
simone-chen simone-chen commented on Dec 03, 2026 06:59 UTC
Author

Depends on #1120, and through it on #1104; must merge after both. This PR is stacked on #1120's branch (aisim-sglang-overlap-first-token), which is stacked on #1104's.

What

SGLang v0.5.23 has three controls that admit new requests in fewer, larger prefill batches. Replay modeled none of
them. They are now opt-in fields on workers.<role>.scheduler (native sglang.*). Unset, admission and the serialized
config are unchanged.

| field | SGLang flag | behaviour (v0.5.23, 297e54fd) |
|---|---|---|
| min_free_slots_delay: N | --min-free-slots-delay | While requests run and no prefill chunk is in flight, admit no new request until N running-request slots are free (min_free_slots_delayer.py, scheduler.py:4103-4113). Capped at max_sequences; 1 or less disables it. |
| prefill_max_requests: N | --prefill-max-requests | At most N requests in one prefill batch, a continuing chunk included (schedule_policy.py:1398-1399). |
| prefill_delayer: {max_delay_passes, queue_min_ratio, max_delay_ms} | --enable-prefill-delayer and its controls | See below (prefill_delayer.py). |

How the prefill delayer works:

  • When it holds: once a candidate fits, it holds the pass's new admissions while either condition is true:

  • - free slots are fewer than the largest of the last 16 prefill batches;
    - with queue_min_ratio, the waiting queue is shorter than min(floor(running x ratio), prefill_max_requests).
  • Limits: the first hold is skipped, and a hold lasts at most max_delay_passes - 1 passes.

  • Ending a hold:

  • - the queue condition lapses after max_delay_ms, measured in simulated time;
    - a pass with no candidate ends the hold;
    - passes blocked by prefill_decode_interval neither count nor end a hold, because SGLang skips the delayer there.

    How the delays count the running batch:

  • Count: with #1120's overlap_output_release, a request whose last forward finished it is still in SGLang's

  • running batch while the next batch forms (len(running_batch.reqs), scheduler.py:4103;
    running_batch.batch_size(), schedule_policy.py:1449). The delays count it too.
  • Rejected: other backends, disaggregated decode workers and AFD.

  • - min_free_slots_delay and the delayer are also rejected with pipeline parallelism, as SGLang does
    (validation_hook.py:165-169).
    - The delayer also needs attention_data: 1, because SGLang negotiates it across the DP group.
  • Not modeled: the delayer's token-usage low watermark and DFlash's automatic min-free-slots threshold.
  • Shortest-prefill-first

    workers.<role>.scheduler.schedule_policy: shortest_prefill_first (native sglang.schedule_policy) models SGLang's
    --schedule-policy shortest-prefill-first (v0.5.23 schedule_policy.py):

  • Order: on a pass that may admit, the waiting queue is sorted by:

  • - duplicate short prefix first;
    - then max(1, input + output - matched) uncached tokens (:398-416);
    - then queue entry. Every enqueue stamps the entry, a retracted request's re-enqueue included (scheduler.py:3493-3494,
    :4539-4540).
  • Continuing chunk: it is capped to leave page-rounded room for shorter waiting requests (:418-438,

  • scheduler.py:4176-4184).
  • Second chunk: none starts while one is unfinished (:1646-1652).

  • When the queue is ordered: only on passes that may admit, as SGLang reaches calc_priority only then

  • (scheduler.py:4100-4131). That excludes passes with a full batch, an empty queue, a min-free-slots delay, no free
    slot or a deferred prefill.
  • Requirements: prefix caching; rejected on decode workers, AFD and other backends.

  • Unchanged: unset and fcfs keep the native FIFO path.
  • Docs: docs/replay/engine/workers.md has the field table rows and the "SGLang prefill admission controls" and "SGLang shortest-prefill-first" sections. The
    new crates/core/src/engine/scheduler/sglang/admission.rs translates SGLang's delay logic, and policy.rs its SPF sort
    and chunk cap. Both are attributed in THIRD_PARTY_NOTICES.md, and the notice copies are byte-identical.

    Evidence

    E2E replay of the 26 InferenceX AgentX points for Qwen3.8-Flash-Next (whole agent sessions, host CPU overhead on).
    The rules were recorded before scoring. The full results are in
    benchmarks/evidence/accuracy/qwen38-sglang-admission-spf.md
    (scoring commit 1433d669a).

  • Scope: five GB300 TP1 points set these flags.

  • - c20 and c36: min_free_slots_delay: 2 and shortest-prefill-first.
    - c56 and c80: also prefill_max_requests: 4 and the delayer, with ratios 0.2 / 0.1 and 300 ms.
    - c8: shortest-prefill-first only.
  • Build: this change on the campaign's current model build.

  • Gates: TTFT 10 % and TPOT 5 %, plus 1 point.
  • The 21 other points are bit-identical.

    | | TTFT e2e | TTFT p5-p95 | TPOT e2e | TPOT p5-p95 | all four |
    |---|---|---|---|---|---|
    | flags unset | 20 | 17 | 17 | 19 | 12 |
    | admission controls only | 20 | 19 | 20 | 21 | 13 |
    | admission controls + shortest-prefill-first (this PR) | 19 | 21 | 19 | 21 | 14 |

    At the flagged points (error %, unset -> this PR):

    | point | TTFT e2e | TTFT p5-p95 | TPOT e2e | TPOT p5-p95 | TPOT pred/sil |
    |---|---|---|---|---|---|
    | GB300 c8 | 9.5 -> 16.6 | 21.7 -> 8.6 | 4.5 -> 4.4 | 4.7 -> 4.8 | 1.045 -> 1.044 |
    | GB300 c20 | 5.3 -> 22.7 | 46.3 -> 12.8 | 9.0 -> 6.2 | 9.2 -> 5.4 | 1.090 -> 1.062 |
    | GB300 c36 | 11.7 -> 8.9 | 85.6 -> 10.3 | 2.4 -> 1.1 | 2.9 -> 2.1 | 1.024 -> 0.989 |
    | GB300 c56 | 1.7 -> 4.1 | 21.5 -> 5.3 | 7.8 -> 2.1 | 9.7 -> 3.6 | 1.078 -> 1.021 |
    | GB300 c80 | 9.5 -> 9.9 | 15.9 -> 6.5 | 9.6 -> 5.1 | 10.6 -> 6.1 | 1.096 -> 1.051 |

    What the controls change:

  • Prefill passes per request now track the server's at c20-c80: replay was 0.26-0.34 above the measured count and is

  • now within 0.01-0.08 of it. Fewer prefill passes interrupt decode, so TPOT e2e error falls at all four.
  • TTFT shape: shortest-prefill-first moves queue wait from short requests to long uncached ones, as on silicon. The

  • short-request p50 TTFT gap falls from 0.9 s to 0.14 s at c20 and from 2.3 s to 0.05 s at c36. The p5-p95 TTFT error
    falls at all three points that set it.

    Accepted rule exception (owner's decision). At c20, shortest-prefill-first raises TPOT pred/sil from 1.026 (admission
    controls alone) to 1.062. That breaks this change's pre-declared rule that TPOT must not move by more than 2 SE and 1
    point (+3.6 points against 3.0). The owner kept it anyway: about 5 points of c20's TPOT over-prediction is a truth
    caveat, not a model error.

  • The GB300 measurements ran an SGLang nightly whose decode iterations are about 5 % faster than the v0.5.23 release this

  • replay models.
  • So even an exact v0.5.23 model would read about 1.04-1.05 at that point.

  • The rise comes from the smaller chunk passes that the continuing-chunk cap creates, which SGLang runs as well.
  • Tests

  • cargo test --workspace: 4,080 passed, none failed, at a1f9a5005. The two later commits change only tests.

  • - At the head, the SGLang scheduler, config and rank tests pass (711).
    - The new test fails when the gate's min-free-slots check is removed.
  • pytest -c pytest.ini tests: everything this change touches passes. The 35 local failures need modules not

  • installed in the local venv (sklearn, requests, collector, pip-licenses, cryptography) or the manylinux
    toolchain.
  • pytest -c python/aisim/pytest.ini python/aisim/tests -m "unit or build": 24,576 passed before SPF was added. The

  • local failures are in collector, onboarding and CLI-binary tests that this change does not touch.
  • New Rust tests, admission controls:

  • - each control alone and the free-slot threshold;
    - the delayer's skip, cap, queue ratio, time cap and end-of-hold rules;
    - a continuing chunk that runs while the delayer holds;
    - interval-blocked passes during a hold;
    - finishing requests counted in the running batch.
  • New Rust tests, shortest-prefill-first:

  • - the CLI value, the order (least uncached work first, queue-entry ties, duplicate prefixes last, generated tokens
    counted);
    - the chunk cap and its stop cases, and the second-chunk refusal;
    - a retracted request re-stamped;
    - host-cached tokens under HiCache;
    - the queue left unordered on passes that cannot admit (no free slot, a min-free-slots hold).
  • New Python tests: config round-trip and validation, lowering for aggregated and PD workers, and end-to-end replay

  • through the native scheduler.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: None requested Review duration: 2924m
    All Vouch review confidence checks passed
    Residual risk 0.36 = Change Risk (0.64) × (1 − Review Confidence (0.44)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.64 · 650 lines diff across 8 files
    0.64
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 10%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    No Reviewer Assigned no_reviewer_assigned
    0.120
    Real PR Conversation Timeline
    1 comments
    "Review active on #1148"
    general weight: 0.35
    Reviewers
    None requested
    Assignees
    simone-chen simone-chen
    Labels
    risk: medium confidence: 44.2% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 64% (MEDIUM) · Higher = larger blast radius
    64%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.2% · Lower = rushed or shallow review
    44.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 35.7% · Moderate risk
    35.7%