Repository navigation
NPU forward: fix cross-request KV leak, faster pack, batched MoE gate/up; GGUF to fused lane - #222
Merged
Merged
Conversation
`1bit serve -m <gguf> --device npu` only ever repacked with repack_gguf.py (the per-op forward's layout) and ran ~100+ synchronous dispatches per token. ONEBIT_NPU_LANE_DIR now packs the GGUF with tools/gguf_to_q4nx.py (the lane's q4_1 tile layout) into its own cache dir and serves it on the fast lane, one launch per layer. The two layouts are not interchangeable (evidence/gguf-npu-six/ task3-fusion-feasibility.md), so the lane pack never aliases the forward pack. Anything the lane cannot serve -- an arch the lane-layout packer does not model, a missing tokenizer, a missing kernel set -- falls through to the unchanged per-op forward, so the route cannot regress a model the lane does not cover. Captured Qwen3-0.6B: GGUF -> fused lane, anchor " Paris", 97-103 tok/s (evidence/gguf-npu-six/fused-lane-gguf-2026-09-28.md); Qwen2.5-7B -> the per-op forward (the lane/dx designs are Qwen3-shaped: 8 KV heads, per-head q/k RMSNorm, no projection bias). (cherry picked from commit 5fb4f4b47a597dcef69761d24e981e8ee4ad26d8)
The dx fused per-layer route reads this layout, and Qwen2.5-7B is the arch the goal is proven on. The tensor-name map already covered qwen2's blk.N.attn_q/ attn_k/attn_v (the same names qwen3 uses), and 1-D tensors are already written as bf16, so the bias tensors land in the Q4NX as model.layers.N.self_attn.*_proj.bias with no new code. Only config() rejected the arch, and qwen2 additionally needs `attention_bias` / `qk_norm` declared so a consumer does not have to sniff the tensor table (dx's decoder checks them against its kernel build flags). Verified: Qwen2.5-7B-Instruct Q4_K_M -> 5,509,628,488 B model.q4nx, 339 tensors, config with attention_bias=true / qk_norm=false; and the run through the dx route answers " Paris" (evidence/gguf-npu-six/dx-qwen2/). (cherry picked from commit a6a134717bfcd7ae5caf0d3210d7b2a000309f66)
… batch MoE expert gate/up (cherry picked from commit 54c31e82a1024bf36e1244f11155a814f490236e)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Docs7 for 1bit-monster/engine
Commit |
|
Preparing review... |
bong-water-water-bong
marked this pull request as draft
September 29, 2026 11:24
Collaborator
Author
|
Draft until verified. My first NPU check of this build gave wrong first tokens on MiniCPM5-1B (Japan/France/Germany/France -> ' a', ' the', ' the', ' the'), not the Tokyo/Paris/Berlin/Paris in the agent's notes. That run shared |
Collaborator
Author
Collaborator
Author
|
Verified. #224 was a converter lookup problem, not code (fixed in #225). With the canonical converter (a7f29fe3f):
Leaving the agent's later opt-in expert LRU commit (1be569bef) out: it measured as not paying, and it's off by default. |
bong-water-water-bong
marked this pull request as ready for review
September 29, 2026 13:03
|
Preparing review... |
This was referenced Nov 6, 2026
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.
Three NPU commits from an agent's local branch
npu-glm-kb-fixon strixhalo, rebased onto main (a fourth was already in #209). The agent's A/B notes and duplicate diffs (evidence/holo4-1bit-capture/) are left out; their numbers are below.Per-op forward (
npu/forward)step_batchnow resets atstart_pos == 0. After the fix: Tokyo / Paris / Berlin / Paris.onebit_npu_forward; it is now (C and CXX). Pack time went 10.9 → 3.2 → 1.2 ms per call.NPU_NO_EXPERT_BATCH=1restores the per-expert path.npu_gemmcalls per 6-token request drop from 6,650 to 3,300. Holo4-35B-A3B, 8 tokens: 221-225 s → 161-162 s. Anchors unchanged on Holo4, Qwen3-Coder-30B-A3B and Qwen3.6-35B-A3B.GGUF → fused lane. With
ONEBIT_NPU_LANE_DIR,serve --device npupacks a Qwen3 GGUF in the lane's own Q4NX layout and runs it on the fast lane. Anything else falls through to the per-op forward.gguf_to_q4nx.pyalso packs Qwen2.These are the agent's measurements. I rebuilt the rebased branch on strixhalo (NPU host build, OpenMP found). I'll re-run the KV-leak anchor sequence myself once the NPU is free, before merging. Host code only: no kernels or designs.
🤖 Generated with Claude Code