Skip to content

fix(models): gemma4_unified leaks multimodal placeholder tokens (audio/image/video) into text generation #350

Closed

Description

@inureyes

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_unified never 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 generate and /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 for gemma4_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

  1. added
    type:bug
    area:models
    area:inference
    priority:medium
    status:in-progress
    status:review
    and removed
    status:in-progress
    on Jun 18, 2026
  2. added 2 commits that reference this issue on Jun 18, 2026
  3. added
    status:done
    and removed
    status:review
    on Jun 18, 2026
  4. added this to the 0.3 milestone on Jun 21, 2026
  5. self-assigned this
    on Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:inferencearea:modelspriority:mediumstatus:donetype:bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions