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);