Repository navigation
fix(models): close eos range, Z1T sequence and K2-Horizon reasoning gaps - #3303
Merged
Merged
Conversation
Limite and Xing4.0 narrowed `eos_token_id` with `as i32`, so an id past `i32::MAX` wrapped to a different token and a negative id was accepted. Both configs now read it through a shared `loading::checked_eos_token_ids`, which refuses such ids with an error naming the value. Z1T's single-sequence path panicked on a sequence id that was never prepared. It now creates the state lazily with `with_or_create_sequence_state`, as its sibling families do; the batched path keeps its validation. K2-Horizon primes `<ifm|think>`, `<ifm|think_fast>` or `<ifm|think_faster>` by `reasoning_effort`, and no marker table knew these pairs, so the reasoning and its close tag stayed in `content`. The three pairs are now registered in the tokenizer marker probe, the thinking-budget resolver, the stream filter delimiters and pair lookup, the parser's marker pairs and the unclosed-primed close list. A shared `THINK_EFFORT_VARIANTS` table lets primed-open detection return the close that matches the primed open, and the budget tracker accepts every variant's close. Closes #3299
inureyes
force-pushed
the
fix/issue-3299-eos-z1t-k2-horizon
branch
from
November 23, 2026 03:20
72c5ca4 to
9a0b87f
Compare
inureyes
marked this pull request as ready for review
November 23, 2026 03:26
This was referenced Nov 23, 2026
inureyes
added a commit
that referenced
this pull request
Nov 23, 2026
…riant (#3330) ## Summary Two follow-ups from #3303 and #3304, in one PR as the issue asks. ### 1. K2-Horizon budget close matches the opened variant K2-Horizon's template primes `<ifm|think>`, `<ifm|think_fast>` or `<ifm|think_faster>` by `reasoning_effort` (high, medium, low). An exhausted `thinking_budget_tokens` cap or a `reasoning_end` control request always forced `</ifm|think>`, so a `medium` or `low` block was closed with a tag the model never saw paired with its open. - `ThinkingTokenIds` gains `alt_opens`, index-paired with `alt_closes` and filled from the same `THINK_EFFORT_VARIANTS` entries, plus `close_for_open`. - `ThinkingState` keeps a private `active_close`. `observe` sets it when the model emits the pair's open or a variant open (a variant open now enters `InBlock` too), and `with_primed_close` sets it for a primed prompt, accepted only when `ids.is_close(close)`. Both forcing paths force `active_close.unwrap_or(ids.close)`, so the `--reasoning-budget-message` run is unchanged and still precedes the close. - `ServerGenerateOptions::thinking_primed_close` carries the `primed_open_thinking_close_marker` value the routes already compute. It is set wherever `thinking_enter_block_on_start` is set from the primed prompt: `prepare_chat_generation` (`/v1/chat/completions` and the `mlxcel chat` / `mlxcel run` CLI through `InProcessServer::chat`), the router front, `/v1/responses` (run and non-streaming), responses compaction, Anthropic `/v1/messages` (streaming and not) and the ASR chat path. - `build_thinking_state` resolves the marker to an id through the new `thinking_budget::resolve_primed_close_id` (the tokenizer's `token_to_id`, only when the prompt primed the block; a multi-token close resolves to nothing and falls back to the pair's close). - A variant open whose close is missing from the vocabulary opens nothing, so a mismatched close is never forced. - Out of scope, as the issue says: the disaggregated handoff (`build_handoff_thinking_state` and the `kv_cache_serde` wire format). The router front sets the field, but the prefill frame does not carry it, so a primed variant on that path still gets `</ifm|think>`; a comment at the assignment, `docs/supported-models.md` and the CHANGELOG say so. ### 2. Stale Qwen3.5 ragged-rollback test `rollback_speculative_cache_panics_on_ragged_batched_accepts` expected a panic that #2442 removed. It is replaced by `rollback_speculative_cache_compacts_ragged_batched_accepts`: rows `[1, 2, 3, 4]` and `[5, 6, 7, 0]` verified with accepts `[3, 1]`; each row's linear-layer `conv_state` and `state_cache` must match a B = 1 rollback of that row with its own accept, and the attention offset must be `max(accepted) + 1` = 4. The shared `verify_and_rollback` helper now checks the returned count against `max(accepted)`, which is what `rollback_speculative_cache` returns for both uniform and ragged accepts. ## Tests - `server::k2_horizon_reasoning_tests::a_primed_budget_forces_the_close_of_the_primed_variant`: for `high`, `medium`, `low`, a primed state with a budget of 2 built through `with_primed_close` forces that effort's own close, and so does a `reasoning_end` flag. - `a_model_emitted_variant_open_is_closed_with_its_own_close`: a non-primed state that observes each open enters `InBlock` and forces the matching close at the cap. - `an_unrelated_primed_close_falls_back_to_the_pair_close`. - `the_primed_close_marker_resolves_to_its_token_id`: each effort's close resolves, an unprimed prompt and a multi-token close resolve to nothing. - `variant_close_edge_cases`: a `--reasoning-budget-message` run precedes the variant close, a zero budget forces the variant close at once, and a model's own matching or mismatched close is let through. - `chat_completions_pass_the_primed_variant_close_to_the_scheduler`: the real chat route, streaming and not, hands the scheduler the primed variant's close for each effort. - Existing `server::thinking_budget` tests (Qwen, Gemma 4, `<|content_thinking|>` pairs) pass unchanged. ## Verification Narrow equivalents of the issue's Verification block (the broad gate is left to the orchestrator): - `cargo fmt --all -- --check`, `cargo clippy --lib --tests --features metal,accelerate -- -D warnings`: clean. - `server::thinking_budget server::k2_horizon_reasoning_tests server::routes::chat`: 131 passed. - `models::qwen3_5_tests --ignored --test-threads=1` (GPU lock): 7 of 7 passed. - `coverage_tests`: 18 passed; the seven CI contract scripts pass. - Real checkpoint, `mlxcel-server --skip-chat-parsing` on `models/k2-horizon-0.9b`, greedy, `thinking_budget_tokens: 6`: `high` ends the reasoning with `</ifm|think>` after six tokens, `medium` with `</ifm|think_fast>` after six tokens, and `low` closes on its own with `</ifm|think_faster>` at the first token. With parsing on, the budgeted tokens land in `reasoning_content` for every effort. Technical report: `TECHNICAL_REPORTS/3330-k2-horizon-variant-close-20261123.en.md` and `.ko.md`. Closes #3321
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
Three small gaps from recent model ports, fixed together as #3299 asks.
1.
eos_token_idrange checks (Limite, Xing4.0)Both configs narrowed
eos_token_idwithas i32, so4294967298wrapped to2and-1was accepted although it can never match. A sharedloading::checked_eos_token_idsnow converts withi32::try_from, refuses negative and out-of-range integers with an error naming the value, and skips non-integer entries asparse_eos_token_idsalready did.ModelArgs::validate()calls it, andeos_token_ids()reads through it.parse_eosreturns the error from deserialization, which is whereXing40Config::validate()already runs, andvalidate()itself also refuses a negative id in a config built in code.eos_token_idsstaysVec<i32>; onlyparse_eosandvalidatechanged inxing4_0.rs.2. Z1T lazy sequence state
Z1t::forward_rows_for_sequencenow useswith_or_create_sequence_state(seq_id, || self.fresh_states(), ..), matching the sibling families, instead of panicking on an unprepared id. The batched path's validation is unchanged. The batched-decode harness test for Z1T moves from the strict prepared-B=1 variant to the lazy one, since B=1 with an unprepared id is now accepted.3. K2-Horizon reasoning split
The template primes
<ifm|think>,<ifm|think_fast>or<ifm|think_faster>byreasoning_effort. The pairs are registered in:SINGLE_TOKEN_PAIRS(tokenizer/mod.rs), which resolves<ifm|think>/</ifm|think>as the marker pair.tokenizer::THINK_EFFORT_VARIANTStable andThinkingMarkers::primeable_pairs(), soprompt_primed_open_thinkingdetects all three primed opens andprompt_primed_open_close_markerreturns the matching close. For every other familyprimeable_pairs()is the one resolved pair, so detection is unchanged.resolve_thinking_token_ids(thinking_budget.rs):ThinkingTokenIdsgainsalt_closesandis_close(), so a budget-tracked block primed with<ifm|think_fast>closes on</ifm|think_fast>instead of counting the answer as reasoning. Other families construct it withThinkingTokenIds::new(open, close)and have no alternates.CHAT_DELIMITERSandcanonical_thinking_pair(stream_filter.rs),THINKING_MARKER_PAIRS(parser.rs), andOPEN_THINKING_CLOSE_MARKERS(routes/chat.rs), the last so a closed K2-Horizon block is not treated as unclosed and itscontentemptied.The primed-open handling is the same one Kimi K3 uses: the stream filter starts in the thinking state, and the parser's primed-open pass keys on the close marker. The limitation note is removed from
docs/supported-models.md.Known limit: when a
thinking_budget_tokenscap runs out undermediumorloweffort, the forced close is</ifm|think>(the resolved pair's close), not the variant's. Every filter treats it as a close, so the split stays correct.Tests
models::limite_tests::validate_refuses_eos_ids_outside_the_i32_range,models::xing4_0::tests::config_refuses_eos_ids_outside_the_i32_range:4294967298,[-1]and[n, 2147483648]are refused with the value in the error;[0, 2147483647]parses.models::z1t::tests::z1t_unprepared_sequence_id_starts_from_fresh_state:forward_with_sequence_idwith a fresh id returns logits equal to the no-id forward of the same prompt (exact), and the following decode step matches too.server::k2_horizon_reasoning_tests: marker resolution and variants, primed detection per effort, the non-streaming and per-char streaming split ofabc\n</ifm|think*>\nanswerfor all three efforts, budget close on every variant, and the real/v1/chat/completionshandler (scripted model) streaming and non-streaming for each effort.Narrow selectors run (the issue's workspace-wide commands exceed the per-command watchdog; the broad gate is left to CI):
models::limite,models::xing4_0,models::z1t,coverage_tests(Metal, under the GPU lock),server::k2_horizon_reasoning_tests,server::tool_calls,server::thinking_budget,thinking,tokenizer::,reasoning_display,server::routes::chat,server::reasoning_echo,server::kimi_k3,server::chat_request,primed,server::batch::speculative_burst_tests,loading::.cargo clippy --lib --tests --features metal,accelerate -- -D warningsand every contract script pass.Real checkpoint:
mlxcel-server -m models/k2-horizon-0.9b,/v1/chat/completionswithreasoning_efforthigh, medium and low, streaming and non-streaming. High and medium return the trace inreasoning_contentand42incontent; low closes the block at once and returns an emptyreasoning_contentwith only the answer incontent. No response containsifm|thinktext.mlxcel generatesmoke onlimite-1b-violettoandz1t-0-mlxloads and generates;xing4.0-29b-a4b-mlx-8bitwas not run (config parsing only, covered by unit tests). The bilingual technical report is inTECHNICAL_REPORTS/3303-eos-z1t-k2-horizon-reasoning-20261123.*.md.Closes #3299