Repository navigation
npu: 64x64 tiled transpose for projection assembly (first-token latency) - #622
Merged
Merged
Conversation
…tride
q4nx_assemble_B() lays a projection out as B[i*N + n0+n] while walking n, so
every element it writes is its own cache line, 68 KB apart at N=17408. Measured
on strixhalo with an offline replay of one 5120x17408 projection (the same
scatter_transposed and pack loop as the engine, no device):
K=5120 N=17408 : 610.6 ms -> 27.0 ms (1.6 -> 13 GB/s effective)
K=17408 N=5120 : 1862.2 ms -> 24.0 ms (0.56 -> 14 GB/s)
per layer, all six roles: 4799 ms -> 313 ms
64x64 tiles make every inner run 64 contiguous floats on both sides and the
16 KB source tile stays in L1/L2. The output layout is unchanged, so the pack
that consumes it does not change, and per-column scales stay bit-identical (the
benchmark exits non-zero if they differ; they match on all six geometries).
A driver trace had put 220.9 s of a 436 s request in the gap before each weight
BO was created, which is this call; a first token on Qwen3.8-27B-NPU2 measured
505 s for 8 tokens before and 351 s after with the same text.
bong-water-water-bong
added a commit
that referenced
this pull request
Oct 27, 2026
* tools: rank measured NPU engine runs in a generated leaderboard A row is one measured run, and the generator refuses any record that cannot say how it was measured: instrument, repeat count, timestamp and source are required, and a record with repeats=0 or a missing instrument fails --check instead of being ranked. The unit decides the sort direction (s/token low-to-high, tok/s high-to-low), rows are grouped by host so nobody compares a laptop NPU with a server, and docs/npu-leaderboard.md carries a do-not-edit-by-hand banner. Seeded with the six runs we have on disk: the 27B Q4NX pair on the NPU route, three Flash-Next prefill points, and the Qwen3-4B four-slot arm from the #528 repro (noted as single-slot, since that arm never used four slots). * leaderboard: emit the licence header from the generator The build job runs tools/copyright.py --check, which wants a notice on every tracked file. The generator now writes the same notice into the top of docs/npu-leaderboard.md instead of fighting --fix on every regeneration. * leaderboard: the 27B first-token pair from the #622 trace 435.9 s before the tiled transpose, 145.7 s after, same instrument and same model. Both records carry what the gap analysis showed: which share is device wait and which is host time. --------- Co-authored-by: 1bit <[email protected]> Co-authored-by: agent <agent@local>
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.
q4nx_assemble_B()writes a projection asB[i*N + n0+n]while walkingn— onefloat per cache line, 68 KB apart at N=17408, 0.56–1.6 GB/s effective on a machine
that does ~100. That call, not the quantisation that follows it, is where the first
token of a 64-layer GDN model goes.
Measured offline (a replay of one projection using the engine's own
scatter_transposedand pack loop, no device):~/lb/587-bench/packbenchonstrixhalo, 32 threads.
Per layer, all six roles: 4799 ms → 313 ms.
End to end, Qwen3.8-27B-NPU2 Q4NX on the NPU (
1bit forward-serve, gated on~/npu.lock+ 5×fuser /dev/accel/accel0,taskset -c 0-3,OMP_NUM_THREADS=4,8 greedy tokens, prompt "The capital of France is"):
" Paris.\nThe capital of Germany is"" Paris.\nThe capital of Germany is"Scope: the output layout is deliberately unchanged, so
packB_blockedin theprivate add-on needs no change, and per-column scales are bit-identical (the
benchmark asserts that and exits non-zero otherwise). No change to quantisation,
to the device side, or to any cache path.
Why tiles and not the bigger rewrite: I benchmarked a blocked output layout
(14.6 GB/s, ~20 % better again) and dropped it — it would need a coordinated change
in the private add-on for a fifth of the win.