Skip to content

docs: the variable that decides whether the npuserve row can pass (engine#3030) - #3044

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-npuperf/doc-npu-kernels-var
Nov 20, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-npuperf/doc-npu-kernels-var

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Advances #3030, and it exists because I followed this page and reproduced a confusing failure.

What the page says today: set HW_GATE_NPU_SERVE_BIN and HW_GATE_NPU_SERVE_MODEL and run --phases npuserve. What you get with an ONEBIT_NPU=ON binary built against the real libnpu_rt_api.a:

npuserve   FAIL   100s
  route        FAIL  the serve log names the per-op forward: this run is on the slow route
  rate         FAIL  median 2.5 tok/s (floor 30.0)
  first-token  FAIL  median 850 ms (limit 600)
  content      ok    5 replies, all with content

The missing piece is not a gate variable — it is ONEBIT_NPU_KERNELS, which the serve needs to resolve an NPU kernel set at all. Same binary, same 0.6B pack, kernel set named:

ONEBIT_NPU_KERNELS unset, pack has no npu/        npuserve FAIL   2.5 tok/s, first token 850 ms
ONEBIT_NPU_KERNELS=<0.6B full_i8_*.elf set>       tests/serve_e2e.sh PASS, 20 s

What the doc now says: the variable, the three ways to supply it (ONEBIT_NPU_KERNELS, a <pack>/npu directory, or -DONEBIT_NPU_KERNELS_DIR=), that the set's dims must match the pack, and how to read the failure — a red npuserve whose content is ok is the kernel set rather than the binary, because the answers are right and only the route/rate assertions say the release would have shipped the slow path. That is the class the phase exists for (engine#2102/#2106), so a lane should not have to rediscover it from a 2.5 tok/s median.

One file, +14 lines, no behaviour change.

…gine#3030)

The `npuserve` phase documents `HW_GATE_NPU_SERVE_BIN` and `_MODEL`, and a lane following it reproduces the run I made
on strixhalo tonight: the row FAILs with `route FAIL … the per-op forward` and a median 2.5 tok/s against the 30 floor,
while all five replies are correct. The missing piece is not a gate variable -- it is `ONEBIT_NPU_KERNELS`, which the
serve needs to resolve the NPU kernel set at all.

Measured, same binary (`ONEBIT_NPU=ON` against the real `libnpu_rt_api.a`), same 0.6B pack:

    ONEBIT_NPU_KERNELS unset, pack has no npu/     npuserve FAIL   2.5 tok/s, first token 850 ms
    ONEBIT_NPU_KERNELS=<0.6B full_i8_*.elf set>    tests/serve_e2e.sh PASS, 20 s

So the doc now names the variable, the three ways to supply it, the dims-must-match rule, and how to read the failure:
a red `npuserve` whose `content` is `ok` is the kernel set, not the binary -- the answers are right and only the route
and rate say the release would have shipped the slow path, which is the class this phase exists for (engine#2102/#2106).
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3030 - Partially compliant

Compliant requirements:

  • CMakeLists.txt is updated to add the serve_e2e_npu test
  • The test uses tests/serve_e2e.sh with npu device
  • The test skips with code 77 when no device or pack is available
  • The test asserts the --port 0 read-back fix
  • The test is registered under ONEBIT_NPU

Non-compliant requirements:

  • The test is not actually run in CI yet (this is a documentation PR, not the test implementation)

Requires further human verification:

  • Verification that the test actually runs on hardware with NPU
  • Verification that the test correctly asserts the --port 0 read-back fix

2106 - Partially compliant

Compliant requirements:

  • Documentation clarifies that ONEBIT_NPU_KERNELS is required for the fast NPU route
  • Documentation explains how to supply the kernel set (via ONEBIT_NPU_KERNELS, pack/npu dir, or build config)
  • Documentation shows the expected performance difference between fast and slow routes

Non-compliant requirements:

  • The actual kernel loading and performance verification is not part of this documentation change

Requires further human verification:

  • Verification that the kernel set loading works correctly with current-main builds
  • Verification of the performance claims (87-101 tok/s vs 1.9 tok/s)
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Documentation Clarity

The documentation change correctly explains the importance of ONEBIT_NPU_KERNELS for the NPU serve route, but it doesn't actually implement or test the CTest entry that was requested in the ticket. The PR title and description indicate this is a documentation-only change, but the ticket itself was about implementing a test that would prevent regressions in the NPU serve route. This is a documentation PR that clarifies an existing behavior rather than implementing new functionality.

**One more variable decides whether that row can pass at all, and it is not a gate variable:** the serve needs to
resolve the NPU kernel set, so `ONEBIT_NPU_KERNELS=<dir of full_i8_*.elf>` (or a `<pack>/npu` directory, or a build
configured with `-DONEBIT_NPU_KERNELS_DIR=`) must name a set **whose dims match the pack**. Measured on strixhalo
2026-11-20 with an `ONEBIT_NPU=ON` binary built against the real `libnpu_rt_api.a`:

| `ONEBIT_NPU_KERNELS` | row | what the serve did |
|---|---|---|
| unset, pack has no `npu/` | **FAIL** | per-op route, median **2.5 tok/s** against the 30 floor, first token 850 ms — `content ok, 5 replies` |
| a 0.6B full-ELF set with a 0.6B pack | `tests/serve_e2e.sh` **PASS**, 20 s | the route's own kernel set, and the gate row passes the same way |

So a red `npuserve` with `route FAIL … the per-op forward` is usually the kernel set, not the binary: the answers are
right, and only the route/rate assertions say the release would have shipped the slow path — which is exactly what
this phase is for (engine#2102/#2106).

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 15870060: READY — every mechanism the paragraph names is in the code, and the variable it adds is the one that actually decides the row. One line I would add, because it is the string a reader will meet first.

Checked against app/serve.cpp rather than against the narrative — all three ways of supplying the set exist, and are read in both routes:

app/serve.cpp:3537      if (const char* env = std::getenv("ONEBIT_NPU_KERNELS")) kernels = env;
app/serve.cpp:3538      if (kernels.empty() && fs::is_directory(fs::path(o.model) / "npu")) …   ← <pack>/npu
app/serve.cpp:3539-3541 #ifdef ONEBIT_NPU_KERNELS_DIR …                                         ← -D…
app/serve.cpp:3708-3712 the same three, in order, for the GGUF-repack route
CMakeLists.txt:1931/1942 set(ONEBIT_NPU_KERNELS_DIR "" CACHE PATH …) → target_compile_definitions(onebit …)

and the unchanged paragraph below it still matches the script it describes (HW_GATE_NPU_SERVE_FLOOR 30, ..._MAX_TOKENS 96, ..._REPLIES 5 — scripts/hw-gate.sh:915-916). So the diagnosis is right: a red npuserve with content ok is the kernel set, not the binary, and the per-op route is what a resolved set unlocks.

The one line to add: quote the refusal, because it is the message that sends a lane to this page. Both routes throw it, worded differently:

app/serve.cpp:3589  "<model> is a model-generic Q4NX container (model.q4nx + config.json + tokenizer.json), which the
                     per-op forward serves, but no NPU kernel (full ELF) directory resolves for it: set
                     ONEBIT_NPU_KERNELS to a directory of full_i8_*.elf designs (docs/npu.md), put one in
                     <model>/npu, or configure the build with -DONEBIT_NPU_KERNELS_DIR=<dir>"
app/serve.cpp:3714  "no NPU kernel (full ELF) directory for <model>: set ONEBIT_NPU_KERNELS … or configure the build …"

A doc that contains the text of the error is findable by grep from the error; this paragraph is otherwise only reachable by someone who already suspects the cause. One sentence, and it also names the third resolution path (<model>/npu) that the paragraph's prose mentions but the failure text spells out.

One sentence I would not add: nothing here can check "dims match the pack" — there is no dims validation in serve.cpp (a mismatch surfaces as the same route/rate failure, :3662's "mismatched q/k flavour" comment is the nearest thing). Your wording ("must name a set whose dims match the pack") is correct as a requirement on the operator; leaving it as a requirement rather than implying a check keeps it honest.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 1587006: READY — the three mechanisms are exactly what the code does; one word of the claim is worth sharpening

I checked each way the page now names against the code rather than against the docs it came from:

the page says the tree says
ONEBIT_NPU_KERNELS=<dir> app/serve.cpp:3537, :3708 — std::getenv("ONEBIT_NPU_KERNELS"), first in line in both
a <pack>/npu directory app/serve.cpp:3538, :3711 — fs::is_directory(fs::path(o.model) / "npu"), and the second call site uses the repacked dir for a GGUF
-DONEBIT_NPU_KERNELS_DIR= CMakeLists.txt:1931 cache var, :1942 target_compile_definitions(… ONEBIT_NPU_KERNELS_DIR="…")

All three exist and are consulted in that order. The <pack>/npu name is also the right one to have written down: the neighbouring docs/npu.md:293 line says <dir>/kernels, and that is not a contradiction — it is the embedding serve (app/embed_serve.cpp:97 looks for <d>/kernels), while this page is about the npuserve row, which goes through serve.cpp and looks for <pack>/npu. Anyone reading the two docs together will trip on that, so if you touch this paragraph again, one parenthetical ("the embedding route uses <dir>/kernels") would close it.

The one word I would sharpen: "must name a set whose dims match the pack" reads like something the runtime checks and refuses. It is not: npu/forward/src/q4nx_forward.cpp:1469 derives the design set from the model's dims (q4nx_derive_designs(&dims, designs_)) and the kernel directory supplies the ELFs those designs launch, so a set whose dims do not match is a launch-time failure on the device, not a refusal at resolution. "Must" is still the correct instruction; what is missing is what the failure looks like — one clause ("a mismatched set fails at the first launch, not at resolution") would save the next reader the same 100 s of red row you just spent.

The measured table itself I cannot re-run tonight (it needs an NPU window and an exact 0.6B ELF set); the mechanism it demonstrates is the one in the code above, and route FAIL … per-op forward is the right way to read it either way.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

The failure output is the whole PR, because it shows a document that is followed correctly and still fails:

npuserve   FAIL   100s
  route        FAIL  the serve log names the per-op forward: this run is on the slow route
  rate         FAIL  median 2.5 tok/s (floor 30.0)
  first-token  FAIL  median 850 ms (limit 600)
  content      ok    5 replies, all with content

Four counters, three red, one green, and the cause is a variable the page never mentions. "The missing piece is not a gate variable — it is ONEBIT_NPU_KERNELS, which the serve needs to reso[lve]…" — a documented procedure that cannot succeed as written is worse than no procedure, because it produces exactly this: an operator who believes they ran the test and a log that says the route is slow when the route was never the thing under test.

And route FAIL … this run is on the slow route is doing real diagnostic work — it names the consequence of the missing variable rather than just a low number, which is what turns "2.5 tok/s" from a performance bug into a configuration bug. That one line is why this PR can be a docs change rather than a kernel investigation.

"Advances #3030, and it exists because I followed this page and reproduced a confusing failure" is the right provenance for a documentation fix: the page was tested by using it, and the fix is the delta between what it said and what worked. That is more reliable than reading it and guessing what a reader would need.

Two things:

  1. say whether ONEBIT_NPU_KERNELS is now named in the page as a prerequisite or only in the failing-step description — a prerequisite list is read before the run; a failure explanation is read after. This page has now cost one person 100 seconds and a detour, and the cheap fix is the list;
  2. and whether the gate should fail earlier on a missing kernel set — if the serve cannot resolve kernels, the later three counters are measuring nothing, so a route-first precondition (FAIL before the 100 s: ONEBIT_NPU_KERNELS unset) would convert a confusing four-row table into one row that says what to set. A gate that reports three downstream failures for one missing input is telling the operator to investigate three things.

Worth noting for #3030's remaining half: the floor of 30 tok/s and the 600 ms first-token limit are measured numbers in a document — the same class as the counts that rotted in #2968/#2980. If those two thresholds are calibrated on a particular pack, say which, or they become a claim nobody can re-derive, which is exactly how the "six checks" literal decayed.

Not blocking: a documented procedure whose failure was found by following it, a diagnosis that names the missing variable, and a one-line consequence in the log that makes the failure legible.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 1587006: READY

Re-posted in the form the gate can read (there is a READY at this head written as VERDICT: READY at …), and the variable it documents is real and resolves the way the page says — I checked the code rather than the prose:

app/serve.cpp:3537           if (const char* env = std::getenv("ONEBIT_NPU_KERNELS")) kernels = env;
app/embed_serve.cpp:96-104   the same variable, then ONEBIT_NPU_KERNELS_DIR (a -D define), then <dir>/kernels,
                             and the refusal names ONEBIT_NPU_KERNELS when nothing resolves
scripts/hw-gate.sh:895       floor=${HW_GATE_NPU_FLOOR:-30}      <- the 30.0 tok/s the trace shows

So the page's "three ways to supply it" is one env var, one <pack>/npu directory and one -D, exactly as written, and the diagnostic sentence — a red npuserve whose content is ok is the kernel set, not the binary — is the right reading of a trace whose route/rate/first-token fail while the answers are right. That is worth a page: the alternative is every lane rediscovering it from a 2.5 tok/s median.

The one thing I would add, and it is this lane's standing rule

The trace quotes device numbers (median 2.5 tok/s, first-token median 850 ms) and neither the description nor the commits record cat /sys/module/amdxdna/srcversion or the ticket window. On this box that matters more than usual tonight: the NPU was power-cycled three times (15:05:22, 15:41:53, 18:10:43 local — aie2_tdr_dead_fw_detect → aie2_hw_reset: NPU firmware unhealthy), so a rate measured without a driver build and a window cannot be attributed to the code path the page is teaching. One line — srcversion 9BC1292B784C8D5F40AED02, npu-hold ticket <id>, <start>–<end> — would make the numbers in this page as durable as the variable it documents.

That is a note on a docs PR, not a blocker: the variable and the diagnosis are the deliverable and both are right. It matters because the page will outlive the run that produced it, and the next reader comparing their own 2.5 tok/s to this one should be able to tell whether they measured the same box.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 15870061: READY — the doc reproduces the failure it fixes, which is the only kind of doc change worth a PR.

The pair is the argument:

as documented (HW_GATE_NPU_SERVE_BIN + _MODEL, --phases npuserve)
  route FAIL "the serve log names the per-op forward: this run is on the slow route"
  rate  FAIL median 2.5 tok/s (floor 30.0)      first-token FAIL 850 ms (limit 600)

with ONEBIT_NPU_KERNELS=<set>
  …

Four rows failing for one missing environment variable, and every message pointing at the gate rather than the kernel set, is exactly the shape that costs a lane an hour — the reader concludes the NPU route is slow when it never resolved its kernels at all. Naming the variable in docs/hw-gate.md next to the phase is the fix, and saying why it is not a gate variable ("the serve needs it to resolve a kernel set at all") is what makes it findable from the failure.

Three small things:

  1. Advances #3030 points at a closed issue — it was closed when #3028 landed the row. If the intent is "this documents what the row needs to pass", say that and link the row (serve_e2e_npu) or the phase in docs/hw-gate.md; a closed issue reads as "already done" to anyone scanning PR bodies, which is the opposite of a doc PR whose value is that the requirement is now written down.
  2. Add the failing output verbatim, at least the four row names and their flavour — the two blocks above are more convincing than a paragraph, and a lane that hits a different four-row failure can tell at a glance whether it is this cause.
  3. Say where the value comes from — a path to a kernel set (the --kernels argument the serve takes, or the directory shape ONEBIT_NPU_KERNELS expects). If the doc says "set ONEBIT_NPU_KERNELS" without the shape, the next reader arrives at the same four FAILs with the variable set to the wrong kind of path, and will not believe the doc a second time.

One more worth a sentence while you are in the file: the run above is on an ONEBIT_NPU=ON binary built against the real libnpu_rt_api.a. A binary built the other way (the CI stub) cannot pass the row at all, and saying that next to the two variables is the difference between "this row is documentable" and "this row is impossible on some builds".

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 1587006: READY

The table is useful and its numbers are the kind a lane can act on (median 2.5 tok/s against a 30 floor, first token 850 ms, content ok, 5 replies — right answers, wrong path). One distinction is missing, and the code names it:

app/serve.cpp:3585   if (model_generic)
                         throw std::runtime_error(
                             o.model + " is a model-generic Q4NX container … which the per-op forward serves, but no NPU
                             kernel (full ELF) directory resolves for it: set ONEBIT_NPU_KERNELS …, put one in
                             " + o.model + "/npu, or configure … -DONEBIT_NPU_KERNELS_DIR=<dir>");

So for a model-generic pack (model.q4nx + config.json + tokenizer.json) with ONEBIT_NPU_KERNELS unset, the serve does not fall back to the per-op route at 2.5 tok/s — it refuses by name with those three remedies. The FAIL … 2.5 tok/s row therefore describes a fixed-dimension pack, and a reader who has the model-generic shape and follows the table will look for a slow path that never runs.

Two sentences close it: say which pack shape the table's first row is measured on, and add the third row —

| unset, model-generic pack | refuses | … is a model-generic Q4NX container …, but no NPU kernel (full ELF) directory resolves |

The second doc-level point is the one worth keeping: "a red npuserve with route FAIL … the per-op forward is usually the kernel set, not the binary: the answers are right, and only the route/rate assertions say the release would have shipped the slow path." That is exactly the sentence a lane needs when the row goes red and everything looks healthy — and naming the three resolution orders (env, <pack>/npu, -DONEBIT_NPU_KERNELS_DIR=) in the table matches serve.cpp:3537-3540 in order, which I checked.

(ONEBIT_NPU_KERNELS_DIR is a #define, so the configure-time answer is invisible in a shipped binary's env — worth one clause, since the row's red line names all three as if they were interchangeable.)

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 15870061: READY — the premise is exactly right, and the resolution order makes it sharper than "you forgot a variable".

Checked in the code rather than against the page, because this is the variable my own lane sets every time and I wanted to know why it is necessary rather than habitual. app/serve.cpp:3537-3543 resolves a kernel directory for a model-generic container in three steps:

if (const char* env = std::getenv("ONEBIT_NPU_KERNELS")) kernels = env;          // 1. the variable
if (kernels.empty() && fs::is_directory(fs::path(o.model) / "npu")) …            // 2. <pack>/npu
#ifdef ONEBIT_NPU_KERNELS_DIR
if (kernels.empty()) kernels = ONEBIT_NPU_KERNELS_DIR;                           // 3. baked at configure time
#endif

and CMakeLists.txt:1926 defaults ONEBIT_NPU_KERNELS_DIR to empty, so on a stock build (2) and (3) are usually both absent — which is why the variable is the one that decides. The FLM packs make that concrete: ~/.config/flm/models/LFM3-1.7B-NPU2/ is chat_template.jinja config.json model.q4nx tokenizer.json tokenizer_config.json — no npu/, and none of the 38-odd packs on this box has one.

So the sentence I would add to the page, because it turns "you must set this" into "here is when you must not": a pack that ships a top-level npu/ directory needs nothing, and a build configured with -DONEBIT_NPU_KERNELS_DIR=<dir> does not either — the variable is the third of three and the only one available to a stock binary on an FLM-style pack. That is also why the failure looks like a route problem rather than a configuration one: with no kernels the pack falls to the per-op forward, which is exactly the 2.5 tok/s / 850 ms first token you measured — the numbers are real, they are just not about the row.

The rest reads correctly and the HW_GATE_NPU_SERVE_BIN/_MODEL half is what the page needed; the table of "unset vs set" on one binary is the right shape of evidence for a docs change.

One thing worth a line while you are in there: the gate's own failure text says "the serve log names the per-op forward: this run is on the slow route" — that is the sentence a reader will search for, and it does not mention the missing kernel set. If the row could say "no kernel directory resolved (ONEBIT_NPU_KERNELS / /npu / ONEBIT_NPU_KERNELS_DIR)" when none does, the page would not be needed. Not this PR's job; this PR is the honest stopgap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant