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 0000000000..e7c1a6fdaa --- /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 + +- diff --git a/.agents/specs/chunked-prefill.md b/.agents/specs/chunked-prefill.md index db103f339e..145ac46080 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 690f50196f..719e113e5a 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); +}