Skip to content

qwen3-asr: the Metal binding (#2105, stacked on #2239) - #2254

Draft
jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:qwen3-asr-metal
Draft

jschmied wants to merge 2 commits into
ashhart:mainfrom
jschmied:qwen3-asr-metal

Conversation

@jschmied

@jschmied jschmied commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Qwen3-ASR's Metal binding, for #2105. Head ee48ea298: rebased onto main e6094de13 on the user's request. #2239 has merged (7fb9fc661), so its commits are dropped; this PR is two commits (ab4e79403, ee48ea298). #2239 moved; still draft until the #2105 / #2118 decisions move.

This head (ee48ea298, on main e6094de13)

The rebase conflicted only in metal_targets.zig. Main's lines are kept, and ours were added next to them. Four edits follow main:

Rerun on this head:

  • GB10: test-qwen3-asr-host green, zig fmt --check and git diff --check clean, tools/pr_check.py 0 errors, lean 0 new. The Metal binding and driver also compile for aarch64-macos here (build-obj, no SDK, no link), with 0 errors.
  • No x86 run: every changed file is Metal-only (metal_targets.zig is reached only on macOS), so a Linux build compiles none of it. The Mac's zig build test below is the full set.
  • Mac (M3 Pro): tf-qwen3-asr-metal md5 1e91d14393c6c182cb70a2fcedeb971e.
    • Qwen3-ASR-0.6B on the three clips below: prompt ids equal to the case's, greedy byte-identical (26/26, 17/17, 40/40), worst stage cosine 0.998783 / 0.999165 / 0.999101. These equal the old rows to five places.
    • This head's times: prompt pass 82.6 / 54.6 / 90.9 ms, decode 87.0 / 90.2 / 79.0 tok/s.
    • test-qwen3-asr-host 28/28, compile-qwen3-asr-metal-host 43/43.
    • zig build test 965/970 steps. The failures are exactly main e6094de13's set on the same Mac (deepseek_v41 vision_config ×2, persistence_identity, tensorfold-native's memcpy nm step). Two more in the first run were memory pressure from another job; both pass idle.
    • Lean 165 = main's 165, 0 in the touched files.

What it adds

  • families/qwen3_asr/metal/ beside cuda/: the binding the shared tower and LM schedules call, plus qwen3_asr.metal, the tf-qwen3-asr-metal tool and compile-qwen3-asr-metal-host.
  • Core kernels wherever the rounding matches:
    • shared_attention for the tower's windows, the LM's causal prompt and decode through the ordinary path;
    • Qwen-VL's gemm_nax for the LM's bias-free prompt GEMMs;
    • qwv_bias_gelu (exact) for every GELU.
  • Family-local, because no core kernel has the same rounding:
    • the biased GEMM (the core GEMM rounds before the bias);
    • the one-row GEMV;
    • bf16 LayerNorm;
    • q/k norm + RoPE from the bf16 cos/sin tables (tf_lane_rope computes its own);
    • add + RMS, SwiGLU;
    • the conv taps and flatten, embed, the q|k|v split.

Gate (Qwen3-ASR-0.6B, M3 Pro)

The reference is qwen-asr 0.0.6's windowed backend, as on #2239.

Carried from the original run (the rows above are this head's):

clip (LibriSpeech dev-clean) tokens transcript worst stage cosine prompt pass decode
1272-128104-0000 26 byte-identical 0.99878 68 ms 83 tok/s
1272-128104-0001 17 byte-identical 0.99917 55 ms 88 tok/s
1272-128104-0002 40 byte-identical 0.99910 91 ms 78 tok/s
  • On the Mac (macOS, at a0b56fd67): test-qwen3-asr-host green; zig build test 694/694 steps (8880 passed, 68 skipped, 0 failed); lean 0 in the touched files.
  • On the GB10 at 77ea0c53e: lean 0 new, zig build test, the no-GPU CI set, git diff --check and zig fmt --check pass.

Notes

  • Seeded sampling, resume and concurrency don't apply here: tf-qwen3-asr-metal is an offline one-stream greedy tool, and no served path changes.
  • Proposed CHANGELOG line, for ashhart to place: qwen3-asr: the Metal binding (tower and Qwen3 LM, greedy on one queue) and tf-qwen3-asr-metal (#2254).
  • No refusal test: this rebase adds no refusal. Without Xcode, tf-qwen3-asr-metal stops with main's existing no-compiler failure.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @jschmied. The Metal binding follows #2239. Using the core kernels wherever the rounding matches is the right call. Before it leaves draft:

  1. Restack on qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239's final head, and rerun the two short-clip cases on Metal, since the short-chunk fix lives in the shared schedule.
  2. Register qwen3_asr.metal's kernels with the kernel contract and post Metal's SUMMARY line.
  3. FP64 checks with planted controls for the family-local kernels, as the XPU binding has.
  4. The full clip set on Metal under the tie rule from qwen3-asr: host slice, the shared tower and Qwen3 schedules over a backend binding (#2105) #2239, in place of the three dev clips.

  • Synthena (Ash's Agent)

…ashhart#2105)

families/qwen3_asr/metal/ binds the shared schedules beside cuda/: one device with buffers addressed as
slot << 40 | offset, the weights put as stored, and qwen3_asr.metal's kernels at the CUDA binding's bf16 points.
Tower: conv taps (3x3 stride 2, channels last) into a GEMM with bias, torch's [c, f] flatten, LayerNorm, the
exact GELU, and bidirectional attention a window at a time. LM: the embedding gather, add + RMS norm, q/k RMS
norm with RoPE into the caches, causal GQA attention over them, SwiGLU, and the tied head; one-row GEMMs take
a GEMV. tf-qwen3-asr-metal runs a clip against a case as tf-qwen3-asr does; compile-qwen3-asr-metal-host
builds it without running shaders.

On an M3 Pro, Qwen/Qwen3-ASR-0.6B, the greedy transcripts of LibriSpeech dev-clean 1272-128104-0000, -0001
and -0002 are byte-identical to qwen-asr 0.0.6's windowed reference (worst stage cosine 0.9986, at lm_layer27).
…nels (ashhart#2105)

The binding now takes what core already has where its rounding points match the reference: shared_attention
for the tower's windows (q, k and v split to its token-major rows, every key visible) and the LM's causal GQA
(a byte mask a pass row, `ordinary` for decode), the Qwen-VL tower's tfp::gemm_nax for the LM's bias-free
prompt GEMMs, and qwv_bias_gelu (exact, zero bias) for every GELU. qwen3_asr.metal keeps what has no core twin
at these points: the biased GEMM and its one-row GEMV, conv taps, flatten, LayerNorm on bf16 rows, add + RMS
norm, q/k norm with RoPE from transformers' bf16 tables, SwiGLU, the embedding gather and the q|k|v split.

On the M3 Pro the three LibriSpeech dev-clean transcripts stay byte-identical (worst stage cosine 0.9988);
the prompt pass takes 55-92 ms where it took 107-196 ms.
@jschmied

Copy link
Copy Markdown
Contributor Author

@ashhart restacked on main e6094de13 (#2239 merged), head ee48ea298, two commits. It followed main in four places: .rotary_dim dropped (#3065), the tower's dumping() and gathered conv_out, and main's no-Xcode build pattern. The body lists them.

Rerun on this head: on the M3 Pro, 3 of 3 transcripts are byte-identical and the cosines equal the old rows; zig build test fails the same tests main fails on that Mac. There's no x86 run, because no file this PR changes compiles on Linux.

Your item 1 is covered by that rerun. Items 2-4 are still open: the kernel-contract records with Metal's SUMMARY, the FP64 checks with planted controls, and the full clip set under the tie rule. It stays a draft until they're in.

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.

2 participants