From e6f6bb8b667ddc8920224a0d00ea3fd86dd3786f Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 16 Nov 2026 07:42:33 -0400 Subject: [PATCH] npu-pack: a 1.7 pack with no head tiles is named as TIED, not blamed on the epsilons (engine#2658) Phi-4-mini-instruct-onnx-ryzenai-npu is refused with "fewer than 6 RMSNorm epsilon headers in the first GiB". Nothing is wrong with its epsilon headers: the model ties lm_head to the embedding, so the export carries NO head tiles and its Token file is exactly layers x stride. fconst17_geometry() computes the right stride, then rejects the size because the wanted size includes a head, and the caller falls back to the epsilon vote -- which reports a cause the pack does not have. The arithmetic for this pack, from the constants in the same function (hidden 3072, IM 8192, 24/8 heads, head_dim 128, vocab 200064, 32 layers): stride = 54,960,128 32 x stride = 1,758,724,096 = the file's exact size head = 3,126 x 108,800 = 340,108,800 B = absent So a size equal to layers x stride is now recognised and named: "the pack carries no head tiles: the file is exactly 32 x 54960128 B = 1758724096 B, and this geometry's head would add 340108800 B -- the model ties lm_head to the embedding (engine#2658)" No behaviour change: the pack is still refused, it is refused for the right reason. Accepting it as a placeable variant is the follow-up and a bigger change -- downstream would read head tiles that do not exist. Arms (synthetic, no pack needed, three of them): - the tied size names the cause and says lm_head; - it does NOT mention RMSNorm, which is the misdirection this removes; - ONE BYTE SHORT of layers x stride is still a generic size error, so the new branch cannot swallow a truncated file. Verified: built and ran on origin/main + this change (npu_pack_import_test, rc 0). The arm was mutated to invert its expectation and went red with the message quoted above, then restored -- so it is known to execute and to fail. --- npu/pack_import.cpp | 9 +++++++++ tests/npu_pack_import_test.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index fd0911a90..4a82f59d0 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -958,6 +958,15 @@ std::string fconst17_geometry(uint64_t size, const Dims& d, Fconst17Geom* g) { return ""; } g->pad = 0; + // engine#2658: a model that TIES `lm_head` to the embedding exports no head tiles, so its Token file is exactly + // layers x stride. The arithmetic above is right and the file is still not this form -- but the refusal used to + // fall through to the generic size sentence, and the caller then fell back to the epsilon vote, which reported + // "fewer than 6 RMSNorm epsilon headers in the first GiB". Nothing was wrong with the epsilons: the file is short + // by exactly its head. Naming that here keeps a reader out of the epsilon machinery (engine#2650, #2651). + if (size == uint64_t(d.layers) * uint64_t(g->stride)) + return "the pack carries no head tiles: the file is exactly " + std::to_string(d.layers) + " x " + + std::to_string(g->stride) + " B = " + std::to_string(size) + " B, and this geometry's head would add " + + std::to_string(g->head) + " B -- the model ties lm_head to the embedding (engine#2658)"; if (size != want) return "the file is " + std::to_string(size) + " B, and the 1.7 headerless form of this geometry is " + std::to_string(d.layers) + " x " + std::to_string(g->stride) + " + a " + std::to_string(g->head) + diff --git a/tests/npu_pack_import_test.cpp b/tests/npu_pack_import_test.cpp index 8bfb3211a..e22084ce2 100644 --- a/tests/npu_pack_import_test.cpp +++ b/tests/npu_pack_import_test.cpp @@ -584,6 +584,21 @@ void test_fconst17_known_geometry() { f17[1000] = char(d.eps_bits & 0xFF), f17[1001] = char(d.eps_bits >> 8); for (int i = 2; i < 12; ++i) f17[size_t(1000 + i)] = '\0'; check(pi::fconst17_geometry_exported(f17.size(), d).empty(), "known geometry: the synthetic 3-layer stream fits"); + // engine#2658: a TIED model exports no head tiles, so its Token file is exactly layers x stride. The arithmetic + // must say THAT, not fall through to the generic size sentence -- the caller then blames the epsilon vote, which + // is where #2658 was pointed before the arithmetic named the real cause. + { + const std::string tied = pi::fconst17_geometry_exported(uint64_t(f17.size() - head), d); + check(tied.find("no head tiles") != std::string::npos, + "known geometry: a stream that stops after the layers is named as a TIED head (" + tied + ")"); + check(tied.find("RMSNorm") == std::string::npos, + " ... and it does not send the reader to the epsilon headers"); + check(tied.find("ties lm_head") != std::string::npos, " ... it names the cause"); + // one byte short of layers x stride is NOT the tied form: it is a truncated file, and must stay generic + const std::string short_one = pi::fconst17_geometry_exported(uint64_t(f17.size() - head - 1), d); + check(short_one.find("no head tiles") == std::string::npos && short_one.find("the file is") != std::string::npos, + " ... but one byte short of it is a size error, not a tied head"); + } const fs::path dir = fs::temp_directory_path() / ("fconst17kg." + std::to_string(::getpid())); fs::remove_all(dir); fs::create_directories(dir);