Fix server XTC crash from heterogeneous xtc_special_tokens#1258
Draft
odysa wants to merge 1 commit intoml-explore:mainfrom
Draft
Fix server XTC crash from heterogeneous xtc_special_tokens#1258odysa wants to merge 1 commit intoml-explore:mainfrom
odysa wants to merge 1 commit intoml-explore:mainfrom
Conversation
`_make_sampler` constructed `xtc_special_tokens` as `[int, list[int]]`
(scalar `eos_token_id` + nested `tokenizer.encode("\n")`). MLX fancy-
indexing in `apply_xtc` (`mask[..., xtc_special_tokens] = False`) cannot
handle the nested list and raises `ValueError: Initialization
encountered extra dimension` on the first sampling step, crashing every
chat-completion request with `xtc_probability > 0`.
Match the flat-list construction already used in generate.py:2070 and
chat.py:156, and pass `add_special_tokens=False` so BOS isn't included.
Also covers multi-EOS tokenizers via `tokenizer.eos_token_ids`.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
mlx_lm.server._make_samplerbuildsxtc_special_tokensas a heterogeneous list —[int, list[int]]— which MLX fancy-indexing inapply_xtccannot handle. Every chat-completion request withxtc_probability > 0crashes the generation worker withValueError: Initialization encountered extra dimension. The client just sees a dropped connection.This fix flattens the list to match the construction already used in
generate.py:2070andchat.py:156, and switches toeos_token_idsfor multi-EOS tokenizers.For Gemma the produced list goes from
[1, [2, 107]](broken) to[107, 1, 106](works).Reproduction (before this PR)
End-to-end via the server:
Test plan
apply_xtccrash onmain.list[int]for Gemma 3 / Gemma 4 tokenizers.xtc_probability > 0.