Skip to content

perf(qwen3-asr,qwen3-tts): fuse decode plans, Metal kernels, and audio/codec paths - #445

Merged
Brooooooklyn merged 3 commits into
mainfrom
perf/qwen3-asr-tts-opt
Nov 29, 2026
Merged

Brooooooklyn merged 3 commits into
mainfrom
perf/qwen3-asr-tts-opt

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Contributor

Summary

Optimizes Qwen3-ASR and Qwen3-TTS end-to-end across three axes with zero silent quantization and full precision parity:

  1. No unnecessary CPU ⇔ GPU data sync — lazy GPU rfft log-mel frontend (zero-copy as_strided), single-FFI C++ decode plans for ASR, Talker, and 15-step CodePredictor, single-copy to_float32_vec, removed redundant streaming sync barriers, PrefixCache single-sync, deferred batched load evals with validated-range page-cache prewarming, and a 66× faster NEON f64 polyphase resampler (resample_mono_cow).
  2. High-performance fusion kernels — six 2D/3D zero-divide Metal kernels (snake_beta, add_bias_layernorm, causal_im2col, causal_transpose_overlap_add, sample_logits_full, swiglu_stacked), zero-copy slice + in-place mlx_kv_store_rows in fused decode/predictor loops, compiled bias_gelu_exact, stacked RVQ decode, and K == stride single-GEMM transpose conv.
  3. No unnecessary dtype upcasts & memory duplication — native BF16/FP16 across bias_gelu_exact, greedy/top-k/top-p sampling, stacked QKV/SwiGLU, and maskless causal prefill; F32 registers only where exactness requires it (LayerNorm, SnakeBeta trig, pre-projected 1.7B tables rounded before bias); dropped ~2.1 GB duplicate ASR and ~1.9 GB duplicate TTS eager weights when fused plans are active; bounded 512-row KV reservation for fused ASR & TTS Talkers; compacted prepared-voice KV caches (20.4 → 4.4 MiB).
flowchart LR
    subgraph ASR["Qwen3-ASR"]
        A1["NEON f64 Resampler<br/>(66x faster)"] --> A2["GPU rfft Log-Mel<br/>(25-28x faster)"]
        A2 --> A3["AudioTower<br/>Stacked QKV + Batched SDPA<br/>bias_gelu_exact + add_bias_layernorm"]
        A3 --> A4["Fused C++ TextDecoder<br/>(BF16/MXFP4, 512-row KV reserve)"]
    end
    subgraph TTS["Qwen3-TTS"]
        T1["Fused C++ Talker<br/>(512-row KV reserve)"] --> T2["1-Dispatch Metal Sampler<br/>(mask + 64-tok rep penalty + radix top_k/top_p)"]
        T2 --> T3["1-FFI C++ 15-Step CodePredictor<br/>(in-place 16-row KvStoreRows,<br/>pre-projected 1.7B tables)"]
        T3 --> T4["Fused Metal CodecDecoder<br/>(2D/3D SnakeBeta, im2col, overlap_add,<br/>stacked RVQ, compact voice KV)"]
    end
Loading

Benchmarks (Apple M5 Max, 128 GB, Full Precision)

Workload Baseline (main) This PR (8546d359e) Delta
CPU Resampler (44.1 → 16 kHz, 2s) 12.68 ms 0.192 ms 66× faster
ASR 1.7B BF16 (30s clip) 917.1 ms (feat 6.49 ms, 121.9 tok/s) 891.1 ms (feat 0.23 ms, 124.3 tok/s, RTF 0.0297) 28× faster frontend
ASR 1.7B MXFP4 (3.35s clip) 53.9 ms (prefill 19.9 ms, feat 0.77 ms) 48.6 ms (prefill 11.5 ms, feat 0.10 ms, RTF 0.0145) 1.73× faster prefill
ASR 1.7B MXFP4 (30s clip) 381.8 ms (prefill 52.6 ms, feat 6.49 ms) 378.3 ms (prefill 46.4 ms, feat 0.26 ms, RTF 0.0126) 79.3× real-time
ASR 1.7B MXFP4 (10s stream) 324.8 ms 252.7 ms -22.2%
TTS 0.6B CustomVoice Stream 2f (256f) 3207.8 ms (79.8 fps, RTF 0.1566, TTFA 110.1 ms) 2729.9 ms (93.8 fps, RTF 0.1333, warm TTFA 23.7 ms) +17.5% fps
TTS 0.6B CustomVoice topP=0.9 (2f) 1207.8 ms (72.0 fps, RTF 0.1735) 982.1 ms (88.6 fps, RTF 0.1411) +23.0% fps
TTS 0.6B CustomVoice Greedy Long (323f) 3518.2 ms (91.8 fps, RTF 0.1362) 3408.5 ms (94.8 fps, RTF 0.1319) +3.2% fps (exact frames)
TTS 1.7B CustomVoice Stream 2f 61.8 fps (RTF 0.2022) 69.5 fps (RTF 0.1800) +12.3% fps
TTS 1.7B CustomVoice topP=0.9 (2f) 57.1 fps (RTF 0.2190) 65.3 fps (RTF 0.1915) +14.4% fps

Metal command trace (MLX_METAL_COMMAND_TRACE=2): 0 Split, 0 Concatenate, 0 Broadcast, 0 AsType in steady decode; ASR MXFP4 dispatches/tok 536 → 286; Codec 8-frame chunk 15.5 → 3.76 ms.

Verification

  • cargo fmt --check & cargo clippy -p mlx-core -p mlx-audio --lib --tests -- -D warnings: pass (0 warnings)
  • vp run build: 2/2 pass (release native addon + metallib smoke checks on MLX 84be893fe)
  • cargo test -p mlx-audio: 20/20 passed
  • cargo test -p mlx-core --lib (ASR, TTS, kernels, KV cache, sampling, as_strided): 187/187 passed
  • vp test (ASR/TTS/CLI/server suite): 203/203 passed
  • Real-checkpoint ASR lifecycle (qwen3-asr-1.7b-mlx-mxfp4): 2/2 passed
  • Real-checkpoint TTS parity (0.6b & 1.7b CustomVoice): 5/5 passed
  • 10 rounds of local Codex adversarial review (gpt-6.2-sol) addressed prior to opening PR.

@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b599d16a-5e21-49fa-8064-12f39c9bd579

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T13:59:18.144394Z 8546d35 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Brooooooklyn
Brooooooklyn enabled auto-merge (squash) November 29, 2026 15:08
@Brooooooklyn
Brooooooklyn merged commit 4e1c56b into main Nov 29, 2026
21 checks passed
@Brooooooklyn
Brooooooklyn deleted the perf/qwen3-asr-tts-opt branch November 29, 2026 15:42
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