From c18207f39f0df8e51629b5c74c81d11b2c4d5f18 Mon Sep 17 00:00:00 2001 From: bong-water-water-bong Date: Mon, 9 Nov 2026 18:57:05 -0400 Subject: [PATCH] npu-pack: the external-data import copies the text artifacts, so its container is a model directory Found on the first real probe of the genre: the container was complete (363 tensors, dims right, 4 designs derived) and `serve` refused the whole directory -- 1bit serve: ... is not an NPU model directory (model.q4nx, config.json, tokenizer.json) -- because import_external wrote model.q4nx and config.json and never copied the tokenizer. That reads like a weights problem and is not one: the registry, the geometry and every tensor were fine, and five files were missing. Fixed by sharing the list every other path already uses (kTextFiles) through one helper, so the genre cannot drift from them: `5 of 8 tokenizer/chat files copied` on the real pack, and the directory now starts the forward (which then refuses at the FIRST missing kernel ELF, which is the honest next wall). The test cannot cover "the directory is servable" without shipping a tokenizer, so this one stays a real-pack observation -- recorded in the commit rather than pretended into a fixture. --- npu/pack_import.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/npu/pack_import.cpp b/npu/pack_import.cpp index f98d6408a..7303b9cf6 100644 --- a/npu/pack_import.cpp +++ b/npu/pack_import.cpp @@ -2362,6 +2362,19 @@ static const char* const kTextFiles[] = {"tokenizer.json", "chat_template.jinja", "generation_config.json"}; +// The same list every path copies (see kTextFiles): a container without tokenizer.json is not an NPU model directory. +static int copy_text_artifacts(const std::string& pack_dir, const std::string& out_dir) { + int copied = 0; + for (const char* f : kTextFiles) { + const std::string src = pack_dir + "/" + f; + std::error_code cec; + if (!fs::exists(src, cec)) continue; + fs::copy_file(src, out_dir + "/" + f, fs::copy_options::overwrite_existing, cec); + if (!cec) ++copied; + } + return copied; +} + TextArtifacts scan_text_artifacts(const std::string& pack_dir) { TextArtifacts t; for (const char* f : kTextFiles) { @@ -2414,6 +2427,9 @@ std::string kernel_set_refusal(const std::vector& file_names, const // .fconst envelope (attention payload, MLP sections, tail) and the graph-weights path, and threading a third shape // through it is how the two existing paths got their special cases. What it shares is the parts that are genuinely // shared -- the plan, the geometry, the tile writer, the container metadata. +// Copies the tokenizer/chat files the container needs beside model.q4nx; defined past kTextFiles' declaration. +static int copy_text_artifacts(const std::string& pack_dir, const std::string& out_dir); + Report import_external(const std::string& pack_dir, const std::string& out_dir, const Options& opt) { const Plan p = plan(pack_dir); const std::string graph = graph_filename(pack_dir); @@ -2553,6 +2569,12 @@ Report import_external(const std::string& pack_dir, const std::string& out_dir, std::ofstream cf(out_dir + "/config.json", std::ios::binary | std::ios::trunc); if (!cf) throw std::runtime_error("cannot write " + out_dir + "/config.json"); cf << c.dump(2) << "\n"; + cf.close(); + // The text artifacts, the same list the other paths copy: without tokenizer.json the directory is not an NPU model + // directory at all, and the first probe of this genre failed exactly there -- the container was complete and + // `serve` refused it for the missing tokenizer, which reads like a weights problem and is not one. + const int copied = copy_text_artifacts(pack_dir, out_dir); + std::fprintf(stderr, "npu-pack: external-data genre: %d text artifact(s) copied\n", copied); std::fprintf(stderr, "npu-pack: external-data genre: %d tensors (%lld tiles, %lld exact)\n", r.tensors, (long long)r.tiles, (long long)aux); return r;