From 5a5188a2fb7317ab2462ac8ad863e367512c9859 Mon Sep 17 00:00:00 2001 From: pi-tmplsec Date: Tue, 10 Nov 2026 17:12:31 -0400 Subject: [PATCH] npu-pack: the in-block header cut scales with the blocks in the window (engine#1985) The cut that decides which epsilon residues are a block's section boundaries was a constant 3, calibrated on h3584 ("about 8 blocks" in the first GiB). At a smaller stride the same window holds more blocks, so a payload coincidence accrues more chances to reach 3 while the real boundaries stay near one-per-block -- Qwen3-1.7B (hidden 2048) came back with four in-block offsets, three real plus one coincidence, and fconst_set_block_headers() accepts only 1 or 3, so the whole layout was dropped and the pack refused as "the 4-header block is read as 2-header" (0 gaps on 91815b27b, 280 today). One repeat per block is the floor the code's own comment already assumes, so the cut is now max(3, blocks_in_window / 4). Not yet pinned by a fixture: the pack leg has no crafted 4-header 1.9 block, which is what this change needs before it should merge. --- npu/pack_import.cpp | 13 ++++++++++--- .../q4nx-container/container-genre/model.q4nx | Bin 0 -> 1340 bytes tests/golden/q4nx-container/huge.q4nx | Bin 0 -> 8 bytes tests/golden/q4nx-container/meta.q4nx | Bin 0 -> 5224 bytes tests/golden/q4nx-container/short.q4nx | Bin 0 -> 5158 bytes tests/golden/q4nx-container/two.q4nx | Bin 0 -> 820685 bytes 6 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 tests/golden/q4nx-container/container-genre/model.q4nx create mode 100644 tests/golden/q4nx-container/huge.q4nx create mode 100644 tests/golden/q4nx-container/meta.q4nx create mode 100644 tests/golden/q4nx-container/short.q4nx create mode 100644 tests/golden/q4nx-container/two.q4nx diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index 3c6c09bae..11eea9604 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -1821,9 +1821,16 @@ FconstGeom locate_fconst_with_header(const std::string& tok, const std::string& return g; } const std::vector pos = eps_header_positions(tok, size_t(1) << 30, dims.eps_bits); - // The scan window is the first GiB (about 8 blocks at h3584), so a real section boundary repeats ~8 times against - // 1-2 for a payload coincidence; 3 separates them (requiring `layers/2` was too strict and dropped the real one). - const std::vector inner = fconst_block_headers(pos, stride8, 3); + // The scan window is the first GiB, so a real section boundary repeats once per block in it, while a payload + // coincidence repeats a handful of times. The cut therefore has to scale with how many blocks the window holds: + // a constant `3` was calibrated on h3584 ("about 8 blocks"), and at a smaller stride the same window holds more + // blocks, so a coincidence accrues more chances to reach 3 while the real boundaries stay near one-per-block + // (engine#1985: Qwen3-1.7B, hidden 2048, came back with four in-block offsets -- three real plus a coincidence -- + // and `fconst_set_block_headers` accepts only 1 or 3, so the whole layout was dropped and the pack refused with + // "the 4-header block is read as 2-header"). One repeat per block is the floor the comment above already assumes. + const int64_t blocks_in_window = int64_t(pos.size()); + const int min_repeat = int(std::max(3, blocks_in_window / 4)); + const std::vector inner = fconst_block_headers(pos, stride8, min_repeat); if (!fconst_set_block_headers(g, inner)) { g.why = "the 1.9 header gives stride " + std::to_string(stride8) + ", but the epsilon anchors repeat at " + std::to_string(inner.size()) + " in-block offset(s), and a layer block has 1 (2-header) or 3 (4-header); " diff --git a/tests/golden/q4nx-container/container-genre/model.q4nx b/tests/golden/q4nx-container/container-genre/model.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..010a7b9d9898fcb8c363ddb9c0d4a389eea8fe7a GIT binary patch literal 1340 zcmdnO00GrXx%nxnIeMwNNvSFECHdK@dBu9=shQ~+B}!J+N+~6k1*u9_N=|NuW=c9r z#TkhpZnT++jzz4FQc7Y;VtjsDT5)PgF;LV%$I!sYB(_!uYGzJiWol8eo`GI&PJv!Z wetBMeK~a7d7SlZ~kj%EwF*L(88)UMMp`oc!Y;CR5C>RZa(GVC7fdL8u07F>ROaK4? literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/huge.q4nx b/tests/golden/q4nx-container/huge.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..b786843b6f0fc9cf328ec334a1487fa9a650e351 GIT binary patch literal 8 NcmZQz00Kq^1^@sH00IC2 literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/meta.q4nx b/tests/golden/q4nx-container/meta.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..457e118667f518277dc85085593e227bd2ac8d2b GIT binary patch literal 5224 zcmeIuK?=e!6h%?j^2Qm|l!|l*u0cu+G*t)EV!i_{*}Fz}A@|Mxg+Do`&2OthxFw5Y zv>1Z=Rp5c2Qz8Ojp eLjVB;5I_I{1Q0*~0R#|0009ILKmdWi6?g-ZrN*%U literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/short.q4nx b/tests/golden/q4nx-container/short.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..193af377155c0f95bb656e259f712733771f4941 GIT binary patch literal 5158 zcmeIup$ULc07X$}dD)~z1P5>i(+35kphf=jB5on)wp-8CeASeUHS2XBTgJ>o+MIiN eXX(3$009C72oNAZfB*pk1PBlyK!5;&-wHg<$FUUv literal 0 HcmV?d00001 diff --git a/tests/golden/q4nx-container/two.q4nx b/tests/golden/q4nx-container/two.q4nx new file mode 100644 index 0000000000000000000000000000000000000000..6b2e734b669d476cb74ddae156e0e2fc758f7c4a GIT binary patch literal 820685 zcmeIuOKQSU6oBEb<&G~Qib!zSL7{6X5(0_Uk{3xtL|k6?RimRm23^2+X6Fq41K;P< zV=kfT%BoK4;#>`5k|u|?KTi35ZM&gKPSxRkKZVUDl+(Gd!X`YwEY=~0abL{q+j^C5 zV