Repository navigation
feat(xla): add Gemma3n audio execution - #922
Conversation
74a7d39 to
876bcc3
Compare
|
Rebased onto Rebase integration:
Post-rebase validation:
The unchanged MLX-to-IREE audio threshold blocker remains, and CUDA is unavailable on the current host. No new numeric pass is claimed. This PR remains draft/blocked and #878 remains blocked by #932. |
876bcc3 to
2b6d949
Compare
|
Foundation refresh complete at head 2b6d949:
The draft remains fail-closed and status:blocked. This refresh does not change the recorded first unresolved boundary: sscp_conv_1_convolution still requires a representable cuDNN/IREE engine or reduction-plan contract. |
2b6d949 to
0a5aa90
Compare
|
Rebased onto current Validation:
The PR intentionally remains draft/fail-closed. The existing production-oracle blocker is unchanged: the first SSCP convolution still has 6 BF16-ULP mismatches ( |
Current-head CUDA actual at
|
MLX_ENABLE_TF32 |
first divergent stage |
|---|---|
1 (MLX default) |
sscp_conv_0_norm_cumulative_sum max_abs 1.562500000e-2 rms 2.432233746e-3 index 373 |
0 (declared policy) |
sscp_conv_0_norm_cumulative_sum max_abs 1.562500000e-2 rms 2.432233746e-3 index 373 |
So the improvement relative to the recorded blocker is attributable to this head rather than
to the reference policy, and the remaining divergence is a property of the emitted graph.
Recording the A/B because the negative result is what makes the attribution safe.
Remaining, unchanged: cumulative normalization and shared prefix scan, local attention,
relative shift, pooling, projection lengths, projected audio embeddings and dense PLE, then
logits/KV/greedy ASR token exactness and the CLI/server, isolation, cancellation and slot
reuse gates.
0a5aa90 to
f1fe444
Compare
f1fe444 to
a953d21
Compare
Add OpenXLA/IREE execution for Gemma3n audio (`Gemma3nAudioFeatureExtractor` mel features through SSCP, conformer blocks, audio projection, hard audio vocabulary replacement, and `dense_ple` language prefill) across CPU, CUDA, and ROCm/HIP targets: - Emit split StableHLO modules (`sscp`, `conformer`, `merge_ple`) for Gemma3n audio and wire them into `Gemma3nAudioRuntime` and `xla_worker` batch admission with fail-closed placeholder span validation and immediate slot cleanup on cancellation. - Fix `dense_ple_input_head` in `src/lib/mlxcel-xla/src/emitter/gemma3n_math.rs` so audio placeholder tokens (`token_id >= vocab_size_per_layer_input`, e.g., `262273 >= 262144`) map to row 0 of `embed_tokens_per_layer` via `per_layer_embedding_lookup` (scaled by `embed_tokens_per_layer_scale`) instead of zeroing the gathered row after lookup, matching MLX's `Gemma3nModel::get_per_layer_inputs` and Hugging Face `Gemma3nTextModel`. - Add ROCm (`xla_iree_rocm`) target compilation and device selection to `Gemma3nAudioRuntime`, and update `molmo`, `molmo2`, `qwen3_vl`, `youtu_vl`, and `numeric_probe` auxiliary weight constructors for `AuxiliaryWeightStorage`. - Implement `LanguageModel::prepare_sequence_state` on `Gemma3nVLModel` and preserve pre-rendered chat-template audio/image placeholders in `prepare_gemma3n_audio_embeddings` when `ORDERED_MEDIA_PREFIX` is absent so `mlxcel generate --audio` works on both Eager MLX and OpenXLA. - Verify 100% token-exact greedy output on `mlx-community/gemma-3n-E4B-it-4bit` across Eager MLX (CPU and ROCm GPU), `xla_gemma3n_audio_check`, and `MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=hip mlxcel generate`. Closes #878
a953d21 to
9b6e9c2
Compare
## Summary - OpenXLA: the Phi4MM speech/vision LoRA A/B tensors are now `WeightSpec::Whole`, not `Proj`. Since #2861 the loader transposes `Proj` specs for the single-sequence `InOut` layout, while the emitter declares the LoRA pairs in the checkpoint layout (`[rank, in]`, `[out, rank]`) and contracts them untransposed, so prefill failed with `expected 320x3072, actual 3072x320`. `Whole` is never transposed and stays f32-resident (the declared element type) in every layout, so the ragged `OutIn` path uploads exactly what it did before. I chose this over flipping the declarations because the LoRA branch is shared by single and ragged graphs. Flipping the declarations would have meant changing the LoRA branch per layout, and the f16-resident `Proj` rule would also have needed an exemption. - A new `WeightSpec::uploads_transposed` now drives the loader's `Proj` branch. The new test `phi4mm_lora_declared_shapes_match_uploaded_shapes_in_every_layout` compares the declared LoRA shapes in the prefill, embeddings-prefill, decode and ragged graphs against what the loader uploads, in both layouts. With the old `Proj` push it fails: `prefill (InOut) declares ...qkv.lora_A.speech as [3, 8] but the loader uploads [8, 3]`. - Eager CLI: `materialize_phi4mm_ordered_prompt` now passes a prompt without ordered-media markers through to `prepare_phi4mm_prompt_tokens`, as the Gemma3n path does since #922. That function inserts the audio tag at the start of the user turn, which is the same normalization the OpenXLA CLI applies, and it still rejects a placeholder count that disagrees with the request. ## Test plan Checkpoint: microsoft/Phi-4-multimodal-instruct@93f923e1. Input: the official `what_is_shown_in_this_image.wav` with "Transcribe the audio exactly." and `-n 8 --temp 0`. - [x] Eager (`MLXCEL_SDPA_DETERMINISTIC=1`), XLA cuda and XLA local-task all produce `13347 382 10147 306 495 3621` ("what is shown in this image") - [x] `xla_phi4_audio_check` passes on local-task and cuda - [x] Phi4MM vision (vision LoRA) runs on XLA cuda. It matches eager for the first 8 tokens, and XLA f16 and f32 give identical output - [x] qwen2.5-0.5b-instruct-bf16 on XLA cuda gives the same tokens as eager - [x] `cargo test -p mlxcel-xla --lib -- phi4` and `cargo test --features cuda --lib -- phi4mm_` pass - [x] `cargo check --features cuda,xla-iree --all-targets`, `cargo check --no-default-features --features xla-diagnostics --all-targets`, `insert_apache_header.py --check` and `cargo fmt --check` pass Closes #3362
Summary
sscp,conformer,merge_ple), projection, prepared-prefill,dense_ple, CLI, and continuous-batch server path across CPU, CUDA, and ROCm/HIP targets.dense_ple_input_headinsrc/lib/mlxcel-xla/src/emitter/gemma3n_math.rsso audio placeholder tokens (token_id >= vocab_size_per_layer_input, e.g.,262273 >= 262144) map to row 0 ofembed_tokens_per_layerviaper_layer_embedding_lookup(scaled byembed_tokens_per_layer_scale) instead of zeroing the gathered row after lookup, matching MLXGemma3nModel::get_per_layer_inputsand Hugging FaceGemma3nTextModel.LanguageModel::prepare_sequence_stateonGemma3nVLModel(src/vision/gemma3n_vl.rs) and preserve pre-rendered chat-template audio/image placeholders inprepare_gemma3n_audio_embeddings(src/server/model_worker.rs) whenORDERED_MEDIA_PREFIXis absent somlxcel generate --audioworks on both Eager MLX and OpenXLA.Root Cause of Previous
dense_pleDivergenceIn
xla_gemma3n_audio_reference_check, the previousdense_plediscrepancy (max_abs = 5.90625, rms = 0.826056) was caused bydense_ple_input_headinsrc/lib/mlxcel-xla/src/emitter/gemma3n_math.rszeroingper_layer_tokenrows whenevertoken_id >= vocab_size_per_layer_input(262273 >= 262144). Both Hugging FaceGemma3nTextModel.get_per_layer_inputsand MLXGemma3nModel::get_per_layer_inputsinstead clamp out-of-range token IDs (token_id < 0 || token_id >= vocab_size_per_layer_input) to index0and gather row0ofembed_tokens_per_layerscaled byembed_tokens_per_layer_scale. Removing the redundant post-gather zeroing indense_ple_input_headdrops thedense_plediff on ROCm (gfx1151) tomax_abs = 0.1328125, rms = 8.972e-3and yields 100% token-exact greedy generation against Eager MLX.Validation
mlx-community/gemma-3n-E4B-it-4bit+103-1240-0000.wav, 16 greedy tokens):ROCm):[24233, 236743, 236770, 236761, 12216, 236761, 35783, 28452, 563, 6486, 143843, 236761, 108, 39828, 236761, 35783]("Chapter 1. Mrs. Rachel Lind is Surprised.\n\nMrs. Rachel")MLXCEL_DEVICE=cpu): identical 16 tokensxla_gemma3n_audio_check(hip): identical 16 tokens (OK: Gemma3n XLA audio generated exact expected transcript)MLXCEL_BACKEND=xla MLXCEL_XLA_DEVICE=hip mlxcel generate): identical 16 tokenscargo test -p mlxcel-xla gemma3n -- --test-threads=1— 60 passedGEMMA3N_MODEL_DIR=... cargo test -p mlxcel-xla gemma3n -- --ignored --test-threads=1— passedcargo test --lib --features xla-diagnostics-rocm gemma3n -- --include-ignored --test-threads=1— 52 passedcargo test --test xla_gemma3n_prefill --features xla-diagnostics-rocm -- --include-ignored --test-threads=1— passedcargo fmt --all -- --check— passedcargo clippy --workspace --all-targets -- -D warnings— passedcargo clippy --all-targets --features xla-diagnostics-rocm -- -D warnings— passedCloses #878
Parent epic: #566