Repository navigation
Conversation
Signed-off-by: LyxWxj <yuxuanlou621@foxmail.com>
Signed-off-by: LyxWxj <yuxuanlou621@foxmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Required human contributor answers
The contributor has identified Dory adaptation as the primary objective. The
answers and necessity decision below are proposed wording for contributor
review, informed by RFC #176 and the implementation; they do not by themselves
complete the human-contributor gate. The contributor must confirm them and
provide a precise, accessible source for the confirmed answers and decision
before submission.
1. What outcome are you trying to achieve?
Enable the new Dory model to use staged chunked prefill while preserving its
attention-bearing PRELUDE and CODA semantics, including prompt CODA KV. This
increment adds the execution and scheduling foundations for per-request fixed
loop counts, loop-level batching, WCPB, and continuous admission/completion.
The broader RFC #176 PR 2A goal also includes ordinary mixed prefill/decode;
automatic batching of prompt and decode CODA remains a follow-up, as does
heterogeneous-loop atomic prefill.
Supporting context: RFC #176 PR 2A and the scope of this increment below.
2. What is the highest-leverage variable for that outcome?
A candidate highest-leverage variable is the runtime's correctly
schedulable Dory prefill frontier: whether each prompt chunk can advance
through PRELUDE, the requested recurrent depths, and CODA while retaining the
correct hidden and KV state. This is a prerequisite for safely admitting new
requests, batching compatible loop depths, and overlapping independent work.
The present evidence concerns correctness of those mechanisms; it does not
establish a throughput improvement.
Supporting context: RFC #176 PR 2A and the frontier and lifetime design
described below; the choice of variable needs contributor confirmation.
3. How will this work move that variable rather than create busywork?
The change moves that variable directly in the runtime rather than adding only
model metadata or documentation:
requires_prefill_codamakes the model's stage contract explicit for Doryand Huginn.
PREFILLING_CODA, separate recurrent/CODA frontiers, and chunk reclamationmake the scheduler advance only after the required causal work is complete.
depths share weights and compatible recurrent batches.
row-aligned logits masks avoid projecting unused prompt rows.
when independent recurrent and CODA work uses different CUDA streams.
The focused CPU and A100 tests exercise these transitions, mixed depths,
selected logits, cancellation, multi-stream execution, and a real Dory
checkpoint. No performance improvement is claimed until matched serving
benchmarks are completed.
Supporting context: implementation and validation described in this draft;
RFC #176 PR 2A.
4. Who is the customer or user, and what do they actually need?
The likely users are maintainers and operators serving Dory through the common
vllm-rlt engine, and their downstream inference users. They need the engine to
preserve Dory's PRELUDE/recurrent/CODA computation, support fixed per-request
loop targets and concurrent requests, and retain the correct attention KV and
hidden state as chunks are interleaved. Downstream users need correct prompt and
decode outputs without managing internal scheduler phases or hidden-state ring
slots. Huginn also benefits because it has an attention-bearing prompt CODA,
but Dory is the primary adaptation target.
Supporting context: RFC #176 PR 2A and the implementation's model scope;
the customer and their priorities need contributor confirmation.
PR necessity and bugfix evidence
Proposed decision: yes, a PR is needed; contributor confirmation is pending.
The base runtime cannot provide the required staged Dory behavior merely by
changing configuration: it lacks the prompt-CODA phase and its associated
frontiers and hidden-state lifecycle.
Observed capability gap, reproduced locally: using the same tiny Dory
configuration, per-loop KV and
mode="mixed", constructing aStageEngineat base
ce200f0d2085fb041c66691245e29aef2a9ed714raises:At head
965ac96f09fa8bc0aa4d961a80e01fe0cd4d626d, the same constructionsucceeds with
staged_prefill=True. The localreproducer and
captured base/head output record the code
snapshots and observed result; these Git-ignored artifacts must be published or
attached before submission. Construction alone is not inference-correctness
evidence: the staged-versus-atomic tests and real-checkpoint checks listed
below provide additional, separately scoped coverage.
This is a feature adaptation, not a regression fix to a previously
supported Dory staged-prefill path. The cross-stream scratch experiment in
artifacts/dory-pr2-a100/stream-scratch-20261123.logis supporting evidence forwhy submission-owned hidden buffers are required: with an intentionally
injected delay, a counterfactual shared-buffer alias corrupts an independent
request's input, while the implementation's separate buffers do not. It is not
presented as an observed failure in a previously supported production path.
Purpose
Dory and Huginn have attention-bearing output stages. A prompt chunk is not
finished when its final recurrent loop finishes: its output-stage attention
must also populate the CODA KV for that chunk. This change introduces that
causal phase into staged prefill and makes it usable with the existing WCPB and
loop-level scheduling machinery, while keeping the scope to synchronous eager
generation with per-loop KV and retained history.
What this increment changes
requires_prefill_codafor Dory and Huginn and add thePREFILLING_CODAruntime phase. Models such as Ouro, which do not declare thecapability, continue to finish a prompt chunk at the final recurrent depth.
their respective causal frontiers. Dory retains the injection input alongside
the recurrent state across the loop calls.
mixed recurrent depths. Compatible prefill/decode recurrent spans may share
a model call, and WCPB can also batch compatible prelude work. Continuous
admission and completion remain supported.
target_loopsbetween1andtotal_ut_steps; when omitted, it defaults tototal_ut_steps. Different target depths share model weights. Trace moderetains its separate trace-driven exit semantics. Huginn retains its existing
loop/exit policy; this PR does not turn Huginn into a fixed-loop model.
inputs across different execution streams and in-flight submissions.
Design decisions and reviewer questions
1. Who advances chunk frontiers, and who owns hidden state?
The scheduler owns request queues and logical progress;
ModelRunnerowns thedevice-resident hidden-state storage, gather/scatter, execution streams, and
completion events. The scheduler distinguishes:
For models requiring prompt CODA,
num_recurrent_prefilled_tokensis thecontiguous final-recurrent-depth frontier and
num_prefilled_tokensis thecontiguous CODA frontier. A chunk's
prefill_reclaimable_tokensboundary movesonly when the whole chunk passes its final required stage. These are logical
frontiers; device consumers are ordered by events rather than assumed complete
merely because the host has submitted them.
2. Why a model capability instead of a per-model terminal-phase enum?
requires_prefill_codaexpresses the model behavior that drives the extrastage. The shared scheduler and executor use it to select the completion and
retention behavior; models do not each provide a separate prefill-terminal
phase. This also covers Huginn's existing attention-bearing CODA instead of
introducing a Dory-only path. Without the capability, final recurrent completion
remains the prompt-chunk completion boundary.
3. When are logits calculated, and what about mixed CODA?
All eligible prompt rows execute attention-bearing CODA so their KV history is
valid. Non-final prompt rows do not need logits or samples; the final prompt
row produces the first output token directly in
PREFILLING_CODA. It doesnot require a redundant ordinary CODA just to sample that token.
ForwardBatch.compute_logitsaccepts either a uniform boolean or a row-alignedboolean mask. For a chunk-bearing CODA batch, only the last row of a final
prompt span and ordinary decode CODA rows are selected. Sparse results are
mapped back to the appropriate request spans. Tests exercise mixed
PREFILLING_CODA/CODAexecution by explicitly selecting both phases;automatic scheduling of those two phases into one batch is not implemented
and remains a later increment. Existing ordinary CODA behavior is preserved.
4. How are WCPB chunk offsets and hidden-state lifetime handled?
WCPB maps a logical chunk to a per-request ring slot relative to
prefill_window_origin:CODA reads only rows that have passed the final recurrent frontier and does not
cross the chunk boundary. Partial chunks retain their slot until CODA consumes
the whole chunk.
prefill_statesis the cross-stage per-request store;BatchInputBuffers.hiddenis submission-local, contiguous model input gatheredfrom those rows and, for mixed batches, ordinary
request.hidden_staterows.Physical staged storage is currently reserved using
prefill_chunk_size * total_ut_stepsrows per request; the ring's logical slotcount for fixed-depth Dory follows that request's target loop count. Although
the ring formula has an origin, boundary-KV prefix caching is still rejected.
5. Why does each in-flight batch own its hidden scratch?
With
multi_stream=True, recurrent submissions use the core stream and promptCODA uses the boundary stream. For the same request, the next submission
waits for the preceding request event. For different requests, a CODA batch
and a recurrent batch may overlap; request-local dependencies do not protect a
single scratch tensor shared by both. Before this change, ordinary decode CODA
read request hidden state through its own gather/workspace path, not the
staged-prefill scratch.
The prior single
ModelRunner.prefill_hiddenis therefore replaced bysubmission-owned
BatchInputBuffers.hiddenbuffers. They rotate with theexisting two submission slots, and a slot is not reused until its consumer
event has retired. This preserves inter-request overlap without treating the
scratch buffer as long-lived request state. The additional allocated scratch
relative to the old single-buffer design is one batch-sized hidden tensor;
there is no throughput claim without a matched benchmark.
6. What happens when atomic prefill requests have different loop counts?
This increment supports differing request targets for staged Dory prefill.
Ordinary atomic prefill still rejects a Dory request target below the model's
configured full depth; it does not silently run all requests to the wrong
depth. Handling mixed request targets inside one atomic prefill batch remains a
follow-up.
target_loopsis not a general adaptive exit mechanism.Scope and limitations
full history. Multi-stream execution is separate from asynchronous
scheduling and remains event-ordered.
preemption, speculation, prefix reuse, shared/last-loop KV, or PD handoff is
not qualified and is rejected where the runtime enforces that restriction.
Ordinary non-staged capabilities are not claimed as coverage for these
combinations.
atomic prefill, hybrid KV reclamation, complete-state prefix reuse, and
long-context qualification remain outside this increment.
improvement. The required matched unprofiled serving benchmarks, ops-only and
full profiles, bottleneck attribution, and post-implementation refactor
review have not been completed.
Test Plan
vllm-rlt Version / Commit:
965ac96f09fa8bc0aa4d961a80e01fe0cd4d626d.ce200f0d2085fb041c66691245e29aef2a9ed714(origin/main),fetched again on 2026-11-23; it is already an ancestor of the tested head.
2.14.0+cu130, projectvirtual environment,
OMP_NUM_THREADS=1.590.48.01, Python3.12.13,PyTorch
2.13.0+cu130, Triton3.7.1; one explicitly selected device.Commands run on the tested head:
The CPU hook does not qualify CUDA/NPU paths. The focused GPU run uses an
isolated source snapshot of the tested commit; the shared host did not have the
gpureservation utility, so the selected A100 was checked idle first.Test Result
python -m ruff check .: passed.pre-commit run --all-files: Ruff lint, Ruff format, and the CPU regressionhook passed. GPU/NPU-marked tests were not enabled in that hook.
prefill, WCPB on/off, multi-stream variations, and the real-checkpoint mixed
fixed-depth comparison.
35 skipped, 895 deselected, and 43 focused GPU passed. No Ascend/NPU
hardware test was run.
Dory1.0-4B-BF16,model.safetensorsSHA-256207483664dfef54c4c4438863260d3ba423bf3d6009b43fe84264b281e9fda23;checkpoint revision was not independently verified. With five- and ten-token
prompts, chunk size 2, target depths 1 and 2, and three greedy tokens, mixed
and WCPB outputs/depths match independent atomic-chunk runs. Reference top-20
logit overlap is 20/20 for the shallow request and 19/20 for the full
request; the largest reported top-20 difference is
0.1500. This is aruntime-to-runtime comparison, not an independent quality benchmark.
delayed B recurrent submission, A's prompt-CODA gather completed while B was
still in flight. The current separate buffers preserved B's input exactly;
forcing the two scratch tensors to alias in the diagnostic changed B's input
(maximum absolute difference
0.5827). This counterfactual is not aproduction configuration or a model-quality result.
The local run logs and the scratch diagnostic script are under the Git-ignored
artifacts/dory-pr2-a100/; the precision investigation and raw measurementsare under
artifacts/dory-pr2-a100/numeric-investigation/. They must be madeaccessible to reviewers before the PR is submitted.
Numerical precision investigation
The same local BF16 checkpoint was compared on A100 with chunk size 2. The
FP32 comparison converts the stored BF16 weights to FP32; it is not an original
FP32 checkpoint. Maximum differences below are on the reference top-20
logits, not all vocabulary rows:
0.15000.00000760.40150.0000048Both comparisons keep the first greedy token in this small diagnostic. For the
41-token BF16 case, however, full-vocabulary maximum difference is
0.5827and softmax total variation is
0.0563; matching argmax is not distributionalequivalence. The existing automated
0.25top-20 bound applies to its specific10-token test and is not established as a universal tolerance.
In the 10-token mixed case, the first differing activation is a PRELUDE
o_projoutput: input, weights, attention output and K/V for the inspected roware equal, while changing only the BF16 matrix row count from 2 to 4 reproduces
991 differing output elements. Disabling reduced-precision BF16 reduction
improves that individual projection, but does not consistently improve the
final distribution across staged and WCPB cases; no global precision switch or
test-tolerance relaxation is proposed. This evidence explains a contribution to
the discrepancy, not all possible scheduling/KV errors.
Remaining before submission
PR-necessity decision, and provide a precise, accessible source for them.
reviewers can access them; reproduce on the final PR head if it changes.
multi-position teacher forcing and sliding-window boundaries; the 10-prompt
smoke test is not a model-quality estimate.
review, or explicitly resolve their outstanding scope with the maintainers.