Repository navigation
Description
Summary
On the Gemma 4 12B Unified audio path, the model sometimes stops transcribing and instead answers the content it (mis)heard, as if the audio were a question to it. On one public FLEURS clip (ko_kr test[3]) this reproduces deterministically in mlxcel (4/4 runs, both greedy and official sampling), while LiteRT-LM (Google's on-device reference runtime) stays in transcription mode on the exact same clip with the same prompt. Both runtimes mishear the hard opening phrase almost identically, so acoustic perception is in the right ballpark; the divergence is in task adherence, which points at how the audio user turn is framed rather than at the feature/injection numerics.
Background
- This is a follow-up to Gemma4 E2B/E4B audio transcription is garbled on 16 kHz PCM16 input while the 12B Unified path transcribes the same clip correctly #782 (E-series garble), which was fixed by fix(gemma4): restore E-series Conformer audio parity with the reference pipeline #796. The reporter confirms this is a separate, pre-existing issue on the 12B Unified path: it reproduces identically on v0.4.0 (brew) and on
main@14b26fe(post-fix(gemma4): restore E-series Conformer audio parity with the reference pipeline #796), and the Unified path is untouched by fix(gemma4): restore E-series Conformer audio parity with the reference pipeline #796. - The Unified path is encoder-free: raw-waveform chunking is projected into the language model via
Gemma4MultimodalEmbedder(src/vision/gemma4_multimodal_embedder.rs), scattered into the audio placeholder insidesrc/vision/gemma4_unified.rs(audio_token_id258881, merged inmerge_multimodal/get_input_embeddings_with_audio). - The reporter notes that the transformers reference pipeline needs explicit handling (
enable_thinking=Falseplusparse_response()) to keep 12B outputs clean, which suggests these checkpoints are sensitive to turn framing. Possibly related plumbing: feat(server): derive the thinking_mode chat-template kwarg when the template supports it #775 (thinking-mode template kwarg).
Proposed Solution
Investigate the audio user-turn conditioning for the Unified 12B checkpoints (chat template around the <|audio|> marker, system context, and thinking handling) rather than the DSP/injection math. The likely lever is the thinking default applied by the CLI/server prompt builder for thinking-capable Gemma 4 templates. Compare mlxcel's rendered prompt for this clip against the transformers reference prompt (which explicitly sets enable_thinking=False) and align the default so the audio transcription turn is framed the way the reference expects.
Implementation Notes
- Audio content only enters the user turn when the processor reports
supports_audio_content(). Seeapply_vlm_chat_templateandresolve_cli_promptinsrc/commands/generate.rs(roughly lines 566 to 660): a{"type": "audio"}content part is emitted so Gemma 4 renders a<|audio|>marker in the user turn; audio placed in the model turn is explicitly avoided. - Thinking default:
build_cli_processorinsrc/commands/generate.rs(roughly lines 675 to 700) setsenable_thinking=trueby default whenevertokenizer.infer_thinking_markers().has_thinking()is true andprocessor.wants_thinking_default_off()is false. The inline comment (issue bug(gemma4): dense gemma-4 text modeling is catastrophically degraded (ppl ~12k vs gemma-3's 15 on the same corpus); likely root of the temp-0 pad-collapse #686) documents that the Gemma 4 thinking-channel template's thinking-OFF branch already renders a well-formed closed priming scaffold that makes the model answer directly, matching transformers' no-enable_thinkingdefault. Verify which branch the 12B Unified audio template actually takes here, and whetherwants_thinking_default_off()returns the correct value for these checkpoints. A thinking-ON default that primes an answer scaffold is a plausible cause of the "answer the content" behavior. - Cross-check the audio-turn scatter path in
src/vision/gemma4_unified.rs(merge_multimodal,get_input_embeddings_with_audio) only to confirm it is not implicated: the report's perception-parity evidence (mlxcel and LiteRT-LM mishear the same phrase almost identically) argues the injection numerics are already close. - Related config/mask surfaces if template changes are needed:
src/vision/gemma4_unified_config.rsandsrc/vision/gemma4_unified_mask.rs. - This environment cannot build or run Metal/MLX, so the code paths above were assessed statically via source reading. The runtime behavior in the report was not reproduced here.
Acceptance Criteria
- On FLEURS
ko_krtest[3]with the Korean verbatim-transcription prompt, mlxcel on the 12B Unified path emits a transcription (not driving-safety advice) under both greedy (-t 0) and official sampling (-t 1.0 --top-p 0.95 --top-k 64). - The other four clips (
test[0],[1],[2],[4]), which already transcribe correctly, keep transcribing with no CER regression. - If the fix is in turn framing / thinking default, the CLI (
mlxcel run --audio) and the server chat path render the same audio user turn, and a regression test pins the rendered prompt for a Gemma 4 12B Unified audio request.
Original Suggestion
Title: Gemma4 12B Unified audio: model deviates from transcription into answering the perceived content (deterministic on FLEURS ko_kr test[3]; LiteRT-LM transcribes the same clip)
Summary
On the Gemma 4 12B Unified audio path, the model intermittently abandons the transcription task and instead answers the content it (mis)heard, as if the audio were a user question. On one public FLEURS clip this is deterministic in mlxcel (4/4 runs, greedy and official sampling alike), while LiteRT-LM (Google's reference on-device runtime) stays in transcription mode on the exact same clip with the exact same prompt — with near-identical acoustic perception. This suggests the Unified path's audio-turn conditioning (chat template / task framing), rather than feature numerics, is where mlxcel diverges from the reference stacks.
Follow-up to #782 (E-series garble, fixed by #796 — thanks for the fast turnaround!). This is a different, pre-existing issue on the 12B path: it reproduces on v0.4.0 (brew) and on main@14b26fe (post-#796) identically, and the Unified path (raw-waveform chunking → Gemma4MultimodalEmbedder, src/vision/gemma4_unified.rs) is untouched by #796.
Environment
- mlxcel
main@14b26fe(post-fix(gemma4): restore E-series Conformer audio parity with the reference pipeline #796), built withcargo build --release --features metal,accelerate; also observed on v0.4.0 (brew) - macOS (Apple Silicon, 64 GB), Metal backend
- Model:
mlx-community/gemma-4-12B-it-4bit(snapshot8de8ab4) - Control runtime: LiteRT-LM CLI (
pip install litert-lm) withlitert-community/gemma-4-12B-it-litert-lm(gemma-4-12B-it.litertlm)
Reproduce (public data only, no auth)
Fetch FLEURS ko_kr test[3] and convert to PCM16 (the WAV reader rejects IEEE-float WAV):
# pip install datasets (streaming; Audio(decode=False) avoids the torchcodec dependency)
import itertools
from datasets import load_dataset, Audio
ds = load_dataset("google/fleurs", "ko_kr", split="test", streaming=True)
ds = ds.cast_column("audio", Audio(decode=False))
ex = next(itertools.islice(iter(ds), 3, 4))
open("fleurs3_raw.wav", "wb").write(ex["audio"]["bytes"])
print(ex["transcription"])ffmpeg -y -i fleurs3_raw.wav -ar 16000 -ac 1 -c:a pcm_s16le fleurs3.wavDependency-free alternative via datasets-server API (currently returning 503 as of filing; works when the service is up)
for attempt in 1 2 3 4 5; do
curl -sf "https://datasets-server.huggingface.co/rows?dataset=google%2Ffleurs&config=ko_kr&split=test&offset=3&length=1" -o row3.json && break
sleep 5
done
python3 -c "import json; print(json.load(open('row3.json'))['rows'][0]['row']['audio'][0]['src'])" | xargs -I{} curl -sL "{}" -o fleurs3_raw.wav
ffmpeg -y -i fleurs3_raw.wav -ar 16000 -ac 1 -c:a pcm_s16le fleurs3.wavRun:
mlxcel run mlx-community/gemma-4-12B-it-4bit \
-p "이 음성을 들리는 그대로 한국어로 받아쓰기 하세요. 번역하지 말고 한국어 원문만 출력하세요." \
--audio fleurs3.wav -t 0 -n 2048(The prompt says: "Transcribe this audio verbatim in Korean. Do not translate; output only the original Korean text.")
Expected
A transcription. FLEURS reference for test[3] (12.5 s):
겨울에 북발트해를 건널 경우에는 빙판을 통과하면서 꽤 끔찍한 소음이 발생하기 때문에 객실의 위치를 확인하는 것이 좋다
Observed (mlxcel): the model answers the content instead
Greedy (-t 0), 247 tokens of driving-safety advice:
네, 맞습니다. 서울의 북파크웨이(North Parkway)는 특히 빙판길에서 매우 위험할 수 있는 구간입니다.
빙판길은 미끄러움과 예측 불가능한 노면 상태 때문에 사고 위험이 높으며 (…) 안전 운전하시고, 빙판길에 주의하세요!
Not a greedy artifact — official Gemma sampling (-t 1.0 --top-p 0.95 --top-k 64) deviates on 3/3 independent runs as well (different wording, same failure: safety advice about icy roads, ending with e.g. "안전하게 이동하시고, 추운 날씨에 건강 유의하시기 바랍니다!").
The other four clips (test[0], [1], [2], [4]) transcribe fine in the same setup — CER 3.0–13.5 % vs the FLEURS references (whitespace/punctuation-normalized), i.e. the Unified audio path clearly works on unambiguous speech.
Control: LiteRT-LM stays on task on the same clip
Same WAV, same Korean prompt, litert-lm run … --backend gpu --audio-backend gpu:
서울의 북팔퇴를 건널 경우에는 빙판을 통과하면서 꽤 끔찍한 소음이 발생하기 때문에 객실의 위치를 확인하는 것이 좋다.
Two things worth noting:
- Perception parity: both runtimes mishear the (acoustically hard) opening phrase almost identically — mlxcel perceives "서울의 북파크웨이", LiteRT-LM writes "서울의 북팔퇴" (reference: "겨울에 북발트해"). So the Unified path's audio injection seems numerically in the right ballpark; this does not look like a Gemma4 E2B/E4B audio transcription is garbled on 16 kHz PCM16 input while the 12B Unified path transcribes the same clip correctly #782-style feature-extraction bug.
- Behavior divergence: after the same uncertain perception, LiteRT-LM still emits a transcription, while mlxcel flips into assistant-answer mode. LiteRT-LM transcribed 5/5 of these clips (avg CER 5.0 %); mlxcel 4/5 with this clip deviating deterministically.
Hypothesis
Since perception matches but task adherence differs, the gap is probably in how the audio user turn is framed/conditioned for the Unified checkpoints (chat template around <|audio|>, system context, thinking handling) rather than in the DSP/injection math. The transformers reference pipeline also needs explicit handling (enable_thinking=False + parse_response()) to keep 12B outputs clean, which hints these checkpoints are sensitive to turn framing. Possibly related plumbing: #775 (thinking-mode template kwarg).
Happy to run diagnostics or test branches on Apple Silicon — same offer as in #782.
Activity
[-]Gemma4 12B Unified audio: model deviates from transcription into answering the perceived content (deterministic on FLEURS ko_kr test[3]; LiteRT-LM transcribes the same clip)[/-][+]Gemma4 12B Unified audio path answers the perceived content instead of transcribing (deterministic on FLEURS ko_kr test[3]; LiteRT-LM transcribes the same clip)[/+]hoonjae-newmean commentedon Jul 16, 2026
Verified the fix on Apple Silicon (M-series, 64 GB, Metal) at b20ea30, built with
cargo build --release --features metal,accelerate. All acceptance criteria pass:ko_krtest[3]now transcribes instead of answering, under both greedy (-t 0) and official sampling (-t 1.0 --top-p 0.95 --top-k 64, 3/3 independent runs). CER 10.0-12.0% against the FLEURS reference, with the same acoustically-hard opening misheard the way LiteRT-LM mishears it, exactly as expected.test[0],[1],[2],[4]) keep transcribing with no CER regression: 2.4-5.8%, slightly better than pre-fix (the "델 포트로" proper noun now comes out right).One note for other users: the v0.4.1 tag (2026-07-16 08:54 UTC) predates this merge by about an hour, so the fix is not in that release. Building from main (or waiting for the next release) is needed.
Thanks for the fast turnaround, twice in a row now. Filing issues on a project this responsive is a pleasure, and I appreciate the clear root-cause writeups in both fix PRs. I will keep testing the audio paths on Apple Silicon as they evolve.
fix(cli): render Gemma 4 audio user turn after the prompt text (lablu…
fix(cli): render Gemma 4 audio user turn after the prompt text (lablu…
fix(vision): align InternVL, MiniCPM-V 4.6 and Gemma 3 image prompts (#…