Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/engine-matrix.md

Large diffs are not rendered by default.

273 changes: 273 additions & 0 deletions .agents/evidence/eng-chunked-prefill-20261128/PROCESS.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ID: ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J
Title: Prefill graph formation must follow the oracle server's ubatch chunking
Row: ENG-CHUNKED-PREFILL
State: CLOSED
Kind: bug
GitHub: -
Mirror: PENDING
Availability: FULL
Created: 2026-11-27
Updated: 2026-11-29
Closed: 2026-11-29

## Problem

Our CPU prefill computes projections one token at a time (per-token matvec), so ggml-shape-dependent batched GEMM accumulation never matches a serving oracle that forms multi-token ubatches. Measured on Inkling-2-Mini W1: llama-server abca69200 with -b 16 -ub 16 forms prefill graphs of 1,2,6,4 tokens for a 10-token prompt; oracle Kcur differs from ours ~2e-4..4e-4 exactly at the positions the oracle's 6-token graph computes (evidence .agents/evidence of the W1 lane, focused.log 2026-11-27 per-position preconv/postconv table), and the exact token gate flips at raw j=5 (151663 vs 161721). Inputs match ULP; quantization matches byte-for-byte; the divergence is batch-shape-dependent matmul accumulation plus conv-state hand-off across graph boundaries. Our scheduler has token-budget chunking, but the prefill forward does not form ubatch-style multi-token graphs and --max-num-batched-tokens does not change graph formation.

## Resolution

Falsified by measurement (2026-11-28, consumer-measured): the premise that divergence comes from batch-shape-dependent matmul accumulation fixable by matching the oracle's graph boundaries does not hold on our side. The consuming Inkling-2-Mini W1 raw token gate ran with chunking ENGAGED at the oracle shape (knob=16): the runner's chunk plan was (1,4) for the 5-token prompt, two ModelRegistry::Forward calls, stderr-verified in the exact failing run (probe record, /tmp/inkling2-w1/docs/bench-evidence/new-candidate-inkling2-w1-20261125/focused.log lines 1041-1050, worktree a2fdde9f6), and the raw gate did NOT move (j=5 flips 151663 vs oracle 161721, unchanged), with the per-position pre/post-conv table byte-identical with and without chunking. Our quantized kernels compute each output row independently, so the oracle server's graph formation does not change per-row numerics here. CORRECTION (2026-11-30): the kernel-class hypothesis was ALSO falsified the same day — vt::cpu::QuantRepackMatmul proved bit-exact to ggml_gemm_q8_0_4x8_q8_0 on live rows (0/6400), and routing W1's Q8_0 projections through the repack class left the per-position table byte-for-byte unchanged. With inputs ULP, kernels bit-exact, and shapes engaged, the residue mechanism remains UNIDENTIFIED; the consuming row continues the hunt via a three-way against the oracle's own captured kproj inputs (fused-projection suspect), and owns the residue. The seam itself landed mutation-verified and inert-by-default; the falsification closes this issue per the falsified-by-the-tree rule.
242 changes: 242 additions & 0 deletions .agents/specs/chunked-prefill.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
# Row: ENG-CHUNKED-PREFILL — Prefill graph formation mirrors the serving oracle's ubatch chunking

Status: DONE (spec committed before implementation; parity purpose falsified and closed 2026-11-29)

## Now

The seam landed mutation-verified and is inert by default (knob 0). The row's
parity purpose is falsified and closed: chunking does not change our per-row
numerics (see Outcome), so the W1 convergence gap is re-owned by the consuming
row's kernel-class wave (repacked vs vec_dot), not by graph formation. The
seam's remaining non-parity uses — mirroring oracle serving behavior for future
exact gates that pin `-b`/`-ub` — stand; no consumer currently depends on it.
Issue: `.agents/issues/ENG-CHUNKED-PREFILL/ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J.md`
Base SHA: `891c4f27d`
Git integration: repository default — one pull request carries this spec and its
implementation (no recorded developer answer for this row, no split case).

## Scope

The engine's prefill path forms ONE forward per scheduler step: the runner packs
every scheduled token row into a single `ModelRegistry::Forward` call
(`src/vllm/v1/worker/gpu/runner.cpp:3273`, `prepare_inputs.cpp:2182`). A
whole-prompt prefill below the token budget therefore computes all positions in
one graph. A serving oracle that mirrors llama.cpp splits the same prompt into
ubatches (`-b`/`-ub`), and llama.cpp's batched GEMM accumulation is
shape-dependent: per-position results differ between one T=10 graph and the
ubatch sequence the oracle actually ran.

This row adds the missing chunk dimension: a model-facing prefill ubatch
(`n_ubatch`) split at the runner/model boundary that mirrors llama.cpp's batch
splitting, so a gate that pins the oracle's serving batch shape can also match
its graph formation. `--max-num-batched-tokens` (the scheduler token budget)
stays the scheduler-level knob; this row adds the ubatch-level knob and its
split rules.

In scope:

- An engine-level prefill chunk size (the `-ub` analog), plumbed from
`EngineParams`/CLI through the runner to the forward boundary.
- The split rule that turns a scheduled token range into chunks, pinned from
llama.cpp source at the oracle revision (see Upstream anchors). The pinned
mechanism is the SERVER prompt-fill checkpoint policy, not `llama-batch.cpp`
splitting (amended 2026-11-29 after the decisive experiment, below).
- Conv/recurrent-state hand-off across chunk boundaries, mirroring how
llama.cpp carries hybrid state from one ubatch to the next.
- A focused test proving the chunk sequence for a fixed prompt shape.

Out of scope:

- Model-local rewrites of per-token loops (the consuming model port owns its
forward; the W1 Inkling-2-Mini row consumes this seam in its own change).
- Scheduler-level token-budget behavior (already landed,
`ResolveMaxNumBatchedTokens`, `model_loader.cpp:1365`).
- Partial-prefill concurrency (`max_num_partial_prefills`) — separate row.
- vLLM parity of the split rule itself: vLLM's CUDA path does not expose
llama.cpp's ubatch concept; this seam exists because our GGUF/CPU lane is
gated against llama.cpp. The vLLM-mirror obligation for scheduler chunking is
already discharged; this row is the llama.cpp-parity lane and states so
explicitly.

## Upstream anchors

Oracle: llama.cpp `abca69200` (pinned in the W1 row's evidence,
`docs/bench-evidence/new-candidate-inkling2-w1-20261125/oracle-revision.txt`).

AMENDED 2026-11-29 — the decisive instrumented experiment (two clean passes,
exact 10-token golden prompt, `cache_prompt=false`, `--no-warmup`, `-b 16
-ub 16`; logs `/tmp/ubatch-exp-pass{1,2,5,6,7}.log`; fprintf at the ubatch
consumption point `/tmp/llamacpp-inkling-tap/src/llama-context.cpp:2355`)
observed the oracle's real prefill graph formation and falsified the original
anchor:

- The observed prefill sequence is **6, then 4** ubatches (`tokens_evaluated=10`).
- The 6/4 split is the **server prompt-fill checkpoint policy**:
`tools/server/server-context.cpp` `pre_decode()` breaks the fill early at
`checkpoint_offsets[] = {4 + n_ubatch, 4}` when
`task->n_tokens() == prompt_n + min(n_batch, offset)` (upstream PR #20288,
`n_ctx_checkpoints` default ON for completion tasks). It is NOT
`llama-batch.cpp` splitting: `llama_memory_hybrid_iswa::init_batch`
(`src/llama-memory-hybrid-iswa.cpp:92`) calls
`split_equal(n_ubatch, ..., n_keep_tail = n_rs_seq > 0 ? n_rs_seq+1 : 0)`;
with `n_rs_seq = 0` the fill is greedy — one ubatch per server batch
(`src/llama-batch.cpp:665-833`, `split_equal`, `split_seq`, `split_simple`,
`ubatch_add`).
- **The 1- and 2-token graphs in the old W1 record are LOAD-TIME PROBES**, not
prompt tokens: the 2-token graph fires before `srv load_model: initializing`
and survives `--no-warmup`. This resolves the record's internal contradiction
(1+2+6+4 = 13 ≠ 10). Probe graphs are excluded by CONSTRUCTION (they precede
serving), not by `--no-warmup` — the original spec's claim is falsified and
stands withdrawn.
- Server anchor: `tools/server/server-context.cpp` `pre_decode()` at
`abca69200` — the implementer pins the exact checkpoint-offset rule
(file:line) and encodes IT, not a fitted sequence.

## Design

1. `EngineParams` gains a prefill ubatch field (0 = default). CLI/server flag
follows the existing knob pattern (`--max-num-batched-tokens`,
`examples/bench/main.cpp:124`). Default preserves current behavior where the
whole scheduled range is one chunk (no silent gate change for existing
models).
2. The runner applies the split rule to the scheduled token range BEFORE
building forward input, producing an ordered chunk sequence. Each chunk is
one `ModelRegistry::Forward` call with the chunk's token rows. Conv/recurrent
state inputs (the model's cached-state slots) must be read and written at
chunk boundaries exactly as llama.cpp does: the state entering chunk k+1 is
the state chunk k wrote.
3. The split rule is transcribed, not invented: pin the llama.cpp rule from
source, record `file:line` in this spec's Outcome, and encode the rule in one
function with a table test. The observed 10-token/`-ub 16` sequence
(6, 4) is the concrete case; load-time probe graphs are excluded by
construction, not by `--no-warmup`.
4. Bit-parity contract: with the oracle's serving batch shape pinned
(`-b`/`-ub` equivalents) and this row's chunking enabled, a consuming model
port running the exact token gate must reproduce the oracle's graph
boundaries and its per-position arithmetic. The kernel-selection rule
(nrc by batch shape) is already landed in the tree
(`vt::cpu::QuantMmlaVecDot`, shape-selected).

## Risks

- R1: RESOLVED by the 2026-11-29 experiment — the observed sequence is server
checkpoint policy (`pre_decode()` `checkpoint_offsets`), which the original
reading missed; the 1/2-token graphs are load-time probes. The remaining risk
is checkpoint-policy gating (`n_ctx_checkpoints` defaults, task type): the
split rule must encode those gates, not a hard-coded {6,4}. If a gate is
ambiguous in source, stop and report `NEEDS_DECISION`.
- R2: Within-graph position dependence is not yet fully explained: in the W1
per-position table, position 1 differs pre-conv at 2.0e-4 while position 0
(same 6-token oracle graph; the old "2-token graph" attribution was a
load-time probe mislabel) matches at 9.1e-8. Chunking alone may not close the
residue. Mitigation: this row lands the seam + tests;
the consuming row's gate is the judge. If the gate stays red with boundaries
matched, the residue hunt returns to the consuming row with the new
instrument (planner-allocated wdata capture) — that is a stop condition for
THIS row's parity claim, not a failure of the seam.
- R3: Chunking the forward multiplies graph-build overhead per prefill. The
default (one chunk) must keep existing benchmarks byte-identical in behavior;
the enabled path is opt-in via the knob, and the consuming gate sets it to
the oracle's shape.
- R4: Conv-state hand-off across boundaries is where the postconv-only
differences (positions 2, 5, 6, 7 in the W1 table) live. The hand-off must be
proven state-exact, not approximately carried: the focused test asserts the
entering state of chunk k+1 equals the written state of chunk k bit-for-bit.

## Tests

Red-first, smallest failing test first:

- T1: the split-rule function, table-driven: 10-token prompt with ub=16 yields
chunks (6, 4) under the pinned server checkpoint rule; boundary cases (prompt
<= ub, prompt == ub, prompt > ub with remainder, checkpoints disabled
(`n_ctx_checkpoints` off -> no split), multi-sequence ranges) each asserted
against the pinned rule. RED before the rule exists.
- T2: runner-level: with the knob set, one scheduled prefill step of N tokens
produces N_chunk forward calls with the pinned chunk sizes, in order. RED
before plumbing.
- T3: state hand-off: chunk k+1's input state equals chunk k's output state
(bit-for-bit on a synthetic model). RED before the hand-off exists.
- T4: default inertness: knob unset → exactly one forward call per step,
unchanged from today. Guards R3.

## Gates

- Full gate on the touched targets; preflight `--staged` before commit.
- The exact token gate that judges this row's parity is the consuming model
row's gate (Inkling-2-Mini W1: raw j=5 flips 151663 → 161721 with chunking
enabled at the oracle's shape). That flip is recorded here as evidence when
it lands; until then this row's own gates are T1–T4 plus the full suite.
- No tolerance change, no distributional gate. The gate is token-exact.

## Evidence

- W1 lane record: `/tmp/inkling2-w1/docs/bench-evidence/new-candidate-inkling2-w1-20261125/focused.log`
(2026-11-26 graph-boundary observation; 2026-11-27 per-position
preconv/postconv table; kernel four-way bit-identity; instrument attempts).
- Oracle server logs with `-b 16 -ub 16` behavior: same directory.
- Tap build: `/tmp/llamacpp-inkling-tap` (scratch worktree at `abca69200`),
captures under `/tmp/inkling-ref/master-abca69200/`.

## Stop conditions

- The pinned llama.cpp split rule contradicts the observed 1,2,6,4 sequence and
no source-level explanation exists → stop, report `NEEDS_DECISION` with both
readings. Never encode a fitted rule.
- Chunk boundaries match and the consuming gate stays red with a residue
explainable only by a new mechanism → this row lands its seam and tests, and
files the follow-up on the consuming row. Do not expand this row's scope into
kernel arithmetic (that lane is proven bit-identical already).
- Any change that would alter default-path behavior (knob unset) beyond the
declared inertness contract → stop, revise the spec first.

## Owed

- Split-rule mirror for multi-sequence mixed prefill/decode steps beyond the
single-request prefill case (T2 covers single-request; concurrency shapes are
a follow-up once a consuming gate needs them).
- vLLM-side anchor for the ubatch concept does not exist; if vLLM later gains a
matching surface, reconcile this seam onto it and record the change here.
- The seam's remaining NON-PARITY uses stand: mirroring oracle serving behavior
for future exact gates that pin `-b`/`-ub`. No consumer currently depends on
it; the parity use that motivated the row is closed (falsified, below).

## Outcome

What was built: the engine-level prefill chunk seam (`n_ubatch` analog),
plumbed from `EngineParams`/CLI through the runner to the forward boundary,
with the pinned server prompt-fill checkpoint split rule, conv/recurrent-state
hand-off across boundaries, and focused tests T1–T4. Mutation-verified (the
reviewer mutated each claimed guarantee and the focused gate detected every
mutation) and inert by default.

What was measured (2026-11-28, consumer-measured): chunking does not change our
per-row numerics. The consuming Inkling-2-Mini W1 raw token gate ran with
chunking ENGAGED at the oracle shape (knob=16) — chunk plan (1,4), two
`ModelRegistry::Forward` calls, stderr-verified in the exact failing run
(probe record: `/tmp/inkling2-w1/docs/bench-evidence/new-candidate-inkling2-w1-20261125/focused.log`
lines 1041–1050, worktree `a2fdde9f6`) — and the raw gate did not move
(j=5 flips 151663 vs oracle 161721, unchanged), with the per-position
pre/post-conv table byte-identical with and without chunking. Our quantized
kernels compute each output row independently, so the oracle server's graph
formation does not change per-row numerics on our side.

What was rejected and why: the row's parity premise — that divergence comes
from batch-shape-dependent matmul accumulation and exact parity needs our
prefill chunking to match the oracle's graph boundaries — is FALSIFIED by that
measurement. CORRECTION (2026-11-30): the kernel-class hypothesis was also
falsified the same day (QuantRepackMatmul bit-exact to the ggml repack gemm on
live rows; routing W1's Q8_0 projections through it left the table unchanged),
so the residue mechanism is UNIDENTIFIED and the consuming row continues via a
three-way against the oracle's own captured kproj inputs. Issue
`ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J` closed on the falsification evidence
2026-11-29; this correction 2026-11-30.

Why each default keeps its value: the knob defaults to 0 (inert) so the
declared default-path inertness contract holds — no existing gate or benchmark
changes behavior, which R3 required. The VT-style knob stays opt-in rather than
being removed: it is a faithful llama-server-behavior mirror (the pinned
checkpoint split rule), kept as the instrument for future llama.cpp-parity
gates that pin `-b`/`-ub`. The Gates section's expected W1 flip (151663 →
161721 with chunking) did not occur; that record stands as falsified evidence,
not a pending claim.
14 changes: 14 additions & 0 deletions include/vllm/entrypoints/model_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ struct EngineParams {
// product let an 8x1024 (8192-token) prefill run in ONE step, blowing the GDN
// prefill activation.
int max_num_batched_tokens = 0;
// ENG-CHUNKED-PREFILL: the prefill ubatch (llama.cpp's `-ub` analog), the
// model-facing chunk size this row adds beside the scheduler token budget
// above. 0 = the DEFAULT and it is INERT: the whole scheduled range is one
// forward, byte-identical to before the field existed. >0 turns on the
// pinned llama.cpp server prompt-fill checkpoint split
// (`tools/server/server-context.cpp` `pre_decode()`,
// `checkpoint_offsets[] = {4 + n_ubatch, 4}` @ abca69200, upstream PR
// #20288): an eligible single-request prefill step runs one forward per
// checkpoint chunk, in order, so a gate pinning the oracle's serving batch
// shape (`-b budget -ub knob`) also matches its graph formation. See
// include/vllm/v1/worker/gpu/prefill_chunks.h for the transcribed rule and
// its gates. No CLI flag yet — the consuming model row sets it through the
// params struct.
int prefill_ubatch = 0;
// Mirrors vLLM's tri-state --[no-]enable-prefix-caching resolution. Hybrid
// and attention-free generation models default OFF at the parity pin;
// decoder-only models default ON. An explicit value overrides the model
Expand Down
Loading
Loading