Skip to content

scheduler: queue a first chunk behind a prefill in flight (ATLAS_PREFILL_QUEUE_FIRST_CHUNK, default-off, ported from Enntity) - #226

Merged
AzeezIsh merged 6 commits into
mainfrom
stack/qwen-queue-first-chunk
Oct 29, 2026
Merged

AzeezIsh merged 6 commits into
mainfrom
stack/qwen-queue-first-chunk

Conversation

@AzeezIsh

Copy link
Copy Markdown
Contributor

Stack: main ← #198 ← #223 ← #224 ← this. 6 commits, ported from Enntity/atlas (AGPL-3.0: 5eeeb1a, 7fd2412, dc896cc, f1cc7cb) with credit lines.

Summary

  • With the switch on, a new prompt longer than one chunk sets up at admission but queues its first chunk behind the prefills already in flight (SRPT order), instead of running it at once and delaying their remaining chunks. Prompts that fit one chunk still run at admission. A refused queued first chunk preempts like a later chunk. Scheduler-only (rank 0 decides), so no parity entry; default off.

Measurements (vs its parent, receipts on #216; git range-diff is = for all 6 commits)

  • Four cold prompts (26.7K / 19.2K / 15.2K / 15.1K tokens) arriving 1–2 s apart, streamed TTFT: the sum of TTFTs drops 19–22% and no request gets slower.
  • Outputs unchanged: greedy C1/C8 equal serial 8/8; tools 21/21; contamination PASS.

Test plan

  • host tests: queue_first 16/16, preempt 49/49
  • CUDA build of the stack top: reiner job 911

Tracking: #220, #216.

Generated with Devin

@AzeezIsh

Copy link
Copy Markdown
Contributor Author

CUDA release build of the stack top (#226 @ a1dab6554, which contains this PR) passes on reiner (job 911). git range-diff against the measured branches is = on every commit, so the #216 receipts apply unchanged.

… prefill in flight

Every new prompt ran its first chunk at admission, ahead of the remaining
chunks of the prompts already prefilling. Four ~18K-token prompts arriving
a second apart at 16K-token chunks (qwen4_exp TP2/EP2) ran all four first
chunks before any 1.7K-token tail: first tokens 16-18.5 s after the first
arrival for all four, where FIFO prefill gives 5.6/10.2/14.7/19.3 s.

With ATLAS_PREFILL_QUEUE_FIRST_CHUNK=1 (default off) on a multi-rank
world, a prompt admitted while a prefill is in `prefilling` does its setup
(grammar, sequence, the worker's MTP fence, vision state and shared-prefix
plant) but no chunk and no prefill command, and joins the queue at its
`queue_order` position with `queued_first_chunk = Some(len)`. The continue
phase runs that chunk when the prompt is the head: the inline chunk's
command, `prefill_chunk` from 0, first-chunk normalization and failure
handling, never the two-phase prefill (which sends the worker nothing).
The head sends each chunk command right before running that chunk, so the
worker runs every prompt's chunks in the head's order.

`start_chunked_prefill` takes `FirstChunk::{Inline, Defer, Queue}` instead
of `defer: bool`. Deferrals (co-dispatch, VARLEN, always-mixed fuse,
multi-prompt prefill) keep precedence; image prompts and beam searches keep
the inline chunk; nothing in flight means inline, as before. A queued
streaming request whose client is gone leaves the queue before its first
chunk (freed on every rank, no prefill command sent). Off, the scheduler
sends and runs exactly what it did.

Not built or run on hardware yet.

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

(cherry picked from commit 5eeeb1a of Enntity/atlas; hand-resolved:
prefill_a_step.rs keeps our FirstChunk param and its deferred branch was
rewritten to first_chunk != Inline / == Defer / == Queue rather than the
upstream bool; the shared phase/queue_first files land in the dc896cc and
f1cc7cb commits that complete them)
ATLAS_PREFILL_QUEUE_FIRST_CHUNK queued every prompt admitted behind a
prefill in flight, including one that fits a single chunk: with SRPT off it
went to the back and waited behind every remaining 16K chunk of a long prompt
(tens of seconds behind a ~200K prefill), where without the lever it finishes
at admission. queue_first::first_chunk now takes one_chunk (the prompt fits
the admission's chunk budget: start_chunked_prefill's first chunk is then the
whole prompt), and such a prompt keeps the inline chunk. The SRPT test's
short newcomer is now an 18-token (two-chunk) prompt; a new test pins a
3-token prompt behind a 200-token prefill running at admission, SRPT on or
off.

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

(cherry picked from commit dc896cc of Enntity/atlas; these files carry the
5eeeb1a and dc896cc hunks together -- their queue_first_chunk.rs hunk is in
7fd2412's commit, which creates that file)
The queued first chunk sent its command and ran the chunk itself, so an
agreed KV refusal failed the request, where every later chunk goes through
prefill_chunk_with_preemption and evicts a decoding sequence. By the time a
queued chunk runs it competes with the sequences decoding beside it exactly
as a later chunk does, so it now takes that path from offset 0 (the same
0xFFFFFFF0 command words) before the first-chunk normalization; a final
refusal still fails only its request. Its record/stream-wait errors are
logged like the inline path's instead of dropped. Tests: a retryable
refusal preempts the decoding request and reruns the chunk; a final one
fails only the queued request; a shared-prefix plant reaches the worker at
admission and the chunk command when the chunk runs.

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

(cherry picked from commit f1cc7cb of Enntity/atlas)
The real start and continue phases against `PreemptStubModel` (now with a
plain multi-rank switch, `ep`), asserted on the chunks the head runs and on
the EP worker's command words:

- a newcomer behind a prefill in flight waits for its tail, and its
  chunk-0 command reaches the worker only when the head runs that chunk
  (never the whole prompt at once: no two-phase prefill);
- off by default, the first chunk runs at admission exactly as before;
- one GPU keeps the inline first chunk with the lever on;
- a burst admitted with nothing in flight runs its first chunks in
  arrival order;
- SRPT puts a short tail ahead of a new long prompt, and a short newcomer
  ahead of a long remainder;
- a queued buffered or streaming request whose caller left is freed on
  every rank with no prefill command sent;
- a refused queued first chunk fails only its request, as an inline one
  does.

Not compiled or run yet (the Mac cannot build the CUDA crates).

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

(cherry picked from commit 7fd2412 of Enntity/atlas)
One-line // Ported from Enntity/atlas <shas> (AGPL-3.0-only) credits; plain comments, not module docs.
…the apply order

Upstream order was 5eeeb1a -> 7fd2412 -> dc896cc -> f1cc7cb, but I applied
7fd2412 last, so dc896cc's and f1cc7cb's hunks to preempt_tests/
queue_first_chunk.rs silently dropped. The file is now f1cc7cb's content
(admit_planted, the 18-token SRPT case, the one-chunk-at-admission case,
the KV-refusal preemption case). Production files verified byte-identical
to upstream f1cc7cb apart from credit lines.
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.

1 participant