You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix MLX min_new_tokens for EOS and stop tokens - #42155
On MLX, min_new_tokens=4 can still stop after one EOS or requested stop token. Fixes#42153.
Modifications
Prevent EOS and requested stop tokens from being selected until the minimum is reached, including in greedy decoding. Add regression tests for decoding and cache reuse.
Accuracy Tests
On Apple M4 with mlx-community/Qwen3-0.6B-4bit, both cases stopped after 1 token on unmodified main. With this fix, forced EOS stopped at token 5 and an explicit stop-token request generated 8 tokens (the configured maximum). The min_new_tokens=0 controls still stop after 1 token. Related MLX tests: 79 passed, 19 subtests passed.
Speed Tests and Profiling
128-token greedy decode, 5 measured requests: 0.559 s median on main, 0.563 s with the fix. Output token IDs matched.
Checklist
Pre-commit passed (Rust-only hooks skipped; no Rust files changed).
Added and ran regression tests.
No documentation change needed for this existing option.
I tested this on an M2 MacBook Air with 8 GB of unified memory, using mlx-community/Qwen3-0.6B-4bit on macOS 27.2.1 (MLX 0.32.2, mlx-lm 0.31.3). I compared base 5423a4d885 with PR commit f7dbde7074, using greedy decoding and max_new_tokens=8.
Request
min_new_tokens
Base
PR
Forced EOS
0
1
1
Forced EOS
4
1
5
Explicit stop token
0
1
1
Explicit stop token
4
1
Metal out of memory
I reproduced both early stops on the base commit. With the PR, the forced-EOS case matched your M4 result: four tokens were generated before EOS appeared as the fifth.
For the explicit-stop case, I used the prompt The capital of France is and stop_token_ids=[12095], the first token from greedy decoding. With min_new_tokens=4, the PR run hit kIOGPUCommandBufferCallbackErrorOutOfMemory in async_chained_decode_mlx on two attempts, including one with a 256-token KV pool and one concurrent request. I couldn't verify the final token count for that case on this machine.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
On MLX,
min_new_tokens=4can still stop after one EOS or requested stop token. Fixes #42153.Modifications
Prevent EOS and requested stop tokens from being selected until the minimum is reached, including in greedy decoding. Add regression tests for decoding and cache reuse.
Accuracy Tests
On Apple M4 with
mlx-community/Qwen3-0.6B-4bit, both cases stopped after 1 token on unmodified main. With this fix, forced EOS stopped at token 5 and an explicit stop-token request generated 8 tokens (the configured maximum). Themin_new_tokens=0controls still stop after 1 token. Related MLX tests: 79 passed, 19 subtests passed.Speed Tests and Profiling
128-token greedy decode, 5 measured requests: 0.559 s median on main, 0.563 s with the fix. Output token IDs matched.
Checklist
CI States
Latest PR Test (Base): ❌ Run #36942503174
Latest PR Test (Extra): ❌ Run #36942502890
Latest PR Test (AMD ROCm 10): ❌ Run #36942503134