From 0d54ef747c7f31ef48c3ebb8dadc8824441134f4 Mon Sep 17 00:00:00 2001 From: agent Date: Tue, 10 Nov 2026 03:12:06 -0400 Subject: [PATCH] npu-pack: the 1.9 header reader fills `hdr` when the vote found none, and stops overwriting one (engine#1831) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `locate_fconst_with_header()` derived the second-header offset from the residue mode of the epsilon anchors and then, on `best >= 3`, assigned the **two-header** block shape unconditionally: 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; `locate_fconst()`'s vote has already set `h1` and a `period - 1`-entry `hdr` when it wins, and `plan()` reads the block layout from `hdr.size()`: **1** entry is the two-header block, **3** is the four-header block (q/k/v, then k_norm, then q_norm, then o_proj -- Qwen3). So for every Qwen3 1.9 pack this truncated the list to one entry, and `post_attn_hdr()` -- which returns `hdr.back()` and is the only thing marking the end of attention -- returned the **k_norm** header as the start of the MLP section: weights read from the wrong place, on a container that parses cleanly. The guard is `g.hdr.empty()`, and the old comment says why: its stated reason for the assignment was *"setting only `h1` left `hdr` empty"* -- a **fill**, which is what it should have stayed. The reader may fill what the vote did not establish; it may not overwrite what it did. When the vote wins, `h1` came from it (`g.h1 = pos[1] - pos[0]`), so nothing else needs to move. Verified: `g++-16 -std=c++26 -fsyntax-only -Inpu -Inpu/forward/include -Inpu/plan -I` on `npu/pack_import.cpp` → clean (one pre-existing `-Wvexing-parse` warning at an unrelated line). **No test arm, and the reason is stated rather than implied**: `locate_fconst_with_header()` is internal to this file, and the arm would need a synthetic 1.9 `.fconst` (header + per-block anchors) as a fixture. The precedent for exposing it is already here -- the file carries `find_token_fconst_exported`/`load_geometry_exported` wrappers for exactly this -- so the arm is an export plus a fixture, not a design question. I could not build to run it either: the box is at 132 GB free, below the plan's 175 GB build floor. Fixes engine#1831. Refs engine#1819. --- npu/pack_import.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index 7243c0898..878aa647c 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1409,7 +1409,15 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& // and every attention projection refused while the MLP imported byte-exact -- measured on Qwen2-7B 1.9. // The scan window is the first GiB (about 8 blocks of this geometry), so the right residue repeats ~8 times // 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 + // engine#1831: this must FILL what the epsilon vote did not establish, never OVERWRITE what it did. + // `locate_fconst()` sets `h1` and a `period - 1`-entry `hdr` when its vote wins, and `plan()` reads the block + // layout from `hdr.size()`: 1 entry is the 2-header block (q/k/v/o in one payload, Qwen2/Llama), 3 is the + // 4-header block (q/k/v, then k_norm, then q_norm, then o_proj, Qwen3). Assigning unconditionally truncated a + // Qwen3 pack's list to one entry, so `post_attn_hdr()` -- which returns `hdr.back()` and is the only thing + // that marks the end of attention -- returned the k_norm header as the start of the MLP section: weights read + // from the wrong place, silently, on a container that parses cleanly. The old comment's own reason ("setting + // only `h1` left `hdr` empty") is exactly why the guard is `g.hdr.empty()`, not a rewrite. + if (best >= 3 && g.hdr.empty()) { // 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;