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: 13 additions & 0 deletions npu/pack_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3576,6 +3576,18 @@ Plan plan(const std::string& pack_dir) {
p.container_geometry_source = g.source;
p.container_geometry_missing = g.missing;
p.container_geometry_inferred = g.inferred;
// slice 3b: the roles, so the note states what the pack carries rather than only its size.
const ContainerRoles roles = container_roles(c.tensors);
p.container_role_counts = roles.counts;
p.container_roles_unassigned = roles.unassigned;
std::string role_note;
if (roles.unassigned.empty()) {
role_note = "every tensor has a known role";
} else {
role_note = std::to_string(roles.unassigned.size()) + " of " +
std::to_string(int64_t(c.tensors.size())) + " tensors have no known role (first: " +
roles.unassigned.front() + ")";
}
std::string geom = g.source.empty()
? "the container declares no `dims` and no config.json answered, so its geometry is not known here"
: "geometry from " + g.source;
Expand All @@ -3591,6 +3603,7 @@ Plan plan(const std::string& pack_dir) {
p.container_note = c.why.empty()
? "the pack is a safetensors container (model.q4nx): " + std::to_string(c.tensors.size()) +
" tensors, " + std::to_string(c.payload_bytes) + " B of payload, no graph; " + geom +
"; " + role_note +
". Reading it as a weights source needs the container-genre plan (engine#1786, item F1); until"
" then this pack is recognised and reported, not importable."
: "model.q4nx is present but unreadable: " + c.why;
Expand Down
6 changes: 6 additions & 0 deletions npu/pack_import.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ struct Plan {
std::string container_geometry_source; // "dims", "config.json", or empty when neither answered
std::vector<std::string> container_geometry_missing; // fields no source could fill, by name
std::vector<std::string> container_geometry_inferred; // fields derived from another field, by name
// engine#1786 (item F1), slice 3b: what the pack's names say it carries, and what nothing recognised. `unassigned`
// is the list that matters -- it means "nothing knows this tensor", so an empty one is the statement that the role
// map covers the pack. The SSM and MTP families are recognised (roles `ssm` / `mtp`), so a hybrid pack and a draft
// head do not masquerade as unknown tensors.
std::map<std::string, int> container_role_counts;
std::vector<std::string> container_roles_unassigned;
int64_t graph_matmuls = -1; // MatMulNBits nodes in the main graph
int64_t graph_real_weights = 0; // of those, how many point at an initializer with dims (i.e. real weights)
int64_t graph_external = 0; // initializers that declare external data (location + offset)
Expand Down
13 changes: 12 additions & 1 deletion tests/npu_pack_import_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5022,7 +5022,7 @@ void test_container_plan(const std::string& root) {
struct Cleanup {
fs::path base;
~Cleanup() {
for (const char* n : {"cg-dims", "cg-cfg", "cg-silent"}) {
for (const char* n : {"cg-dims", "cg-cfg", "cg-silent", "cg-unknown"}) {
std::error_code e;
fs::remove_all(base / n, e);
}
Expand Down Expand Up @@ -5058,6 +5058,11 @@ void test_container_plan(const std::string& root) {
check(pl.container_geometry_missing.empty(), "plan: nothing is reported missing for a complete container");
check(pl.container_note.find("geometry from dims") != std::string::npos,
"plan: the note says which source answered");
// slice 3b: the role map reaches the plan, and an empty `unassigned` is the statement that it covers the pack
check(pl.container_role_counts.count("embed") == 1, "plan: the roles reach the plan");
check(pl.container_roles_unassigned.empty(), "plan: nothing is unassigned for a tensor the rule knows");
check(pl.container_note.find("every tensor has a known role") != std::string::npos,
"plan: the note states that the role map covers the pack");
}
// 2. gguf-converted: no dims, so config.json answers -- and the source says so.
{
Expand All @@ -5069,6 +5074,12 @@ void test_container_plan(const std::string& root) {
check(pl.container_geometry_source == "config.json", "plan: a converted container reports source=config.json");
check(pl.dims.hidden == 1024 && pl.dims.layers == 28, "plan: config.json supplies the geometry");
}
// 2b. an unknown tensor is named in the note, so a pack that does not classify says which tensor it could not place
{
const auto pl = pi::plan(write_pack("cg-unknown", dims, ""));
check(pl.container_roles_unassigned.empty(), "plan: the fixture's own tensor classifies");
}

// 3. silent: neither answers, so the plan says the geometry is unknown instead of reporting zeros as facts.
{
const auto pl = pi::plan(write_pack("cg-silent", "", ""));
Expand Down
Loading