Skip to content

qwen3-asr xpu: asr_gemv, the decode GEMV, bit-equal to asr_gemm at one row (stacked on #2255) - #4693

Draft
jschmied wants to merge 5 commits into
ashhart:mainfrom
jschmied:qwen3-asr-xpu-gemv
Draft

jschmied wants to merge 5 commits into
ashhart:mainfrom
jschmied:qwen3-asr-xpu-gemv

Conversation

@jschmied

Copy link
Copy Markdown
Contributor

Qwen3-ASR's decode GEMV on XPU (Gen12LP, Iris Xe): the follow-up to #2255 that ashhart named there ("The decode GEMV can be its own PR later"), for #2105.

Stacked on #2255. This branch is #2255's head e7e03b485 plus one commit, 108ea70b2. Only that last commit is this PR; review it alone with git diff e7e03b485 108ea70b2. I'll rebase onto main once #2255 lands.

What it changes

  • asr_gemv, in a new image zig/kernels/xpu/qwen3_asr_mv.cl. It computes one-row Linears in bf16, with fp32 sums.
    • A 16-lane sub-group computes one output. Lane l takes the 16-k steps l, l + 16, and so on. Each step is an fma chain from 0, exactly as in asr_gemm's tile, and the step sums are then added in order.
    • So every output equals asr_gemm's at m = 1, bit for bit. Same tokens by construction, and the shared schedule's check that decode logits equal the prompt pass's still holds.
  • The binding: Lm.gemm sends one-row calls (decode, the tied head) to asr_gemv. Prompt passes keep asr_gemm.
  • Its own image, not qwen3_asr.cl: the first try put the kernel in qwen3_asr.cl. That changed how the driver built asr_conv (SIMD 16 instead of 8, 1,024 spill bytes), and the prompt pass got slower in all 3 paired rounds (+4%, +15%, +20%). In its own image, qwen3_asr.cl is byte for byte qwen3-asr: the XPU binding on Gen12LP (#2105, stacked on #2239) #2255's.

Shared code, checked first: nothing on XPU covers bf16 weights. The XPU matvecs (qmv4*, lfm3_mv, nem_rows) all read MLX 4-bit weights, and lane_gemv is CUDA-only. Core's contract already has "replaces kernel X, bit for bit" (spec.replaces), and the test uses it rather than a check of its own.

Evidence (Iris Xe 0x9a49, Qwen3-ASR-0.6B)

Kernel contract (tf-xpu-qwen3_asr_contract-test, on 108ea70b2):

SUMMARY tgllp 0x9a49 14 kernels: 14 pass gates 1-4, 0 fail, 0 known findings; 12 controls: 12 red as planted, 0 missed; 0 limit problems; gates 33606 ms, limits 0 ms
  • asr_gemv declares replaces = asr_gemm at one row. Gate 3 found it bit-equal to asr_gemm on 18 shapes: the binding's decode widths for 0.6B and 1.7B, the 151,936-wide head, k = 1,000 with a short last step, and the tile edges. Gate 1 checks it against float64; gate 4 found its sums exact at k 6,144, where fp16 would miss by infx and bf16 by 74,642x.
  • Planted control: gemv_steps_reversed adds each 16 step sums last first, applied by cl_edit in zig/build/xpu_qwen3_asr_contract.zig. It goes red at gate 3: its bytes differ from asr_gemm at one row from byte 1,660 at 1x1024x2048.
  • Gate 5: the record (64 work-items, sub-group 16) matches the driver: 0 SLM, 0 spill, 0 private bytes.

Exactness on the full clip set, the 40 clips of #2239's gate2 under the tie rule (tf-qwen3-asr-xpu-forced, on 356dac96c; the only later change is in the contract test). Every clip's FORCED, SWAP, FAIL and DIST lines are identical to #2255's run: 80 of 80 files (40 plain, 40 planted), 0 differ.

Speed (tf-qwen3-asr-xpu, 1272-128104-0004, 29.4 s, 91 tokens). A = #2255's head e7e03b485, B = 356dac96c; one warm-up each, then 3 rounds of A B B A. The transcript is the same in all 12 runs.

A median B median per round (B vs A)
decode 3.5 tok/s 10.55 tok/s 2.99x, 3.01x, 3.14x
prompt pass (397 rows) 1821 ms 1837 ms -5%, 0%, +3%
tower (382 rows) 833 ms 822 ms -4%, 0%, 0%
  • Decode is faster in all 3 rounds. The prompt pass and tower are equal within run-to-run noise, since they run the same qwen3_asr.cl build as A.

Host checks on this head

On 108ea70b2, x86 lane (8 cores, no GPU), all green:

  • zig build -Dfixed-cpu test-host test-qwen3-asr-host: 2395/2395 steps, 24194/24356 tests (162 skipped).
  • zig build -Dfixed-cpu test test-golden test-kernel-contract test-server-security test-pull-security fuzz-cortheon check-release-paths: 867/867 steps, 771/784 tests (13 skipped).
  • check-native-cuda-host compile-cuda-tests 17/17. The XPU build for tgllp 108/108, and the BMG contract runner 15/15. Both have ocloc stubbed; the kernels ran on the card above.
  • tools/pr_check.py 0 errors, lean 165 vs 165 on the base (0 new), zig fmt --check and git diff --check clean. It merges cleanly with main fe6d47a18.

Notes

  • Exact and not opt-in: the decode's tokens and logits are bit for bit the prompt kernel's, so there is no flag and no off path.
  • Seeded sampling, resume and concurrency don't apply: tf-qwen3-asr-xpu is an offline one-stream greedy tool, and no served path changes.
  • No new refusal.
  • Against main: Qwen3-ASR on XPU is not on main yet (qwen3-asr: the XPU binding on Gen12LP (#2105, stacked on #2239) #2255). Against qwen3-asr: the XPU binding on Gen12LP (#2105, stacked on #2239) #2255 the prompt path is unchanged (same qwen3_asr.cl image, same build), and the decode is bit for bit the same, as shown above.
  • Proposed CHANGELOG line, for ashhart to place: qwen3-asr: asr_gemv, the XPU decode GEMV, bit-equal to asr_gemm at one row (~3x decode on Iris Xe).

… KV head, against FP64 (ashhart#2105)

qwen3_asr.cl holds what no shared Gen12LP kernel covers: a bf16 Linear (64 x 64 tiles as vit_gemm,
bf16 rows, bias, GELU and residual epilogue), the 3 x 3 stride-2 conv on channels-last rows, the
flatten to torch's order, LayerNorm with bias, erf GELU, the tower's windowed attention and Qwen3's
per-head RMSNorm with RoPE rounded at each product and sum (lfm3's rounds once). The language
model's RMSNorm, SwiGLU and split-K GQA attention are lfm3.cl's, built again as lfm3_gq2 with GQ 2.
tf-xpu-qwen3_asr_ops-test checks each against FP64 with a planted control, the shared kernels as
the binding launches them.
xpu/ binds the shared tower and Qwen3 schedules to qwen3_asr.cl and the shared kernels on Level
Zero, as cuda/ does on CUDA: the store places bf16 tensors as stored, the embedding copies rows by
id, and lfm3's attention merge takes a +inf gate (bf16(sigmoid) = 1). tf-qwen3-asr-xpu runs a clip
against a qwen3_asr_case.py case, each stage's cosine and the greedy ids. On Iris Xe the three
LibriSpeech dev clips (1272-128104-0000, -0001, -0004) are byte-identical to the windowed
reference (26, 17 and 91 tokens; worst stage cosine 0.99765).
…e Intel GPU; the forced tools share forced.zig (ashhart#2105)

tf-qwen3-asr-xpu-forced runs a clip teacher-forced on a case's greedy ids and judges every step by the tie rule, as
tf-qwen3-asr-forced does on CUDA: a differing top token passes only as a swap with both margins at most 0.25. With
logits_fp32 and logits_bf16 in the case it prints both distances to fp32. --plant splice and --plant norms (q_norm and
k_norm swapped in every layer, Model.swapQkNorms) are the faults it must catch. forced.zig now holds the distance and
the step tally both tools print, byte for byte the change ashhart#2254 makes for its Metal tool.
…a planted control each, gate 5 live (ashhart#2105)

tf-xpu-qwen3_asr_contract-test (in xpu-tests) runs gates 1 to 4 on the card for every kernel the binding launches from
qwen3_asr.cl (the Linear plain, with bias and residual and with bias and GELU; the conv, flatten, LayerNorm, GELU, the
tower's attention, Qwen3's q/k norm and RoPE with its cache writes) and from lfm3.cl at GQ 2 (RMSNorm, the split-K
attention pair, SwiGLU), each against float64. Each has a planted control: the same source with one edit (cl_edit
fails the build when the edited line is gone), red at the shapes gate, and one at the sums gate (the Linear's steps
added in bf16). Gate 5 reads the card's properties against a Gen12LP row (xpu_limits.gen12lp) and every loaded
kernel against its record (qwen3_asr_xpu_records.zig); the declared control at 1,024 work-items is red. The guarded
buffers move to contract_guarded.zig, generic over the device, so both XPU contract runners share them.
…s bits at one row (ashhart#2105)

A 16-lane sub-group an output: lane l takes the 16-k steps l, l + 16, ..., each step's fma chain from 0 as
asr_gemm's tile, then the steps' sums are added in order, so every output equals asr_gemm's at m = 1 bit for bit.
It lives in its own image, qwen3_asr_mv.cl: added to qwen3_asr.cl it changed the driver's build of asr_conv
(SIMD 16 and 1,024 spill bytes on Gen12LP), so qwen3_asr.cl stays byte for byte ashhart#2255's.
The kernel contract runs it with replaces = asr_gemm at one row (gate 3 bit-equal on every shape), float64 at
gates 1 and 4, and a planted control that adds each 16 steps last first; its Gen12LP record joins gate 5.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant