From 8e57d0dce10248ad2ab5f9a38e531a84cb5e131f Mon Sep 17 00:00:00 2001 From: pi-zha Date: Sun, 8 Nov 2026 17:54:42 -0400 Subject: [PATCH] npu: a missing kernel whose only sibling is the _b8 variant names the LAYOUT, not just the file (engine#1503) A container imported without --weight-layout b8 is row-major, so it asks for full_i8__K_N.elf while every per-op ELF set on the box carries the _b8 suffix. The failure was 'missing full ELF ', which reads as a missing artifact and sends the reader looking for a kernel that was never supposed to exist; the actual fix is an import flag. Measured on a Ryzen AI 1.9 pack (Qwen2.5-0.5B_rai_1.9.0, hidden 896): the same container answers correctly on the NPU once re-imported with --weight-layout b8 and served against the shipped kernels-05b-hyb-b8 set, and refuses with the message above when imported row-major. Both name-producing sites get the hint - the xdna target layer's prefill path, which is where this container fails, and Q4nxNpuForward::missing_kernel, which serves the plan path. Checked by elf_present() on the sibling name alone, so nothing changes except the wording of a refusal that was already happening. Verified: built (ONEBIT_NPU=ON), reproduced the message against a directory holding only the _b8 names, rc unchanged (4). --- npu/forward/src/q4nx_forward.cpp | 16 ++++++++++++++++ npu/target/xdna/xdna_target.cpp | 22 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/npu/forward/src/q4nx_forward.cpp b/npu/forward/src/q4nx_forward.cpp index 57effaf1c..3519c51cb 100644 --- a/npu/forward/src/q4nx_forward.cpp +++ b/npu/forward/src/q4nx_forward.cpp @@ -3572,6 +3572,22 @@ std::string Q4nxNpuForward::missing_kernel(const std::string& dir, const char* e if (plan_.loaded()) return "plan " + plan_path_ + ": this model's plan needs the " + role_tag(role) + " kernel \"" + elf_name + "\" in " + dir + " (missing)"; + // engine#1503: a container imported without `--weight-layout b8` is row-major, so it asks for plain kernel names while + // the only kernels on the box carry the _b8 suffix. Naming the layout instead of only the missing file is the + // difference between "re-fetch the artifact" and "re-import the pack with a flag" - measured on a Ryzen AI 1.9 pack, + // where the same container ran correctly with the b8 set and the flag. + { + const std::string name(elf_name); + if (name.size() > 4 && name.compare(name.size() - 4, 4, ".elf") == 0) { + const std::string b8 = name.substr(0, name.size() - 4) + "_b8.elf"; + if (file_exists(dir + "/" + b8)) + return "missing full ELF " + dir + "/" + elf_name + + " - but the b8 variant \"" + b8 + "\" is there: this container's weight layout is row-major " + + "(q4nx_weight_layout absent), so it asks for row-major kernels and the directory holds the b8 " + + "family. Re-import the pack with `npu-pack import --weight-layout b8`, or supply row-major ELFs " + + "(engine#1503)."; + } + } return "missing full ELF " + dir + "/" + elf_name; } diff --git a/npu/target/xdna/xdna_target.cpp b/npu/target/xdna/xdna_target.cpp index dc8f2b4cc..def6a0534 100644 --- a/npu/target/xdna/xdna_target.cpp +++ b/npu/target/xdna/xdna_target.cpp @@ -130,9 +130,25 @@ bool XdnaTarget::open_prefill(const Q4nxDesignGeom* designs, int n, std::string& // The same wording the forward used for this case, because a diagnostic that changes shape // when code moves is a diagnostic someone has to re-learn. const char* role = q4nx_design_log_tag(g->role); - err = plan_path.empty() ? ("missing full ELF " + elf) - : ("plan " + plan_path + ": this model's plan needs the " + role + - " kernel \"" + g->elf_name + "\" in " + dir + " (missing)"); + // engine#1503: when the asked-for name is the plain one and the directory holds only the _b8 family, the missing + // thing is the container's LAYOUT, not the artifact. Measured on a Ryzen AI 1.9 pack: the same container ran + // correctly once it was re-imported with `--weight-layout b8`. Say that here, or the reader goes looking for a + // kernel that was never supposed to exist. + std::string hint; + { + const std::string nm(g->elf_name); + if (nm.size() > 4 && nm.compare(nm.size() - 4, 4, ".elf") == 0) { + const std::string b8 = nm.substr(0, nm.size() - 4) + "_b8.elf"; + if (elf_present(dir + "/" + b8)) + hint = " - but the b8 variant \"" + b8 + "\" is there: this container's weight layout is " + "row-major (q4nx_weight_layout absent), and a row-major container asks for row-major " + "kernels. Re-import the pack with `npu-pack import --weight-layout b8`, or supply a " + "row-major ELF family (engine#1503)."; + } + } + err = (plan_path.empty() ? ("missing full ELF " + elf) + : ("plan " + plan_path + ": this model's plan needs the " + role + + " kernel \"" + g->elf_name + "\" in " + dir + " (missing)")) + hint; return false; } if (!dev_) {