Repository navigation
npu forward: read the engine converter's MoE container, so a converted Qwen3-30B-A3B runs on the device (refs #1035) - #1266
Merged
Conversation
…ig keys and the per-expert tile grid (refs #1035) A container built by tools/gguf_to_q4nx.py from a qwen3moe GGUF loaded as DENSE: it carries num_experts/num_experts_per_tok (HF names) and mlp.experts.*_proj.weight tensors, while the forward read n_expert/top_k and the FastFlowLM-style *_exps_proj names. n_expert_ stayed 0, so layer 0 asked for a mlp.gate_proj.weight the container does not have and the first token died with 'MLP dequant : data_size 0 at geometry 768x2048' (engine#1035). Even with the names fixed the expert slices would have been silently permuted: the converter writes a plain [N][K] tile grid, the forward decoded [K][N] (same bytes, corr 0.99999 vs the GGUF on [N][K] and 0.00855 on [K][N] on Qwen3-30B expert 0). npu/forward/include/moe_container.h holds the two conventions in one table (names, router bias, HF vs llama.cpp config keys, and the per-expert decode geometry); q4nx_forward detects the convention from layer 0's gate tensor and uses it in the standard and GDN-MoE load paths and in mla_expert. mla_expert's design check now accepts a fused-GU plan's batched GB/UB designs (a converted qwen3moe plan is fused and has no G/U), and a failed moe_mlp keeps its reason instead of collapsing to 'moe failed'. Test: tests/npu_moe_container_test.cpp (+ .sh self-compile, CTest npu_moe_container) is a known-answer check: both spellings, the config fallbacks, the geometry each convention selects, and a q4_1 slice built with a known [N][K] weight decoded through the shipped q4nx_dequant.c -- the selected grid recovers it exactly, the other grid does not.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 6, 2026
…ixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 6, 2026
…ixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was. One row of the gate was a citation rather than a check, and is now a check: §4 item 4 asks for `--npu-target xdna` as the default with an unknown name refused by name, and A1 had no such option at all -- the name appeared only in a comment in npu/target/target.h and in the design doc, so the earlier "PASS: from the A1 design row" was a claim about the document. The flag now exists: `forward-serve --npu-target <name>` (defaulting to XdnaTarget::kName), `serve` carries it through to that child, and an unknown name is refused **before the device is opened**, which is what makes the row measurable without a ticket.
|
Failed to review PR |
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 6, 2026
…ixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was. One row of the gate was a citation rather than a check, and is now a check: §4 item 4 asks for `--npu-target xdna` as the default with an unknown name refused by name, and A1 had no such option at all -- the name appeared only in a comment in npu/target/target.h and in the design doc, so the earlier "PASS: from the A1 design row" was a claim about the document. The flag now exists: `forward-serve --npu-target <name>` (defaulting to XdnaTarget::kName), `serve` carries it through to that child, and an unknown name is refused **before the device is opened**, which is what makes the row measurable without a ticket.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 6, 2026
…ixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was. One row of the gate was a citation rather than a check, and is now a check: §4 item 4 asks for `--npu-target xdna` as the default with an unknown name refused by name, and A1 had no such option at all -- the name appeared only in a comment in npu/target/target.h and in the design doc, so the earlier "PASS: from the A1 design row" was a claim about the document. The flag now exists: `forward-serve --npu-target <name>` (defaulting to XdnaTarget::kName), `serve` carries it through to that child, and an unknown name is refused **before the device is opened**, which is what makes the row measurable without a ticket.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 6, 2026
…ixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was. One row of the gate was a citation rather than a check, and is now a check: §4 item 4 asks for `--npu-target xdna` as the default with an unknown name refused by name, and A1 had no such option at all -- the name appeared only in a comment in npu/target/target.h and in the design doc, so the earlier "PASS: from the A1 design row" was a claim about the document. The flag now exists: `forward-serve --npu-target <name>` (defaulting to XdnaTarget::kName), `serve` carries it through to that child, and an unknown name is refused **before the device is opened**, which is what makes the row measurable without a ticket.
bong-water-water-bong
added a commit
that referenced
this pull request
Nov 7, 2026
…808) * npu: extract the XDNA launch layer behind NpuTarget (engine#799 P4, fixes #803) Same content as the 13-commit stack on npu/plan-p4-target, re-applied onto origin/main 7153bed as ONE commit: the branch had accumulated fifteen "merge origin/main" commits, one per re-gate, and the repo squashes on merge anyway. npu(p4): extract the XDNA launch layer behind NpuTarget (engine#799 P4 / #803) docs(npu-p4): the Apache-2.0 notice tools/copyright.py requires npu(p4): consume P1's plan loader in NpuTarget::open instead of duplicating the derivation npu(p4): the LM head falls back through ctx_for(), so a set with no M=16 twins still runs npu(p4): the pb16i role split is the target's state, so setup asks it instead of assigning npu(p4): the kernel family is the forward's to name, so open() takes it npu(p4): the rotation is one implementation, so the target calls hadamard.h too npu(p4): the head's ternary flag is head_pb16i_, not a self-reference npu(p4): the rebase put a_k in the wkey/sc slots, so pass all three as main does docs(npu-p4): name the gemv family's boundary in A1, now that #885 is in the rebase npu(p4): the m16 debug comparison takes its difference at int64 width npu(p4): the target headers take npu-relative includes, so CI's syntax target compiles them chore: re-trigger CI Rebased rather than merged this time, because the merge caravan is what has been voiding the gate: each "merge origin/main" moved the head, so fourteen pairings were spent keeping a table honest against a tree that kept moving. The split's own files are byte-identical to the reviewed ones (blob check in the PR): npu/target/target.h, npu/target/xdna/*, npu/forward/include/q4nx_lh.h, docs/npu-p4-target-split.md. The three that differ are the three main changed: CMakeLists.txt (main's test registrations), and q4nx_forward.{h,cpp}, which now carry main's newer forward work (#1243's AVX2/FMA attention, #1266's MoE container) *on top of* the split -- verified by grepping the moved-in symbols in the rebased file, not by trusting the clean merge. Nothing in here changes numerics: the device and launch layer moved, the 38 launch sites became role-based calls, and the model math stayed where it was. One row of the gate was a citation rather than a check, and is now a check: §4 item 4 asks for `--npu-target xdna` as the default with an unknown name refused by name, and A1 had no such option at all -- the name appeared only in a comment in npu/target/target.h and in the design doc, so the earlier "PASS: from the A1 design row" was a claim about the document. The flag now exists: `forward-serve --npu-target <name>` (defaulting to XdnaTarget::kName), `serve` carries it through to that child, and an unknown name is refused **before the device is opened**, which is what makes the row measurable without a ticket. * npu(p4): the host fallback pads its activations too, so a padded design cannot be read past its buffer Review of #808 found the regression this move introduced: main pads A from the design's real_k up to K before branching, and the split moved that pad into XdnaTarget while leaving the host branch of npu_gemm()/npu_gemm_rows() on the raw A. At a padded design (0 < real_k < K, e.g. hidden 896 stored at K=1024) the host matvec then read A[real_k..K) past the caller's buffer, and the rows form read at stride K from a buffer laid out at stride real_k -- every row after the first was the wrong row as well as an overrun. It fires under NPU_INFER_HOST_GEMM=1/init_host, which is #796 rung 1's reference path. The pad and the multiply are one decision, so they now live in one function: q4nx_host_gemm_f32_padded() (q4nx_pack.{h,c}) zero-fills the tail into scratch and runs the loop at stride K; both host branches are one call to it, so no caller can take the read without the pad. a_k <= 0 (the MLA designs) and a_k >= K keep their old path exactly. tests/host_gemm_pad_test.c (ctest host_gemm_pad) pins it with a NaN guard tail after the activation buffer, so an implementation that reads past the buffer fails even when its numbers look plausible. Checked by breaking the code rather than by watching it pass: with the pad disabled it reports 'worst |d| 60' and 'got 0 want 1' on the guard for the 896-of-1024 case, and passes once restored. Also: the design doc now records that the engine#666 canary retry is conditional on !ctx.gemv because readback() only verifies for a non-gemv context -- not a dropped safety, and worth saying so where a reader will look. * ci: bind host_gemm_pad_test to a target CI already builds, so ctest runs it ci.yml names its build targets explicitly and needs the `workflow` scope to extend, which this lane's token does not have. Without the binding the new row reports 'Not Run' and the job fails after 106 tests have passed -- which is exactly what happened on f605dbe. Same mechanism as hadamard_rotate_test and attn_math_test on the line above. --------- Co-authored-by: bong-water-water-bong <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A converted MoE container loaded as a DENSE model, and would have permuted its experts if the names had been the only problem. Both are fixed; a Qwen3-Coder-30B-A3B Q4_K_M container converted by
tools/gguf_to_q4nx.pynow loads and answers on the NPU. The throughput row is measured below, with the next blockers named.Root cause (measured, not inferred)
tools/gguf_to_q4nx.pywrites the engine's own MoE convention:num_experts/num_experts_per_tok/moe_intermediate_size;model.layers.N.mlp.gate.weight, the routed stacks aremodel.layers.N.mlp.experts.{gate,up,down}_proj.weight, each a plain[N][K]per-expert tile grid.npu/forward/src/q4nx_forward.cppread the FastFlowLM-style convention instead:n_expert/top_k,moe_router.weight,mlp.*_exps_proj.weight, and decoded an expert slice on a[K][N]grid. Son_expert_stayed 0, layer 0 took the dense path, asked for amlp.gate_proj.weightthe container does not carry, and the first token died withThe grid half is silent: on Qwen3-30B expert 0 the converter's bytes correlate 0.99999 with the GGUF on
[N][K]and 0.00855 on[K][N].Also fixed on the way: with a fused-GU plan (what a converted qwen3moe plan is: QKV, O, GU, D, GB, UB)
moe_mlprefused with "MoE designs missing" because it required the split G/U designs; it now accepts the batched GB/UB designs, which those containers use. And a failedmoe_mlpkeeps its reason instead of collapsing to "moe failed" (that cost a ticket).Change
npu/forward/include/moe_container.h(new): the two conventions in one table — tensor suffix names, optional router bias, HF vs llama.cpp config keys, and the decode geometry for an expert slice.npu/forward/src/q4nx_forward.cpp: the convention is detected from layer 0's gate tensor (both spellings exist on disk; neither means the old FLM assumption), then used by the standard and GDN-MoE load paths and bymla_expert; config keys fall back fromn_expert/top_ktonum_experts/num_experts_per_tokandmoe_intermediate_size.tests/npu_moe_container_test.cpp+.sh(CTestnpu_moe_container, self-compiling, no NPU runtime): a known-answer test — both spellings, the config fallbacks, the geometry each convention selects, and a q4_1 slice carrying a known[N][K]weight decoded through the shippedq4nx_dequant.c; the selected grid recovers the weights exactly, the other grid does not.CI (default build, current main):
ctest -R 'npu_moe_container|npu_forward_loader|npu_plan|npu_padded_grid|npu_t2_layout|safetensors_to_q4nx'8/8 pass;tools/copyright.py --checkrc 0.On the device (strixhalo, npu-hold, current main a6c9bf5 + this patch)
forward-serve -m ~/models/npu/qwen3-coder-30b-a3b-moe/model.q4nx --kernels ~/models/npu/qwen3-coder-kernels, under one npu-hold ticket (queued 11:16:45, token after 0 s, held 196 s, released 11:20:01,amdxdnaerrors 0):Row (same prompts as the leaderboard instrument, greedy): 5-token prompt + 1 token = 50.3 s cold / 23.5 s warm → prefill 0.21-0.23 tok/s; 8 tokens decoded in 58.4 s → 0.137 tok/s decode (7.3 s/token). In-tree GGUF Q4_K_M baseline on the same box:
bench/npu-leaderboard/coder30b-hrx-solo-20261030.json= 84.33 tok/s (HRX/GPU, parallel=1). CPU llama.cpp on the same GGUF and box measures 29.2 tok/s decode, 49.4 tok/s prefill, for scale.What remains (named, not papered over)
docs/npu.md, "Routed expert stacks"), not this path.docs/npu.mdalready measured that 32/48 layers route a different top-8 for a 0.5 % hidden-state difference — single-token comparisons are not the acceptance gate there. The gate is aggregate KLD/perplexity against the container's own host reference (tools/moe_q4nx_ref.py), which is the next measurement this row needs.No pin or submodule change.