diff --git a/npu/forward/src/q4nx_forward.cpp b/npu/forward/src/q4nx_forward.cpp index d2bd410d6..be8f4318d 100644 --- a/npu/forward/src/q4nx_forward.cpp +++ b/npu/forward/src/q4nx_forward.cpp @@ -1202,6 +1202,11 @@ bool Q4nxNpuForward::init_impl(xrt::device* dev, const char* model_path, setup.pb16i_dir = pb16i_dir_; setup.head_pb16i_images = pb16i_ && !pb16i_dir_.empty() && file_exists(head_pb16i_stem(0) + image_ext()); + // The plan's decode directories, resolved before the target is configured: the decode family and the + // lm-head both search setup.decode_dirs, so a list filled after this line reaches neither. (It used to be + // filled inside the M=16 block further down, which the projections read through a local copy; with that + // block on the target, nothing filled it at all.) + plan_decode_dirs_ = plan_.resolved_decode_dirs(mdir, dir); setup.decode_dirs = m16dirs_like_head(mdir, dir, plan_decode_dirs_); setup.hidden = c_.H; setup.vocab = c_.NV; diff --git a/npu/plan/plan.h b/npu/plan/plan.h index 643d7adf2..54dfeff02 100644 --- a/npu/plan/plan.h +++ b/npu/plan/plan.h @@ -205,6 +205,17 @@ struct Plan { // relative directory under it ("." = that directory itself). struct DecodeDir { bool under_model = false; std::string path; }; std::vector decode_dirs; + // decode_dirs as the paths to search, in the plan's order: each entry under the model directory or the + // kernel directory it names. Empty when the plan names none (or is not loaded), which is the caller's cue + // to fall back to its built-in places. One function, because the projections' decode twins and the lm-head's + // have to be looked for in the same list (engine#910), and the list was once built in a block that a move + // took away, leaving every caller on the built-in places with no error (engine#1984 review). + std::vector resolved_decode_dirs(const std::string& model_dir, const std::string& kernels_dir) const { + std::vector out; + if (!loaded()) return out; + for (const DecodeDir& d : decode_dirs) out.push_back((d.under_model ? model_dir : kernels_dir) + "/" + d.path); + return out; + } std::string sealed_elf; // pb16i: one sealed ELF, per-role instance names struct { bool enabled = false; int K = 0, N = 0; } moe_batched_gu; std::vector layer_plans; diff --git a/tests/npu_plan_test.cpp b/tests/npu_plan_test.cpp index 50001ed94..92bf5aa88 100644 --- a/tests/npu_plan_test.cpp +++ b/tests/npu_plan_test.cpp @@ -123,6 +123,21 @@ void test_valid() { "the pb16i family is read with its sealed ELF"); check(pp.decode_dirs.size() == 2 && pp.decode_dirs[0].under_model, "a model-relative decode dir is kept"); + // The search list a target is configured with: the plan's entries, each under the directory it names, in the + // plan's order (engine#1984 review: nothing resolved them, so a plan naming any place but the built-in three + // lost its decode twins without an error). + { + const std::vector got = pp.resolved_decode_dirs("/m", "/k"); + check(got.size() == 2 && got[0] == "/m/kernels-m16" && got[1] == "/k/.", + "decode dirs resolve under the model dir or the kernel dir, in the plan's order"); + auto seq = base_plan(); + seq["decode"]["dirs"] = nlohmann::json::array({nlohmann::json{{"root", "model"}, {"path", "kernels-m16-seq"}}}); + const std::vector only = Plan::load(write_plan("seq", seq)).resolved_decode_dirs("/m", "/k"); + check(only.size() == 1 && only[0] == "/m/kernels-m16-seq", + "a plan naming one directory outside the built-in places resolves to exactly that directory"); + check(Plan().resolved_decode_dirs("/m", "/k").empty(), "a plan that is not loaded resolves to no directories"); + } + // attention.mode is optional and defaults to causal, so a plan written before the field loads and // still means what it meant then. check(p.attention_mode == "causal" && !p.noncausal(), "a plan with no attention block is causal");