Repository navigation
Description
Problem / Background
During text-only generation, gemma-4-12b-it-4bit (model_type gemma4_unified) occasionally emits a multimodal placeholder token in the middle of otherwise-coherent text.
Reproduction with mlxcel generate (chat template applied):
mlxcel generate -m models/gemma-4-12b-it-4bit -p "What is a hash table? Answer in one sentence." -n 60 -t 0
produced output containing a stray audio placeholder token:
...compute an<audio|>ex index, allowing for efficient data retrieval...
The leak is occasional and context-dependent. The "hash table" prompt leaks the audio placeholder, while "list three primary colors" and "write one sentence about the moon" generate cleanly.
Via /v1/chat/completions, the server strips special tokens from the response content, so a leak-heavy generation (the hash-table prompt) returns an EMPTY content with finish_reason=length despite ~60 generated tokens (per usage.completion_tokens).
Root Cause
gemma4_unified is a multimodal model (audio + image + video). The placeholder token ids in models/gemma-4-12b-it-4bit/config.json are input-alignment placeholders that must never appear in generated text output. The leaked one is audio_token_id (258881):
| config field | token id |
|---|---|
audio_token_id |
258881 |
image_token_id |
258880 |
boa_token_id |
256000 |
boi_token_id |
255999 |
eoa_token_index |
258883 |
eoi_token_id |
258882 |
video_token_id |
258884 |
mlxcel does not suppress these in the output logits during generation, so at a near-tie greedy step a placeholder can become the argmax and leak into the text stream.
Proposed Solution
src/lib/mlxcel-core/src/sampling.rs already supports permanently suppressing a token by inserting f32::NEG_INFINITY into the per-step bias map (doc comment near line 93: "Use f32::NEG_INFINITY to permanently suppress a token"; an existing insert at line 1625 backed by a test asserting the suppressed-token probability is 0.0; language-bias suppression counters near lines 47-100).
Currently no gemma4_unified placeholder token is registered for OUTPUT suppression (model implementation in src/models/gemma4.rs, detected via src/models/detection.rs:125). The only model that references an image token at all today is qwen3_vl (src/models/qwen3_vl.rs), and that reference is for input embedding alignment, not output masking.
Fix: register the gemma4_unified multimodal placeholder token ids so they are masked to -inf at every decode step. Prefer deriving the suppressed set generically from the model config *_token_id / *_token_index fields rather than hardcoding only gemma4.
Scope note (companion audit)
A broader audit of whether other multimodal/VLM families (gemma3, qwen2.5-vl, and similar) suppress their own placeholder tokens in the OUTPUT logits is a recommended companion. The fix should be generic where practical (derive the suppressed set from the model config *_token_id fields) rather than family-specific.
Acceptance Criteria
-
gemma4_unifiednever emits audio/image/video/boi/eoi/boa/eoa placeholder tokens as generated text. - The hash-table prompt yields coherent, non-empty output via BOTH
mlxcel generateand/v1/chat/completions. - No regression on already-coherent prompts (for example "list three primary colors", "write one sentence about the moon").
- A regression test pins that the placeholder token ids are suppressed (
NEG_INFINITY) in the generation logits forgemma4_unified.
Provenance
Pre-existing behavior, not introduced by the #325-#333 performance chain. Surfaced during #333 (PR #348) adaptive MTP validation using the gemma-4-12b-it-4bit plus assistant pairing.
Activity
fix(inference): suppress placeholders on MTP verify and chat paths
chore: add #350 latent-gap note to DFlash argmax; fix fmt
fix(models): suppress gemma4_unified multimodal placeholder tokens (#351
feat(generate): wire MTP speculative decode into offline generate (#385)
fix(gemma4): restore E-series Conformer audio parity with the referen…
fix(models): suppress gemma4_unified multimodal placeholder tokens (l…
feat(generate): wire MTP speculative decode into offline generate (la…
fix(gemma4): restore E-series Conformer audio parity with the referen…