fix(pflash): reuse Qwen3 drafter K/V buffers - #574
Merged
davide221 merged 2 commits intoAug 3, 2026
Conversation
cheese-cakee
marked this pull request as ready for review
August 1, 2026 20:59
Contributor
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="server/src/qwen3/qwen3_graph.cpp">
<violation number="1" location="server/src/qwen3/qwen3_graph.cpp:421">
P3: The `nope_tail ? 0u : (size_t)il` buffer-index idiom is now computed three separate times in the same function — as `li` in the allocation loop (line ~326), `layer_cache_idx` in the forward loop (~421), and `layer_cache_idx` again in the scoring loop (~786). Because the indexing rules (index 0 when reusing in NoPE mode, per-layer index in legacy mode) live in three copies, a future change to the buffer plan or to the reuse policy must be applied consistently in all three or the code silently falls out of sync with `Qwen3DrafterBufferPlan`. Consider consolidating the index derivation into a small local helper (e.g. a lambda or a method on the plan struct) so the reuse policy is defined and read in one place.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DFLASH_FP_NOPE_TAIL=0Root cause
The Qwen3 drafter allocated full-sequence K and V tensors for every layer even though the default NoPE path consumes the RoPE K/V pair before advancing to the next layer. At the contexts reported in #147, one BF16 K or V tensor is approximately 350 to 390 MiB, so repeated per-layer reservations exhaust a 24 GB device and force compression to fall back to extraction.
The default path now retains one reusable RoPE K buffer and one reusable V buffer. The legacy post-RoPE scoring path still retains the per-layer K and Q-tail tensors that it reads after the forward loop; V remains reusable in both modes.
Fixes #147.
Scope
This PR contains only the Qwen3 buffer-lifetime fix and its allocation-policy test. It does not include the separately preserved FlashPrefill phase-one kernel hardening or any hunks overlapping draft PR #542.
Verification
0438574DFLASH_FP_NOPE_TAIL=0short-context outputs matched the current-main baseline byte-for-byte-Wall -Wextra -Werrorgit diff --checkpassedLimitations