[PR #5273] [Engine] guard KVA stream-plan access for short prefill chunks #5371

Open
opened 2026-11-07 16:34:42 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5273
Author: @zapabob
Created: 11/5/2026
Status: 🔄 Open

Base: main ← Head: codex/fix-kva-small-chunk


📝 Commits (1)

  • 8f7470a fix(engine): avoid absent KVA stream plans for short chunks

📊 Changes

1 file changed (+12 additions, -6 deletions)

View changed files

📝 src/prefill/prefill.cpp (+12 -6)

📄 Description

KVA's MoE, GDN state-only and QSA state-only exits index seq_start[l + 1] even when stream_all is false. The vector is populated only for the full streaming path. With --prefill 512 below the 1024-token streaming threshold, an approximated chunk can therefore dereference an empty vector.

Guard only the three stream-plan consumption/release pairs with if (stream_all). State advancement, QSA indexing, KV prefetch and the early exits stay where they were. The active streaming path executes the same release operations. No defaults, arithmetic or KVA approximation settings change.

This is a draft because exact upstream-tree compilation and the other affected backends have not been verified.

Validation performed:

  • CUDA build and kva_test passed in the Windows fork. Hardware: RTX 5060 Ti 16 GB, Ryzen 5 4500, 32 GB RAM, CUDA 13.3, sm_120.
  • Two actual Swift Qwen3.8-Flash-Next IQ2_XS regressions completed 912 input tokens and two generated tokens at capacity 98,304, prefill 512, including the partial final chunk. Environment: STRATA_KVA=1, STRATA_KVA_SPLIT=1, STRATA_KVA_MIN_PROMPT=512, STRATA_KVA_SUFFIX=64, with STRATA_KVA_SKIP=state and then moe. These are branch/crash checks, not retrieval-quality measurements.
  • Those hardware checks used fork executable SHA256 83959903089c536a16a85cb14261070b05d1cb892f42d6b059bab61b238b21e7, containing these same guards. They were not runs of this exact upstream PR tree.
  • git diff --check HEAD~1 HEAD passed for this branch.

Failure and limits:

The original fork executable crashed with Windows 0xc0000005 on the first approximated chunk of a 98,016-token request. Its crash dump resolved a null-vector read in Prefill::run_impl. After repair, a separate full-input rerun reached 96,256 processed tokens, but the PC became unresponsive and the user manually restarted it. There is no completed answer from that run; the cause of the host hang is unresolved. No 98K completion or speed improvement is claimed.

Not run: exact upstream-tree CUDA build/execution, HIP, SYCL, and a complete streaming/non-streaming regression matrix. Targeted backend verification is needed before review readiness.

The patch is based on upstream ffa80d73133ea5c548aefe57889a16e8085a938f. Open and closed discussions were searched for seq_start and KVA crash; the returned HIP/long-prompt discussions concern different paths.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/5273 **Author:** [@zapabob](https://github.com/zapabob) **Created:** 11/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `codex/fix-kva-small-chunk` --- ### 📝 Commits (1) - [`8f7470a`](https://github.com/Niko1221/Strata/commit/8f7470a16c0c0b7321784cb7b3502b15d0377e63) fix(engine): avoid absent KVA stream plans for short chunks ### 📊 Changes **1 file changed** (+12 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+12 -6) </details> ### 📄 Description KVA's MoE, GDN state-only and QSA state-only exits index `seq_start[l + 1]` even when `stream_all` is false. The vector is populated only for the full streaming path. With `--prefill 512` below the 1024-token streaming threshold, an approximated chunk can therefore dereference an empty vector. Guard only the three stream-plan consumption/release pairs with `if (stream_all)`. State advancement, QSA indexing, KV prefetch and the early exits stay where they were. The active streaming path executes the same release operations. No defaults, arithmetic or KVA approximation settings change. This is a draft because exact upstream-tree compilation and the other affected backends have not been verified. Validation performed: - CUDA build and `kva_test` passed in the Windows fork. Hardware: RTX 5060 Ti 16 GB, Ryzen 5 4500, 32 GB RAM, CUDA 13.3, sm_120. - Two actual Swift Qwen3.8-Flash-Next IQ2_XS regressions completed 912 input tokens and two generated tokens at capacity 98,304, prefill 512, including the partial final chunk. Environment: `STRATA_KVA=1`, `STRATA_KVA_SPLIT=1`, `STRATA_KVA_MIN_PROMPT=512`, `STRATA_KVA_SUFFIX=64`, with `STRATA_KVA_SKIP=state` and then `moe`. These are branch/crash checks, not retrieval-quality measurements. - Those hardware checks used fork executable SHA256 `83959903089c536a16a85cb14261070b05d1cb892f42d6b059bab61b238b21e7`, containing these same guards. They were not runs of this exact upstream PR tree. - `git diff --check HEAD~1 HEAD` passed for this branch. Failure and limits: The original fork executable crashed with Windows `0xc0000005` on the first approximated chunk of a 98,016-token request. Its crash dump resolved a null-vector read in `Prefill::run_impl`. After repair, a separate full-input rerun reached 96,256 processed tokens, but the PC became unresponsive and the user manually restarted it. There is no completed answer from that run; the cause of the host hang is unresolved. No 98K completion or speed improvement is claimed. Not run: exact upstream-tree CUDA build/execution, HIP, SYCL, and a complete streaming/non-streaming regression matrix. Targeted backend verification is needed before review readiness. The patch is based on upstream `ffa80d73133ea5c548aefe57889a16e8085a938f`. Open and closed discussions were searched for `seq_start` and `KVA crash`; the returned HIP/long-prompt discussions concern different paths. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5371
No description provided.