From 9fc49fd7ed4f6d4b73add85e0128b7dbbd6e0776 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 2 Dec 2026 04:51:40 +0100 Subject: [PATCH 1/2] test(ENG-CHUNKED-PREFILL): prove the chunk hand-off on sequential requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS (consumer-found on the kolibri-1.1 lane) reports that the chunk continuation corrupts model state across sequential requests: with chunking engaged, the 24-gate battery regresses 6/24 vs 7/24 unchunked and a standalone-exact prompt flips mid-battery. The report's root-cause class names this seam: the state hand-off was validated only on Inkling's GDN topology, and the chunk loop was suspected of skipping a per-request reset the whole-step path performs. This commit is the red-first reproduction the repair owed, and it reports the honest outcome: the defect does not reproduce at the seam. The T5 fixture (test_runner.cpp) extends the ChunkCountingModel fixture to the sequential battery shape: two 10-token prefills back-to-back on one chunked runner, request B admitted in the same step that retires A, then B's first decode. Every forward's input is recorded — token/position rows, chunk cams (query_start_loc, seq_lens, num_computed continuation markers, slot mappings, block tables), GDN state slots and has_initial_state masks, logits indices — and request B's chunked inputs are asserted to reassemble to the unchunked path's single-forward inputs for the same request, field for field. The fixture is GREEN before any repair, 66/66 assertions: the chunk loop derives every per-request artifact the whole-step path derives per step. The GDN metadata builder is constructed fresh per request-step, the chunk cams slice the step's own prepared per-group slot mappings, and the multi-cache channels (kolibri-1.1's actual topology, one KV group per KV source) ride through by shared pointer, so no per-request reset exists for the chunk loop to skip. A static audit of the consuming model agrees: the kolibri-1.1 forward holds no state across forwards, and its cache writes/reads are addressed by the same metadata both paths produce. Mutation: the F1 reachability mutation (chunk call site neutered at runner.cpp execute_model) reds the fixture (REQUIRE(chunked.size() == 5) fails, 1/7) and still reds the T2 forward-count test; the tree was restored byte-for-byte and all three focused suites (prefill_chunks 1291, prepare_inputs 61, test_runner 1993 assertions) are green on the restored head. Consequence: the battery delta (6/24 vs 7/24, one prompt flipping) does not localize to this seam's orchestration. It sits inside the ULP tie-cascade churn band the consuming lane itself adjudicated — it observed 5/24, 6/24 and 7/24 across its own builds WITHOUT this seam engaged. The chunked-vs-unchunked bitwise difference the lane measured is the MatmulBTQuant GEMM/GEMV dispatch by M, a shared-seam property, not a metadata hand-off defect. Localizing further needs the kolibri-1.1 model-local path or the shared quantized-GEMM tie seam; both are out of this row's scope, so no product change rides this commit. The spec's Tests section gains T5 recording the fixture, the green-before outcome and the escalation. FOLLOWING_AGENTS_PROTOCOL Following-Agents-Protocol: true AI-Assisted: true Assisted-by: AGENT:zai/glm-5.3-flash [task] --- .agents/specs/chunked-prefill.md | 21 +++ tests/vllm/v1/worker/test_runner.cpp | 224 +++++++++++++++++++++++++++ 2 files changed, 245 insertions(+) diff --git a/.agents/specs/chunked-prefill.md b/.agents/specs/chunked-prefill.md index db103f339..145ac4608 100644 --- a/.agents/specs/chunked-prefill.md +++ b/.agents/specs/chunked-prefill.md @@ -159,6 +159,27 @@ Red-first, smallest failing test first: (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. +- T5 (2026-12-02, the ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS escalation): the + sequential-request hand-off fixture. TWO 10-token prefills back-to-back on + ONE chunked runner — request B admitted in the same step that retires A — + plus B's first decode; every forward's input recorded (token/position rows, + chunk cams, slot mappings, GDN state slots and has_initial_state masks) and + request B's chunked inputs asserted to reassemble to the unchunked path's + single-forward inputs exactly. HONEST OUTCOME: the fixture is GREEN before + any repair — the seam's per-request hand-off could NOT reproduce the + consumer's cross-request corruption on the topologies the runner-level + fixture can express. The chunk loop derives every per-request artifact the + whole-step path derives per step (fresh GDN builder per request, per-group + slot mapping sliced from the step's own prepared inputs, request-level + multi-cache channels by shared pointer by construction). The F1 reachability + mutation (chunk call site neutered) still reds the fixture and the T2 + forward-count test. The consumer battery delta (6/24 chunked vs 7/24 + unchunked, one prompt flipping) therefore does not localize to this seam's + orchestration; it sits inside the ULP tie-cascade churn band the consuming + lane already adjudicated (5/24, 6/24 and 7/24 all observed across its own + builds without this seam). Escalated: localizing further needs the + kolibri-1.1 model-local path or the shared quantized-GEMM tie seam, both out + of this row's scope. ## Gates diff --git a/tests/vllm/v1/worker/test_runner.cpp b/tests/vllm/v1/worker/test_runner.cpp index 690f50196..719e113e5 100644 --- a/tests/vllm/v1/worker/test_runner.cpp +++ b/tests/vllm/v1/worker/test_runner.cpp @@ -3627,12 +3627,69 @@ namespace { int g_chunk_forward_calls = 0; std::vector g_chunk_forward_token_counts; +// ENG-CHUNKED-PREFILL (ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS): what each +// forward SAW. The counting fixture above proves the split; this record proves +// the state hand-off: a second sequential request's per-chunk forward inputs +// must reassemble to exactly what the unchunked path produces for the same +// request (state slots, cache metadata, slot mappings). +struct ChunkFwdRecord { + std::vector token_ids; + std::vector positions; + std::vector logits_indices; + int num_reqs = 0; + int64_t gdn_state_slots = 0; + // CommonAttentionMetadata. + std::vector query_start_loc; + std::vector seq_lens; + std::vector num_computed_tokens_cpu; + std::vector slot_mapping; + int num_actual_tokens = 0; + int max_query_len = 0; + std::vector block_table; + int block_table_num_cols = 0; + // GDNAttentionMetadata (the recurrent state hand-off). + int gdn_num_prefill_tokens = 0; + std::vector gdn_state_indices; + std::vector gdn_prefill_has_initial_state; +}; +std::vector g_chunk_records; + +ChunkFwdRecord RecordChunkForward(const vllm::ModelForwardInput& input) { + ChunkFwdRecord r; + r.token_ids = input.token_ids; + r.positions.reserve(input.positions.size()); + for (const int64_t p : input.positions) { + r.positions.push_back(static_cast(p)); + } + r.logits_indices = input.logits_indices; + r.num_reqs = input.num_reqs; + r.gdn_state_slots = input.gdn_state_slots; + r.query_start_loc = input.attn_meta.query_start_loc_cpu; + r.seq_lens = input.attn_meta.seq_lens_cpu; + r.num_computed_tokens_cpu = input.attn_meta.num_computed_tokens_cpu; + r.slot_mapping = input.attn_meta.slot_mapping; + r.num_actual_tokens = input.attn_meta.num_actual_tokens; + r.max_query_len = input.attn_meta.max_query_len; + r.block_table = input.attn_meta.block_table_tensor; + r.block_table_num_cols = input.attn_meta.block_table_num_cols; + r.gdn_num_prefill_tokens = input.gdn_meta.num_prefill_tokens; + if (input.gdn_meta.non_spec_state_indices_tensor.has_value()) { + r.gdn_state_indices = *input.gdn_meta.non_spec_state_indices_tensor; + } + if (input.gdn_meta.prefill_has_initial_state.has_value()) { + r.gdn_prefill_has_initial_state = + *input.gdn_meta.prefill_has_initial_state; + } + return r; +} + vllm::ForwardLogits ChunkCountingForward(vllm::LoadedModel& model, const vllm::ModelForwardInput& input) { (void)model; ++g_chunk_forward_calls; g_chunk_forward_token_counts.push_back( static_cast(input.token_ids.size())); + g_chunk_records.push_back(RecordChunkForward(input)); return {}; } @@ -3698,3 +3755,170 @@ TEST_CASE("ENG-CHUNKED-PREFILL: execute_model runs ONE forward PER CHUNK") { CHECK(g_chunk_forward_token_counts[1] == 4); } } + +// ─── ENG-CHUNKED-PREFILL (ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS) ──────────── +// Consumer defect: with chunking enabled, SEQUENTIAL requests corrupt model +// state — a request whose chunked standalone run is exact flips when it follows +// another chunked request in the same engine process. The chunk loop's +// per-request state hand-off (state slots, cache metadata, slot mappings) must +// be exactly what the unchunked single-forward path produces for the SAME +// request. This fixture drives two prefill requests back-to-back through ONE +// chunked runner (request A's chunks, then request B's) and asserts request +// B's per-chunk forward inputs reassemble to the unchunked path's single +// forward input for B. +TEST_CASE("ENG-CHUNKED-PREFILL: second sequential request's chunk inputs " + "reassemble to the unchunked path") { + vllm::ModelFactory factory; + factory.prepare = &ChunkCountingPrepare; + factory.forward = &ChunkCountingForward; + constexpr std::string_view kCountingArch = "ChunkCountProbeModel"; + const vllm::ModelRegistration reg{kCountingArch, &factory, vllm::ModelInfo{}}; + + const HfConfig c = MakeConfig(); + const auto MakeReq = [](const std::string& id, std::vector fa_blocks, + int gdn_block) { + return MakeNewReq(id, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {}, + /*num_computed=*/0, std::move(fa_blocks), gdn_block, + Greedy()); + }; + // A NEW request admitted in the SAME step that retires the previous one — + // the sequential-request battery shape (request N's chunks, then N+1's). + const auto MakeSequentialStep = [](NewRequestData next) { + SchedulerOutput so; + so.finished_req_ids = {"A"}; + so.scheduled_cached_reqs = CachedRequestData::make_empty(); + so.scheduled_new_reqs = {std::move(next)}; + so.num_scheduled_tokens = {{"B", 10}}; + so.total_num_scheduled_tokens = 10; + return so; + }; + + const auto Run = [&](bool chunked) { + ChunkCountingModel model(reg); + GPUModelRunner runner(c, model, MakeKvConfig(c), Q(), + /*max_num_reqs=*/8, kMaxModelLen, 64); + if (chunked) runner.set_prefill_ubatch(16); + g_chunk_records.clear(); + // Request A: fresh 10-token prefill, chunked (6, 4) or whole (10). + CHECK_FALSE( + runner.execute_model(NewStep({MakeReq("A", {2, 3}, 1)}, {{"A", 10}})) + .has_value()); + // Request B, admitted as A retires: ANOTHER 10-token prefill on the SAME + // engine. Its forward inputs are the seam's state hand-off under test. + CHECK_FALSE(runner + .execute_model(MakeSequentialStep( + MakeReq("B", {4, 5}, /*gdn_block=*/2))) + .has_value()); + // B's FIRST DECODE on the same engine — the sequential battery's step right + // after a chunked (or whole) prefill. Its forward input must read the cache + // the prefill wrote through the SAME metadata either path produces. + CHECK_FALSE(runner.execute_model(DecodeStep("B", /*num_computed=*/10, + /*num_output=*/0)) + .has_value()); + return g_chunk_records; + }; + + const std::vector chunked = Run(/*chunked=*/true); + const std::vector whole = Run(/*chunked=*/false); + + // Both runs: A's prefill, B's prefill, B's first decode. The chunked run + // splits each prefill (6, 4); the whole run is one forward per step. + REQUIRE(chunked.size() == 5); + REQUIRE(whole.size() == 3); + + // THE DECODE AFTER THE CHUNKED PREFILL must carry exactly the metadata the + // decode after the whole-step prefill carries: same slot (the recurrent + // state B's prefill wrote), same block table, same seq_lens/slot mapping — + // the consumer's cross-request corruption would show here first. + { + const ChunkFwdRecord& bd = chunked[4]; + const ChunkFwdRecord& bwd = whole[2]; + CHECK(bd.token_ids == bwd.token_ids); + CHECK(bd.positions == bwd.positions); + CHECK(bd.num_reqs == bwd.num_reqs); + CHECK(bd.seq_lens == bwd.seq_lens); + CHECK(bd.num_computed_tokens_cpu == bwd.num_computed_tokens_cpu); + CHECK(bd.query_start_loc == bwd.query_start_loc); + CHECK(bd.slot_mapping == bwd.slot_mapping); + CHECK(bd.block_table == bwd.block_table); + CHECK(bd.block_table_num_cols == bwd.block_table_num_cols); + CHECK(bd.gdn_state_indices == bwd.gdn_state_indices); + CHECK(bd.gdn_state_slots == bwd.gdn_state_slots); + CHECK(bd.logits_indices == bwd.logits_indices); + } + + const ChunkFwdRecord& b0 = chunked[2]; // B's first chunk + const ChunkFwdRecord& b1 = chunked[3]; // B's second chunk (continuation) + const ChunkFwdRecord& bw = whole[1]; // B's unchunked forward + + // Row shape: one request per chunk forward, chunks (6, 4). + CHECK(b0.num_reqs == 1); + CHECK(b1.num_reqs == 1); + CHECK(b0.token_ids.size() == 6); + CHECK(b1.token_ids.size() == 4); + CHECK(b0.num_actual_tokens == 6); + CHECK(b1.num_actual_tokens == 4); + CHECK(b0.max_query_len == 6); + CHECK(b1.max_query_len == 4); + + // THE TOKEN STREAM reassembles exactly: same tokens, same positions, in + // order, and only the FINAL chunk owes the sampler its lm_head row. + CHECK(b0.token_ids == std::vector(bw.token_ids.begin(), + bw.token_ids.begin() + 6)); + CHECK(b1.token_ids == std::vector(bw.token_ids.begin() + 6, + bw.token_ids.end())); + CHECK(b0.positions == std::vector(bw.positions.begin(), + bw.positions.begin() + 6)); + CHECK(b1.positions == std::vector(bw.positions.begin() + 6, + bw.positions.end())); + CHECK(b0.logits_indices.empty()); + REQUIRE(b1.logits_indices.size() == 1); + CHECK(b1.logits_indices[0] == 3); + + // CACHE METADATA: the continuation marker (num_computed) is the chunk's own + // context; seq_lens is context THROUGH the chunk's last token. + REQUIRE(b0.num_computed_tokens_cpu.size() == 1); + REQUIRE(b1.num_computed_tokens_cpu.size() == 1); + CHECK(b0.num_computed_tokens_cpu[0] == 0); + CHECK(b1.num_computed_tokens_cpu[0] == 6); + REQUIRE(b0.seq_lens.size() == 1); + REQUIRE(b1.seq_lens.size() == 1); + CHECK(b0.seq_lens[0] == 6); + CHECK(b1.seq_lens[0] == 10); + CHECK(b0.query_start_loc == std::vector{0, 6}); + CHECK(b1.query_start_loc == std::vector{0, 4}); + + // SLOT MAPPINGS: the chunked path must address the SAME physical KV rows the + // whole-step path writes — the per-chunk slices concatenate to the whole + // step's mapping, and the request-level block table rides through unchanged. + std::vector concat_slots = b0.slot_mapping; + concat_slots.insert(concat_slots.end(), b1.slot_mapping.begin(), + b1.slot_mapping.end()); + CHECK(concat_slots == bw.slot_mapping); + CHECK(b0.block_table == bw.block_table); + CHECK(b1.block_table == bw.block_table); + CHECK(b0.block_table_num_cols == bw.block_table_num_cols); + CHECK(b1.block_table_num_cols == bw.block_table_num_cols); + + // RECURRENT STATE HAND-OFF: both chunks address the SAME state slot (the one + // the whole-step path used for B), the slot count matches, and the + // continuation carries chunk 0's written state in (has_initial_state 1) while + // the fresh request's first chunk starts from zero state (mask 0) — exactly + // what the unchunked path's mask says for B. + REQUIRE(b0.gdn_state_indices.size() == 1); + REQUIRE(b1.gdn_state_indices.size() == 1); + REQUIRE(bw.gdn_state_indices.size() == 1); + CHECK(b0.gdn_state_indices[0] == bw.gdn_state_indices[0]); + CHECK(b1.gdn_state_indices[0] == bw.gdn_state_indices[0]); + CHECK(b0.gdn_state_indices[0] >= 0); + CHECK(b0.gdn_state_slots == bw.gdn_state_slots); + REQUIRE(b0.gdn_prefill_has_initial_state.size() == 1); + REQUIRE(b1.gdn_prefill_has_initial_state.size() == 1); + REQUIRE(bw.gdn_prefill_has_initial_state.size() == 1); + CHECK(b0.gdn_prefill_has_initial_state[0] == 0); + CHECK(b1.gdn_prefill_has_initial_state[0] == 1); + CHECK(bw.gdn_prefill_has_initial_state[0] == 0); + CHECK(b0.gdn_num_prefill_tokens == 6); + CHECK(b1.gdn_num_prefill_tokens == 4); + CHECK(bw.gdn_num_prefill_tokens == 10); +} From 2fda8f612734e11ce37b76e5da4847f19cfe60a7 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Wed, 2 Dec 2026 05:16:55 +0100 Subject: [PATCH 2/2] record(ENG-CHUNKED-PREFILL): import the consumer's cross-request chunk defect The T5 fixture commit references ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS, which the consuming kolibri-1.1 lane filed in its own branched record tree; this worktree's check-agent-record refused the reference because the canonical file did not exist here yet. Import the file VERBATIM at its canonical row path so the reference validates offline and the two trees carry byte-identical authority for the issue. Open state unchanged; the consuming row owns its resolution and re-verification. FOLLOWING_AGENTS_PROTOCOL Following-Agents-Protocol: true AI-Assisted: true Assisted-by: AGENT:zai/glm-5.3-flash [task] --- .../ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .agents/issues/MODEL-TEXT-kolibri-1-1-kolibri1-1-for-causal-lm/ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS.md diff --git a/.agents/issues/MODEL-TEXT-kolibri-1-1-kolibri1-1-for-causal-lm/ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS.md b/.agents/issues/MODEL-TEXT-kolibri-1-1-kolibri1-1-for-causal-lm/ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS.md new file mode 100644 index 000000000..e7c1a6fda --- /dev/null +++ b/.agents/issues/MODEL-TEXT-kolibri-1-1-kolibri1-1-for-causal-lm/ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS.md @@ -0,0 +1,19 @@ +ID: ISSUE-LOCAL-01M8TBA3XW1Y284PBJTYV8PWXS +Title: chunked prefill regresses the sequential kolibri-1.1 battery while every standalone chunked probe is exact +Row: MODEL-TEXT-kolibri-1-1-kolibri1-1-for-causal-lm +State: OPEN +Kind: bug +GitHub: - +Mirror: PENDING +Availability: FULL +Created: 2026-12-02 +Updated: 2026-12-02 +Closed: - + +## Problem + +ENG-CHUNKED-PREFILL seam engaged at the oracle shape (VT_PROBE_UBATCH=512 -> plan (1,4) for the 5-token prompt) on the U3 lane: standalone raw probes runs 0/1/2 are EXACT (9224,46,14147 / 543,1889,1270 / 543,21499,11910) and the engine 4-token chunk matches the oracle node tap bitwise (24576/24576 q_proj_out L0, whole-prompt prefill differs 1-2 ULP from row 6145), but the in-process 24-gate battery regresses to 6/24 (18 failing tags; raw:The capital of France is flips at j=2 got=9255 want=456) from 7/24 without chunking. The chunked-prefill continuation corrupts state across sequential requests on the kolibri-1.1 hybrid (sparse kv-source + recurrent) cache path. + +## Resolution + +-