From f544730d848192c60141937ef66fa952acac2909 Mon Sep 17 00:00:00 2001 From: t Date: Tue, 10 Nov 2026 04:19:02 -0400 Subject: [PATCH] npu-pack: the arm that pins q4nx_weight_layout being WRITTEN, in both directions (engine#1840) The fix in #1793 was right -- `import_external` now writes `q4nx_weight_layout` exactly as the `.fconst` path does, so a container built for the `_b8` family stops asking for untagged ELFs and reporting "missing full ELF" for files that are on disk -- and the CHANGES at its merged head asked for the arm that would have caught it. That arm never landed: grep -c q4nx_weight_layout tests/npu_pack_import_test.cpp -> 0 so the regression could return silently while the report still printed `declares q4nx_weight_layout "b8"`. Two arms, because the key's meaning depends on both directions: it is written ONLY for a non-default layout, and every container the importer wrote before that option existed carries no such key. An arm that only checked the positive would leave the negative -- every earlier container -- free to acquire a key that changes which kernels are looked for. weight layout: a default import writes NO q4nx_weight_layout key weight layout: an import with --weight-layout b8 CARRIES the key in its container Both live in `test_final_norm_envelope` because that fixture already reaches a successful `import_pack`, so the arms pin the writer instead of duplicating a crafted pack. Proved they can fail: disabling both `c["q4nx_weight_layout"] = opt.weight_layout;` writes reproduces exactly the #1793 state and the arm reports FAIL weight layout: an import with --weight-layout b8 CARRIES the key in its container (was missing: engine#1793) then the revert restores a clean run. Suite 172/172. Refs #1840, #1793. --- tests/npu_pack_import_test.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/npu_pack_import_test.cpp b/tests/npu_pack_import_test.cpp index 25051340b..cf2ed7a88 100644 --- a/tests/npu_pack_import_test.cpp +++ b/tests/npu_pack_import_test.cpp @@ -1414,6 +1414,35 @@ void test_final_norm_envelope(const std::string& root) { fs::remove_all(out); const pi::Report r = pi::import_pack(dir.string(), out, allow); check(r.final_norm_imported, "final norm: the crafted tail envelope yields model.norm.weight"); + /* engine#1840: the arm the CHANGES at #1793 asked for and never got. `import_external` now writes + * `q4nx_weight_layout` exactly as the `.fconst` path does, so a container built for the `_b8` family stops asking for + * untagged ELFs and reporting "missing full ELF" for files that are on disk. Nothing asserted it, so the regression + * could return silently while the report happily printed `declares q4nx_weight_layout "b8"`. + * + * Both directions, because the key's meaning depends on both: it is written ONLY for a non-default layout, and every + * container the importer wrote before that option existed has no such key. An arm that only checked the positive + * would leave the negative — every earlier container — free to acquire a key that changes which kernels are looked + * for. */ + { + const auto layout_of = [](const std::string& dir) -> std::string { + std::ifstream f(dir + "/config.json"); + if (!f) return ""; + const nlohmann::json c = nlohmann::json::parse(f); + return c.contains("q4nx_weight_layout") ? c.at("q4nx_weight_layout").get() : std::string(); + }; + check(layout_of(out).empty(), + "weight layout: a default import writes NO q4nx_weight_layout key (every earlier container depends on that)"); + pi::Options b8 = allow; + b8.weight_layout = "b8"; + const std::string out8 = out + "_b8"; + fs::remove_all(out8); + const pi::Report r8 = pi::import_pack(dir.string(), out8, b8); + check(r8.final_norm_imported, "weight layout: the same pack imports with a declared b8 layout"); + check(layout_of(out8) == "b8", + "weight layout: an import with --weight-layout b8 CARRIES the key in its container (was missing: engine#1793)"); + std::printf(" weight layout: default import writes no key, b8 import writes \"b8\"\n"); + fs::remove_all(out8); + } check(!r.prefill_tail_seen && !r.final_norm_crosscheck, "final norm: with no prefill program the cross-check is unavailable, not failed"); if (r.final_norm_imported) {