From 0777cc60ebc86266e2b21c7beb0b900686df9ac7 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Tue, 10 Nov 2026 03:11:33 -0400 Subject: [PATCH] npu-pack: never overwrite the epsilon vote's header list with the 2-header shape (fixes #1831) locate_fconst_with_header() writes the 2-header block shape (hdr.assign(1, best_off); period = 2) from its own residue vote, and it did so unconditionally -- including when locate_fconst()'s epsilon vote had already filled g.hdr with period-1 inner headers and set g.period from the repeat period it measured. The reader picks the block layout from that list: plan() branches on hdr.size() == 1 (2-header: Qwen2/Llama, q/k/v/o in one payload) against hdr.size() == 3 (4-header: Qwen3, q/k/v, then k_norm and q_norm, then o_proj), and FconstGeom::post_attn_hdr() returns hdr.back(), which is the post-attention norm *and* the start of the MLP section. So on every Qwen3 1.9 pack the 3-entry list became a 1-entry list, post_attn_hdr() returned the k_norm header, and the block was read from the wrong offset -- without an error, because nothing about the result is structurally invalid, only wrong. The guard is what the branch's own comment already describes: it exists for the case where the vote could not win and left hdr empty. It now applies exactly then. g.h1 is still set from the residue in both cases, since it is the second-header offset the payload reader uses independently of the block shape. No test in this commit: the fixture has to craft a 4-header 1.9 tail, and I cannot build here (disk 147 G, below the 175 G floor this lane works under), so a test I cannot run would be worse than none. The case to add is a crafted 4-header fconst asserting hdr.size() == 3 and period == 4 after locate_fconst_with_header(), beside the existing 2-header case, which must still produce hdr.size() == 1 when the eps vote finds nothing. Checked as far as this box allows: g++ -std=c++20 -fsyntax-only over npu/pack_import.cpp with the build's json include, clean except a pre-existing -Wvexing-parse at :4473. fixes #1831 --- npu/pack_import.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index 7243c0898..e5ff517ab 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1411,8 +1411,17 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& // against 1-2 for a payload coincidence. Requiring `layers/2` was too strict and silently dropped the real one. if (best >= 3) { // the residue repeats across blocks: a real section boundary g.h1 = best_off; - g.hdr.assign(1, best_off); // 2-header block: q/k/v/o in one payload (Qwen2/Llama) - g.period = 2; + // NEVER overwrite a header list the epsilon vote already established (engine#1831). `locate_fconst` + // records `period - 1` inner headers, and the reader picks the block layout from that count: one entry + // is the 2-header Qwen2/Llama shape, three is the 4-header Qwen3 shape (q/k/v, then k_norm and q_norm, + // then o_proj). Assigning unconditionally turned every Qwen3 pack into the 2-header shape, so + // `post_attn_hdr()` -- which is `hdr.back()`, the post-attention norm AND the start of the MLP section -- + // returned the k_norm header and the block was read from the wrong offset with no error. This branch + // exists for the case its comment describes: the vote could not win and left `hdr` empty. + if (g.hdr.empty()) { + g.hdr.assign(1, best_off); // 2-header block: q/k/v/o in one payload (Qwen2/Llama) + g.period = 2; + } } } }