Repository navigation
Description
Summary
When a Gemma 4 checkpoint emits its reasoning channel, the mlxcel run / mlxcel generate CLI path prints the raw channel markers and the entire chain-of-thought to the terminal as visible output. Observed on gemma-4-e4b-it-qat-4bit (also reproduces on plain gemma-4-e4b-it-4bit). The server chat-completions path already routes this reasoning into reasoning_content, so the gap is specifically the CLI output path, plus a minor leftover on the server side.
Reproduction
CLI (leaks raw markers + reasoning):
./target/release/mlxcel run <path>/gemma-4-e4b-it-qat-4bit -t 0 -n 60 \
-p "Explain briefly why the sky is blue."
Actual output (verbatim):
<|channel>thought
Here's a thinking process to arrive at the suggested answer:
1. **Analyze the Request:** The user wants a brief explanation of why the sky is blue.
2. **Identify the Core Scientific Concept:** The phenomenon is called Rayleigh scattering.
3. ...
The literal <|channel>thought marker and the full step-by-step reasoning are printed as if they were the answer. On prompts where the model answers directly (e.g. "What is 2+2? Answer briefly." returns 4) there is no leak, so the trigger is: the model chooses to open a thought channel.
Server, same model and prompt, for contrast (/v1/chat/completions, non-stream): the reasoning is routed to reasoning_content and content holds the final answer. But reasoning_content retains a leading thought\n (the channel argument), e.g. reasoning_content = "thought\nHere's a thinking process ...".
Expected
- CLI: the reasoning channel should be hidden from the visible answer by default (raw
<|channel>thought/<channel|>markers must never print), matching how the server hides it fromcontent. A toggle (consistent with the existingpreserve_thinking/enable_thinkingkwargs, e.g. a--show-reasoningflag) may optionally surface the reasoning, ideally dimmed. - Server:
reasoning_contentshould not retain thethoughtchannel-argument prefix.
Root cause
mlxcel already recognizes the Gemma 4 channel markers. The tokenizer sets up ThinkingMarkers { think_start: "<|channel>thought", think_end: "<channel|>" } when both <|channel> and <channel|> are present as token IDs (src/tokenizer/mod.rs:250; the e4b-qat tokenizer defines them as added-token IDs 100 and 101 in tokenizer.json). The server reasoning splitters use this to separate reasoning from content.
The CLI generation path does not use these markers on the output side:
src/commands/chat.rsstreaming callback (around lines 602-608) callsdecode_state.on_token(...)thenprint!("{text}")for every generated piece, with no thinking-channel filtering. So the raw<|channel>thoughtblock streams straight to the terminal.- The CLI's only thinking-awareness is
src/commands/generate.rs:707(infer_thinking_markers().has_thinking()), which governs the prompt-sideenable_thinkingdefault only, not output rendering. - Note the final transcript decode uses
tokenizer.decode(&ids, true)(skip special tokens) so the marker is not re-fed into history, but that path does not run on the live-streamed visible output and does not strip thethoughtargument or the CoT body.
Additionally, the prompt-side thinking-OFF default from issue #686 (the closed <|channel>thought\n<channel|> priming scaffold, src/commands/generate.rs:700-711, src/server/chat_template.rs:2043-2058) does not prevent the model from opening a thought channel on many prompts, so relying on the prompt default is insufficient. The output path must handle the channel whenever it appears.
The server-side thought\n leftover comes from think_start = "<|channel>thought" where the <|channel> token is consumed but the thought argument text is not trimmed from the captured reasoning.
Proposed fix
- Apply the tokenizer's
ThinkingMarkers(think_start/think_end) in the CLI streaming output path (src/commands/chat.rsstream callback and themlxcel generateone-shot output), so the reasoning channel is suppressed from visible terminal output by default and the raw<|channel>thought/<channel|>markers never print. - Buffer across the streaming boundary: the markers can split across token pieces, so hold output until the channel open/close state is resolved (a small stream-state filter, mirroring the server splitters).
- Trim the
think_startargument (thought) so neither the CLI reasoning display nor the serverreasoning_contentkeeps a leftover prefix. - Add an opt-in CLI flag to surface reasoning (dimmed), consistent with
preserve_thinking/enable_thinking. - Tests (CLI + server): thought-then-answer, answer-only (no channel), thought cut off with no
<channel|>close, and streamed token-by-token, all asserting the raw markers never appear in visible output and reasoning is captured without thethoughtprefix.
Acceptance criteria
mlxcel run/mlxcel generateon a Gemma 4 checkpoint that opens a thought channel prints only the final answer by default; no<|channel>/<channel|>/thoughttext appears in the visible output.- The optional reasoning-display flag surfaces the reasoning without raw markers.
- Server
reasoning_contentno longer carries the leadingthoughtprefix. - The listed tests pass; the direct-answer case (no channel) is byte-identical to today.
Environment / notes
- Reproduced on Linux GB10 (CUDA, sm_121), HEAD of
main, release CUDA build. - Models:
gemma-4-e4b-it-qat-4bit,gemma-4-e4b-it-4bit. - Related: 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 (Gemma 4 thinking-OFF prompt scaffold), bug(gemma4/cuda): decode collapses to <pad> after 1-3 tokens (single-query maskless attention + quantized GEMV); mlx_lm decodes coherently #688 (Gemma 4 CUDA-graph decode). This issue is output-rendering only and independent of the separate Gemma 4 26B A4B multi-turn corruption investigation.
Activity
inureyes commentedon Jul 23, 2026
Clarification: the originally reported "useless tokens" symptom on gemma-4-e4b-it-qat is actually a collapse into reserved <unused...> vocabulary tokens caused by a chunked-prefill sliding-window mask drop on the server. That is now tracked separately in #885 (#885).
This issue (#884) remains valid as a separate, lower-severity problem: the <|channel>thought reasoning-channel text leaking into CLI output. The two have different root causes.
fix: suppress prompt-primed reasoning channel in CLI output
test(reasoning-stream): cover re-opened channels and flush idempotence
fix: hide Gemma 4 reasoning channel from CLI output (#889)
fix: hide Gemma 4 reasoning channel from CLI output (lablup#889)