Skip to content

feat(ENG-CHUNKED-PREFILL): engine prefill chunking mirrors the oracle server's checkpoint split - #3602

Open
lu-zero wants to merge 9 commits into
localai-org:mainfrom
lu-zero:row/ENG-CHUNKED-PREFILL
Open

lu-zero wants to merge 9 commits into
localai-org:mainfrom
lu-zero:row/ENG-CHUNKED-PREFILL

Conversation

@lu-zero

@lu-zero lu-zero commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Engine prefill chunking mirrors the oracle server's checkpoint split

Adds an opt-in prefill-ubatch seam that mirrors llama.cpp's server-side
prompt-fill checkpoint policy (tools/server/server-context.cpp
pre_decode(), checkpoint_offsets {4+n_ubatch, 4}, upstream PR #20288,
pinned at abca69200): when EngineParams::prefill_ubatch is set on an
eligible single-request prefill step, the scheduled range is split by
the pinned rule and runs as one ModelRegistry::Forward per chunk, in
order, with bit-exact recurrent-state hand-off across boundaries
(chunk k+1 rebuilds GDN metadata on the same state slot the previous
chunk wrote). Default (knob 0) is byte-identical to the previous
single-forward behavior, mutation-verified both ways.

Honest outcome, recorded in the spec: the original parity motivation
was falsified by measurement - our quantized kernels are row-
independent, so oracle graph formation does not change per-row
numerics (the consuming Inkling-2-Mini gate ran with the chunk plan
(1,4) engaged and did not move; the issue is closed on that evidence
with a correction after a second falsification). The seam stands as a
faithful llama-server-behavior mirror for future gates that pin -b/-ub
serving shapes, inert by default with no current consumer. Split-rule
table tests cover (6,4)/(1,4)/(12,4) shapes, the 4+n_ubatch offset
order, checkpoints-disabled, and multi-sequence inertness; a
runner-level test drives the production forward loop through a
counting synthetic model and reds under a call-site-neutering
mutation; the review's F1/F2 findings were repaired with mutation-RED
evidence.

Closes ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]

…'s ubatch chunking

The W1 Inkling-2-Mini gate is red at raw j=5 because llama-server
abca69200 (-b 16 -ub 16) computes a 10-token prompt in graphs of
1,2,6,4 tokens while our engine packs the whole scheduled range into
one forward; ggml's batched accumulation is shape-dependent, so
per-position Kcur differs exactly where the oracle's 6-token graph
ran (projection accumulation at pos 1,3,4, conv state hand-off at
2,5,6,7; kernels and quantization bit-identical). This row adds the
missing engine seam: a prefill ubatch knob, the llama.cpp split rule
pinned from source, and bit-exact state hand-off, so a gate that
pins the oracle's serving batch shape can also match its graph
formation. Model-local consumption rides the W1 row.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]
…oint split

The decisive instrumented experiment (two clean passes, exact 10-token
golden prompt, cache_prompt=false, -b 16 -ub 16) observed the oracle's
real prefill formation: ubatches 6 then 4, produced by the llama-server
pre_decode checkpoint policy (checkpoint_offsets {4+n_ubatch, 4},
upstream PR #20288), NOT llama-batch.cpp splitting, which fills greedily
and never splits a 10-token prompt at ub=16. The record's 1- and
2-token graphs are load-time probes that survive --no-warmup, which
resolves the 13!=10 contradiction and falsifies the original spec
anchor; T1 is retargeted to (6,4) with a checkpoints-disabled boundary
case, and the residue analysis loses the probe-graph attribution.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]
…'s server checkpoint split

The runner formed ONE forward per scheduler step, so a whole-prompt prefill
below the token budget computed every position in one graph while the
llama.cpp oracle the GGUF/CPU lane is gated against split the same prompt
into checkpoint chunks. This adds the missing ubatch-level seam:

- EngineParams::prefill_ubatch (the -ub analog, 0 = default = inert) wired
  through LoadedEngine to GPUModelRunner via set_prefill_ubatch.
- PrefillCheckpointChunks (include/vllm/v1/worker/gpu/prefill_chunks.h)
  transcribes the pinned llama.cpp abca69200 rule from
  tools/server/server-context.cpp pre_decode(): the fill loop breaks early
  at checkpoint_offsets {4 + n_ubatch, 4} when
  task->n_tokens() == prompt_n + min(n_batch, offset), gated on
  do_checkpoint (n_ctx_checkpoints ON for COMPLETION tasks, PR #20288).
  n_batch maps to the per-step max_num_batched_tokens budget. The {6, 4}
  observed sequence falls out of the rule; nothing is fitted.
- The forward site plans the chunk sequence BEFORE building forward input
  and runs one ModelRegistry::Forward per chunk, in order, only for eligible
  single-request gathered-logits prefill steps. The GDN state hand-off is
  bit-exact by address identity: every chunk's rebuilt metadata addresses
  the same persistent state slot, with has_initial_state from the chunk's
  own context. The final chunk carries the last-prompt-token lm_head row.
- tests/vllm/v1/worker/test_prefill_chunks.cpp: T1 table-driven rule (the
  (10,16,16)->{6,4} case plus boundaries and a 320-combination sweep), the
  T2 slice/planning gates, the T3 state-slot hand-off, and the T4 default
  inertness. RED was the missing-header compile failure; GREEN is 5 cases /
  1274 assertions. The multi-sequence mixed-prefill mirror stays Owed per
  the spec.

Focused ctest gate (prefill_chunks, runner, prepare_inputs, input_batch,
engine_core, llm_engine, engine_types): 7/7. Staged preflight: exit 0 after
repairing the ENG-MOE-LOADSTREAM anchor this change shifted in
.agents/engine-matrix.md (2576 -> 2580). The row's parity judge remains the
consuming model row's token gate.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
…d pin the 4+ub offset order

Reviewer repairs for row ENG-CHUNKED-PREFILL (issue ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J).

F1 (reachability): every prior ENG-CHUNKED-PREFILL case gated the pure rule
and the seam helpers, so a mutation that neuters the PlanPrefillChunks call
at runner.cpp:3302 (plan forced empty) left all of them green — the gate
could not see the feature stop existing. The new case
"ENG-CHUNKED-PREFILL: execute_model runs ONE forward PER CHUNK" enters
through the PRODUCTION entry point `GPUModelRunner::execute_model` on CPU
over a counting synthetic model (a LoadedModel + ModelFactory whose forward
records each call's token-row width, following the
test_device_token_ids_refusal.cpp fixture pattern): knob 0 → exactly ONE
forward over the whole 10-token range; knob 16 → exactly TWO forwards with
sizes (6, 4) in order. RED-first evidence: with the call site neutered the
knob arm fails `CHECK( g_chunk_forward_calls == 2 ) ... values: CHECK( 1 == 2 )`
and the size REQUIRE (1 == 2); restored, the case is green. This also
upgrades the earlier PROCESS.md caveat that T2/T3 were never exercised
through full runner execution.

F2 (T1 blind spot): the asserted table never exercised n_batch >
n_ubatch + 4, where the 4 + n_ubatch offset fires BEFORE the 4 offset. Two
new subcases pin it: (T=12, b=16, ub=4) -> {4, 4, 4} and (T=13, b=16, ub=8)
-> {1, 8, 4} — both assert the CORRECT pinned-rule values, and under the
reviewer's {n_ubatch, 4} mutation they give {8, 4} / {5, 4, 4} and RED
(test_prefill_chunks.cpp:101, :105 in the mutated run). A third subcase
(T=17, b=16, ub=32) -> {1, 12, 4} pins the min(n_batch, 4+n_ubatch) half,
which the mutation cannot reach. Note: the review finding's example value
{8, 4} for (12, 16, 4) was wrong under the pinned rule — offsets are
iterated in {4 + n_ubatch, 4} order and the first match breaks
(server-context.cpp:4480-4490 @ abca69200), so {4, 4, 4} is correct and
equally distinctive against the mutation.

No production code changed; no checker touched; CPU-only tests.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
… evidence

Append the timestamped repair-round entry to the row's PROCESS.md: the
reachability test name and its verbatim RED under the neutered call site,
the F2 table cases and their RED under the offset mutation, the focused
green set, the exit-0 preflight, and the repair commit.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
Taking main's engine-matrix wholesale during the rebase left the
ENG-MOE-LOADSTREAM anchor at main's pre-insertion line (2668); our four
loader lines move FromModelDir to 2672. Eight further stale anchors
were the branch's stale matrix hunk, removed by resetting the file to
main's version; this row adds no matrix row of its own.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]
…the slice

The consumer-reported Inkling-2-Mini gate SIGSEGV inside
SliceCommonAttentionMetadata: inkling2_loop publishes its packed KV group as a
SlidingWindowSpec (kind kSlidingWindow), so the runner's full_attn_group_id_
stays the -1 sentinel (the selector only takes kFullAttention/kMlaAttention
groups, runner.cpp:846) and MakeCommonAttentionMetadata leaves the step's
slot_mapping EMPTY (the `group < slot_mapping.size()` guard is false for the
cast sentinel, backend.cpp:86-89). The whole-step path passes the empty vector
through untouched; the chunk loop sliced `begin() + begin` on it, and the
consumer's gdb frame was exactly that assign. T2's synthetic fixture always
populated slot_mapping, so the shape was never covered — a fixture gap, not a
transcription error.

The fix mirrors the whole-step behavior: an empty step-level slot_mapping rides
through empty; a populated one slices exactly as before. The new T2b case in
test_prefill_chunks builds the crashing shape (10-token prefill, empty
slot_mapping and block table) and was RED on the pre-fix header, GREEN after.
Mutation checks: forcing the runner's chunk_plan empty (runner.cpp:3366) reds
the F1 reachability case; reverting the guard reds T2b. Tree restored
byte-for-byte after each mutation. Focused set green: test_prefill_chunks 6/6,
test_prepare_inputs 9/9, test_runner 42/42 (CPU-only).

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
…ord the outcome

The consuming Inkling-2-Mini W1 gate ran with chunking engaged (plan (1,4),
two ModelRegistry::Forward calls, stderr-verified in the exact failing run)
and the raw token gate did not move; the per-position pre/post-conv table is
byte-identical with and without chunking. Our quantized kernels compute each
output row independently, so the issue's premise — batch-shape-dependent
matmul accumulation that exact parity could repair by matching the oracle's
graph boundaries — is falsified by measurement. The residue's actual
mechanism is the kernel class (repacked vs vec_dot), owned by the consuming
row. This change closes ISSUE-LOCAL-01M8FKEEA4VJBDK75035DR365J on that
evidence, marks the spec DONE with an ## Outcome recording what was built,
measured, rejected, and why the knob-0 default and opt-in VT-style knob keep
their values, adds ## Now (seam landed, parity purpose falsified, W1
convergence re-owned by the consuming row's kernel-class wave), and notes in
## Owed that the seam's non-parity uses stand with no current consumer.
Records only; no product code.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [task]
…d falsification

The issue resolution and spec Outcome named the kernel class
(repacked vs vec_dot) as the residue mechanism; the consuming row
falsified that too within the day (QuantRepackMatmul bit-exact to the
ggml repack gemm on live rows, table unchanged when W1's projections
route through it). Both premises are now measured-falsified; the
mechanism is unidentified and the consuming row continues via a
three-way against the oracle's own captured kproj inputs.

FOLLOWING_AGENTS_PROTOCOL

Following-Agents-Protocol: true
AI-Assisted: true
Assisted-by: AGENT:zai/glm-5.3-flash [maki]

This branch has not been deployed

No deployments
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