Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion npu/pack_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,18 @@ OnnxModel parse_onnx(const std::string& path) {
else
continue;
const OnnxTensor* pw = find_init(packed);
if (!pw || no_bytes(*pw)) continue;
if (!pw) continue; // no sibling at all: not this genre's pack, leave it to the reader below
if (no_bytes(*pw)) {
// engine#1671: the sibling exists and is ITSELF a zero-length placeholder (measured on
// Qwen2.5-0.5B-Instruct rai_1.9.0 -- dims [0], no external-data location, offset 0, length 0, for all 241
// of its MatMulNBits). So the weights are genuinely absent from the pack's external data, and the honest
// answer is a refusal that says that. Deferring it produced `...qweight.empty: no data` from a lookup much
// later, which names the placeholder rather than the problem and reads as a tile-layout fault.
throw std::runtime_error(
"the pack names " + w->name + ", and its " + packed + " sibling exists but carries no data either "
"(no external-data location, dims all zero): these weights are genuinely absent from the pack's "
"external data, so this pack cannot be imported -- not a tile-layout or block-size problem");
}
mm.weight = pw->name;
++m.packed_siblings;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/npu_pack_import_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,32 @@ void test_crafted_refusals(const std::string& root) {
"crafted: the refusal names the qweight tensor (" + what + ")");
}
check(!fs::exists(dir / "out2" / "model.q4nx"), "crafted: nothing written for the overstated MatMulNBits");

// 3. engine#1671: a node names a `.qweight.empty` placeholder and its `.qweight.packed` sibling exists but is
// ITSELF empty (dims [0], no external-data location). The weights are genuinely absent, so the refusal must say
// so and name the tensor -- not defer to a `no data` lookup much later, which named the placeholder and read as
// a tile-layout fault. Measured on Qwen2.5-0.5B-Instruct rai_1.9.0, whose 241 MatMulNBits are all this shape.
put_file((dir / "model.onnx").string(),
pb::model({pb::tensor("model.embed_tokens.weight", {8, 8}, "model.onnx.data", 0, 256),
pb::tensor("gguf_qweight.empty", {0}, "", 0, 0),
pb::tensor("gguf_qweight.packed", {0}, "", 0, 0),
pb::tensor("gguf_scales", {}, "model.onnx.data", 256, 1024),
pb::tensor("gguf_zeros", {}, "model.onnx.data", 1280, 160)},
{pb::matmulnbits("mm", {"x", "gguf_qweight.empty", "gguf_scales", "gguf_zeros"},
64, 512, 4, 128)}));
try {
const auto r = pi::import_pack(dir.string(), (dir / "out3").string(), allow);
check(false, "crafted: an empty .packed sibling was refused");
} catch (const std::exception& e) {
const std::string what = e.what();
std::printf(" crafted packed-empty refusal: %s\n", what.c_str());
check(what.find("gguf_qweight.empty") != std::string::npos && what.find("gguf_qweight.packed") != std::string::npos,
"crafted: the refusal names the placeholder and its sibling (" + what + ")");
check(what.find("genuinely absent") != std::string::npos,
"crafted: and says the bytes are absent rather than reporting a tile/lookup fault (" + what + ")");
}
check(!fs::exists(dir / "out3" / "model.qnx") && !fs::exists(dir / "out3" / "model.q4nx"),
"crafted: nothing written for the empty .packed sibling");
fs::remove_all(dir);
}

Expand Down
Loading