Skip to content
Closed
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
5 changes: 5 additions & 0 deletions npu/forward/src/q4nx_forward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions npu/plan/plan.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ struct Plan {
// relative directory under it ("." = that directory itself).
struct DecodeDir { bool under_model = false; std::string path; };
std::vector<DecodeDir> 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<std::string> resolved_decode_dirs(const std::string& model_dir, const std::string& kernels_dir) const {
std::vector<std::string> 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<LayerPlan> layer_plans;
Expand Down
15 changes: 15 additions & 0 deletions tests/npu_plan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> 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");
Expand Down