Repository navigation
npu forward: host-GEMM needs no ELF set, so a geometry without kernels still answers (#796) - #833
Conversation
…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.
PR Reviewer Guide 🔍(Review updated until commit c7ad589)Here are some key observations to aid the review process:
|
|
The second-consumer row landed (deliberately not claimed in the body before it was measured). So the change does not merely let The six derives the engine logged on the way are also an independent confirmation of #796's design set — the same six, |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
|
Persistent review updated to latest commit c7ad589 |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
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.
The problem
Host-GEMM mode is the offline path:
npu_gemm()does a plain float matmul over the decoded weights and the device isnever 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:
That is the whole reason engine #796's rung 1 ("loads under
NPU_INFER_HOST_GEMM=1with no device") was gated on thesame 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: nofile_existsrefusal. The role prints the artifact namewhen it is on disk and the geometry plus the missing name when it is not:
The device path keeps every check it had (
file_existsandinit_elf), and an ELF set is still whattests/verify_design_elfs+tests/verify_full_elfs.shverify — this only stops the offline path from requiring anartifact it never opens.
q4nx_forward.h'sinit_hostcontract anddocs/npu.md's d3 section said the opposite, soboth are corrected in the same commit.
Measured (strixhalo, real
vllm-sr/d3-litepack, onenpu-hold -l npufeatticket, 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):(host-GEMM, no ELF: …)— and the model loads/health→max_input_tokens 32768, modalities ["text"]choice{"choice":"b","confidence":0.0980,"probabilities":{"a":0.3179,"b":0.6821}}— sums 1.000000noul{"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"}}invalid_questions, nothing ranamdxdnaerrors after the runctest npu_plan npu_plan_generate safetensors_to_q4nx npu_sampling systemone_contract systemone_routetools/copyright.py --checkNo 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.pyis not measured: the reference needstransformers.models.qwen3_5, and thebox's user-site
transformersis a broken install (…/site-packages/transformers/modelsmissing,huggingface-hub 2.4.0vs the<2.0pin).torch 2.13.0+cpuandsafetensorsimport fine, so that comparison needs a clean venv —its own piece of work.
Not done, deliberately
No new ctest:
forward-serveis only compiled underONEBIT_NPU=ON, which CI does not configure, so the path cannotbe covered from the default build. The check that does cover a no-ELF container is the existing host-only
mtp_batch_allctest, 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 runningunder a ticket and will be added here as a comment rather than claimed in advance.