Skip to content

npu forward: host-GEMM needs no ELF set, so a geometry without kernels still answers (#796) - #833

Merged
bong-water-water-bong merged 2 commits into
mainfrom
npu/host-gemm-no-elfs
Nov 2, 2026
Merged

bong-water-water-bong merged 2 commits into
mainfrom
npu/host-gemm-no-elfs

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

The problem

Host-GEMM mode is the offline path: npu_gemm() does a plain float matmul over the decoded weights and the device is
never opened. It still asserted the geometry→artifact mapping, so a model whose kernel set has not been built yet
refused to load even with no device involved
:

1bit forward-serve: forward init failed: plan /home/bcloud/models/npu/d3-lite-conv/plan.json:
  this model's plan needs the QKV kernel "full_i8_QKV_K1024_N5120.elf" in … (missing)

That is the whole reason engine #796's rung 1 ("loads under NPU_INFER_HOST_GEMM=1 with no device") was gated on the
same six AIE designs as the device rung, and it is why the d3-lite pack could be converted, verified and not asked
anything.

The change

npu/forward/src/q4nx_forward.cpp, host-GEMM branch only: no file_exists refusal. The role prints the artifact name
when it is on disk and the geometry plus the missing name when it is not:

[forward] QKV M=128 K=1024 N=5120  (host-GEMM, no ELF: full_i8_QKV_K1024_N5120.elf)

The device path keeps every check it had (file_exists and init_elf), and an ELF set is still what
tests/verify_design_elfs + tests/verify_full_elfs.sh verify — this only stops the offline path from requiring an
artifact it never opens. q4nx_forward.h's init_host contract and docs/npu.md's d3 section said the opposite, so
both are corrected in the same commit.

Measured (strixhalo, real vllm-sr/d3-lite pack, one npu-hold -l npufeat ticket, no device opened)

Pack converted by #819 (320 tensors, 782 MB, H=1024, 24 layers, 18 GDN layers) plus its real decision head
(readout.safetensors + decision_config.json → decision.q4nx, 255×1024 f32, 255 codes):

row result
ELF policy 6 designs, all (host-GEMM, no ELF: …) — and the model loads
ready 2 s; /health → max_input_tokens 32768, modalities ["text"]
choice {"choice":"b","confidence":0.0980,"probabilities":{"a":0.3179,"b":0.6821}} — sums 1.000000
noul {"noul":0.6882}
score {"score":1.1246,"confidence":0.0432,"probabilities":{"0":0.2090,"1":0.4575,"2":0.3335},"legend":{"0":"bad","1":"ok","2":"great"}}
one malformed sibling 422 invalid_questions, nothing ran
chat route, same pack runs (12 empty pieces — a decision-tuned backbone with the empty-think template is not a chat model)
amdxdna errors after the run 0; no device fd; die 67 °C
ctest npu_plan npu_plan_generate safetensors_to_q4nx npu_sampling systemone_contract systemone_route 6/6 PASS
tools/copyright.py --check rc 0

No accuracy is claimed. These are the engine's own host-GEMM answers over the converted q4_1 weights. Parity
against the pack's d3_runtime.py is not measured: the reference needs transformers.models.qwen3_5, and the
box's user-site transformers is a broken install (…/site-packages/transformers/models missing, huggingface-hub 2.4.0 vs the <2.0 pin). torch 2.13.0+cpu and safetensors import fine, so that comparison needs a clean venv —
its own piece of work.

Not done, deliberately

No new ctest: forward-serve is only compiled under ONEBIT_NPU=ON, which CI does not configure, so the path cannot
be covered from the default build. The check that does cover a no-ELF container is the existing host-only
mtp_batch_all ctest, which used to SKIP on exactly this refusal:
ONEBIT_TEST_Q4NX=<dir with an empty kernels/> ./mtp_batch_all_test. Its row for the converted d3 pack is running
under a ticket and will be added here as a comment rather than claimed in advance.

…s still answers (#796)

The forward asserted the geometry->artifact mapping in host-GEMM mode too, so
NPU_INFER_HOST_GEMM=1 refused to load any model whose kernel set had not been
built yet:

  forward init failed: plan .../plan.json: this model's plan needs the QKV
  kernel "full_i8_QKV_K1024_N5120.elf" in ... (missing)

That made engine #796's rung 1 ("loads and answers with no device") gated on
the same six AIE designs as the device rung.  Host GEMMs are plain float
matmuls over the decoded weights: no ELF is opened on this path, so none is
required.  The artifact is still named when it is on disk; when it is not, the
role logs the geometry and the missing name instead of failing.  The device
path keeps every check it had (file_exists + init_elf), and the ELF set itself
is what tests/verify_design_elfs + tests/verify_full_elfs.sh check.

Measured on the real vllm-sr/d3-lite pack converted by #819 (320 tensors,
782 MB, host 1024, 24 layers, 18 GDN layers), NPU_INFER_HOST_GEMM=1, one
npu-hold ticket, no device opened:

  [forward] QKV M=128 K=1024 N=5120  (host-GEMM, no ELF: full_i8_QKV_K1024_N5120.elf)
  ... six designs, all "no ELF"
  ready in 2 s; /v1/systemone answers choice, noul and score; probabilities sum
  to 1.000000; a malformed sibling still 422s the whole request; 0 amdxdna errors

This does not claim accuracy: the numbers are the engine's own host-GEMM answer
over the converted weights, and parity against the pack's d3_runtime.py is not
measured here.
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit c7ad589)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

796 - Partially compliant

Compliant requirements:

  • Host rung: the real pack converts and loads under NPU_INFER_HOST_GEMM=1 with no device opened, and answers through the route
  • Host rung: numeric parity against the pack's own d3_runtime.py with the three transforms each covered by a known-answer test

Non-compliant requirements:

  • Device rung: the 7-design ELF set is not included in this PR
  • Accuracy rung: a real d3 row against upstream is not included in this PR

Requires further human verification:

  • Device rung validation requires the 7-design ELF set to be built and available
  • Accuracy rung validation requires a labelled evaluation against upstream

819 - Partially compliant

Compliant requirements:

  • The pack conversion tool works with the real d3 pack
  • Three transforms are implemented with known-answer tests
  • Name mapping is handled correctly
  • Bugs in embedding shape and text_config handling are fixed
  • npu_plan.py is fixed to account for attn_output_gate
  • Measured performance and verification results are provided

Non-compliant requirements:

  • The PR does not include the 7-design ELF set required for device rung

Requires further human verification:

  • The 7-design ELF set needs to be built and validated separately
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Host-GEMM ELF Requirement

The change removes the requirement for ELF files in host-GEMM mode, which allows models to load and answer without the device being opened. This is a significant behavior change that should be carefully validated to ensure that all necessary components are still correctly initialized and that the model's behavior is consistent with expectations.

if (host_gemm_) {
    // Offline mode: host GEMMs are plain float matmuls over the decoded weights, so
    // no ELF is opened and none is required.  A model whose kernel set has not been
    // built yet can be loaded and prompted, which is what makes it a usable
    // numeric reference for a new geometry (engine #796: the d3-lite backbone
    // answers on the host while its six designs do not exist).  The artifact is
    // named when it is there; the ELF set itself is checked by
    // tests/verify_design_elfs + tests/verify_full_elfs.sh, not by this path.
    std::string elf = dir + "/" + g->elf_name;
    if (file_exists(elf)) {
        fprintf(stderr, "  [forward] %-3s M=%d K=%d N=%d  %s (host-GEMM)\n",
                role_tag(g->role), g->M, g->K, g->N, elf.c_str());
    } else {
        fprintf(stderr, "  [forward] %-3s M=%d K=%d N=%d  (host-GEMM, no ELF: %s)\n",
                role_tag(g->role), g->M, g->K, g->N, g->elf_name);
    }
} else {
Documentation Update

The documentation for init_host has been updated to clarify that no ELF is required in host-GEMM mode. This is important for developers to understand the difference between host-GEMM and device modes, and to avoid confusion about when ELFs are needed.

// Host-GEMM mode (NPU_INFER_HOST_GEMM=1): never opens the device.  Design
// derivation, weight decode and the layer maths all run, but npu_gemm() does a
// plain float matmul, and **no ELF is required** — a geometry whose kernel set
// has not been built yet can still load and answer.  This validates the whole
// forward against the Python reference offline, which is how the C++ GDN port is
// checked without the shared NPU (see docs/qwen35-4b-weight-format.md).
Clarification of Artifact Requirements

The documentation now clearly states that the artifact set is only required for device rows, not for host-GEMM mode. This helps clarify the behavior and requirements for different execution modes.

What is still missing for a real d3 row is the **artifact set** — but only for a *device* row. `NPU_INFER_HOST_GEMM=1`
opens no device, so it needs no ELF: the backbone loads, answers, and serves as the numeric reference for a geometry
whose kernels do not exist yet (this is how `d3-lite` is exercised before its six designs are built). A device row
needs all six — `QKV K1024 N5120` (q|gate|k|v, `q_proj` carries the output gate), `O K2048 N1024` (GDN's `ssm_out`
reuses it), `GU K1024 N7168`, `D K3584 N1024`, GDN `QKV K1024 N6144` and `Z K1024 N2048` — and without them the
device path stops at `forward init failed: … this model's plan needs the QKV kernel "full_i8_QKV_K1024_N5120.elf" …
(missing)`.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

The second-consumer row landed (deliberately not claimed in the body before it was measured). mtp_batch_all is the
existing host-only ctest that used to SKIP on exactly the refusal this PR removes — ONEBIT_TEST_Q4NX pointed at a
container whose kernels/ dir is empty (0 files):

--- artifact dir /tmp/d3rung1-test/kernels holds 0 files
container /tmp/d3rung1-test/model.q4nx, vocab 248320
PASS  row 0: batched vs sequential rel-L1 0.00e+00 (max|d| 0.00e+00), argmax 1 vs 1
PASS  row 1: batched vs sequential rel-L1 0.00e+00 (max|d| 0.00e+00), argmax 220 vs 220
PASS  last row == step_batch(): rel-L1 0.00e+00, argmax 220 vs 220
PASS  repeat run identical: rel-L1 0.00e+00
all checks passed   rc=0

So the change does not merely let forward-serve start: an ELF-less container now initialises and computes
correctly
(step_batch_all vs sequential decode, exact, and stable across a repeat). Ticket
01793638035440830962.npufeat (queued 12:47:15, took the token 12:58:17 after 656 s, held 5 s, die 52 °C),
amdxdna errors after: 0, no device fd.

The six derives the engine logged on the way are also an independent confirmation of #796's design set — the same six,
from the engine's own geometry rather than from the issue text (note Z, which is the GDN output gate):

QKV M=128 K=1024 N=5120   O  K=2048 N=1024   GU K=1024 N=7168
D   M=128 K=3584 N=1024   QKV(GDN) K=1024 N=6144   Z K=1024 N=2048

@bong-water-water-bong bong-water-water-bong added the tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied label Nov 2, 2026

@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 at 3a529db11 — reproduced on the pack the body names, and the whole offline claim holds.

Built at this head (Release, -G Ninja, gcc-16, -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=<private rt>), then ran the d3-lite pack that has no ELF set in its kernels/:

NPU_INFER_HOST_GEMM=1 NPU_NO_DEVICE_LOCK=1 1bit forward-serve -m ~/models/npu/d3-lite-conv/model.q4nx \
    --kernels ~/models/npu/d3-lite-conv/kernels -p 18099
  [forward] QKV M=128 K=1024 N=5120  (host-GEMM, no ELF: full_i8_QKV_K1024_N5120.elf)
  [forward] O   M=128 K=2048 N=1024  (host-GEMM, no ELF: full_i8_O_K2048_N1024.elf)
  [forward] GU  M=128 K=1024 N=7168  (host-GEMM, no ELF: full_i8_GU_K1024_N7168.elf)
  [forward] D   M=128 K=3584 N=1024  (host-GEMM, no ELF: full_i8_D_K3584_N1024.elf)
  [forward] QKV M=128 K=1024 N=6144  (host-GEMM, no ELF: full_i8_QKV_K1024_N6144.elf)
  [forward] Z   M=128 K=1024 N=2048  (host-GEMM, no ELF: full_i8_Z_K1024_N2048.elf)
  1bit forward-serve: d3-lite-conv ready on http://127.0.0.1:18099 (full ELF)

GET  /v1/models              -> 200
POST /v1/chat/completions    -> 200, prompt_tokens 12, completion_tokens 8

Before this commit the same command stopped at exactly the refusal the body quotes (… this model's plan needs the QKV kernel "full_i8_QKV_K1024_N5120.elf" … (missing)), and the six names above are the six designs the doc lists. The
content of the completion is newlines — this pack is the synthetic d3-lite backbone, so that is the model, not the
harness; what the PR claims is that it loads and answers, and it does.

The device path is untouched by the diff (file_exists and init_elf still in the else branch), which I checked by
reading rather than by running: exercising it means opening xrt::device(0) and the owner's serve holds the NPU.

One thing worth knowing, pre-existing and not this PR's fault: with NPU_INFER_HOST_GEMM=1 alone, forward-serve still
takes the exclusive NPU device lock first (take_npu_device_lock(streams) at app/forward_serve.cpp:725, before the
host_gemm test at :732), so on a box where the NPU is busy the "offline" path waits on the fleet's lock even though it
never opens the device. The run above needed NPU_NO_DEVICE_LOCK=1 for that reason. Since the whole point of #796's rung
1 is a geometry that can be exercised without the device, skipping the lock when host_gemm is on would make the offline
story true on a shared box — a follow-up, not a blocker.

CI at this head: build pass 4m52s, CodeQL pass, Analyze (c-cpp) pass, pr_agent pass. tprs-ready applied.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Persistent review updated to latest commit c7ad589

@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 at c7ad589b3 — re-head after the update-branch, and I re-ran the offline load on a binary built from this
exact head rather than carrying the earlier run.

The PR's own hunk is byte-identical to 3a529db11 (diff of the two git diff … -- npu/forward/src/q4nx_forward.cpp
hunks prints nothing); the file only looks different because main's #826 (t2s, valid_sidecar_dir) is now under it. Own
diff is 3 files, +25/−14.

Re-run at this head, Release/-G Ninja/gcc-16, -DONEBIT_NPU=ON -DONEBIT_NPU_RUNTIME=own -DONEBIT_NPU_RT_DIR=<private rt>:

NPU_INFER_HOST_GEMM=1 NPU_NO_DEVICE_LOCK=1 1bit forward-serve -m ~/models/npu/d3-lite-conv/model.q4nx \
    --kernels ~/models/npu/d3-lite-conv/kernels -p 18098
  six  "[forward] <ROLE> M=128 K=… N=…  (host-GEMM, no ELF: full_i8_…elf)"  lines
  1bit forward-serve: d3-lite-conv ready on http://127.0.0.1:18098 (full ELF)
GET /v1/models -> 200

Six of six designs load with no ELF on disk, which is the claim. The device branch is unchanged (file_exists and
init_elf both still there) — read, not run, because exercising it would open xrt::device(0) and the owner's serve holds
the NPU.

CI at this head: build pass 4m43s, CodeQL pass, pr_agent pass, and the PR is CLEAN. tprs-ready is on, so this
line is the merge gate for the head the waiter will squash. The one follow-up I would keep on the list is the pre-existing
one: forward-serve takes the exclusive NPU device lock at app/forward_serve.cpp:725, before the host_gemm test at
:732, so the offline path waits on a busy NPU unless NPU_NO_DEVICE_LOCK=1 — which is what the run above needed.

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

Labels

Review effort 3/5 tprs-ready TPRS: review verdict READY posted by the standing reviewer; merge gate satisfied

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant