Skip to content

qwen: one EOS rule for the family readers; qwen27 reads generation_config.json - #4678

Merged
ashhart merged 2 commits into
ashhart:mainfrom
devopsfortunato:eos-one-rule-3701
Nov 23, 2026
Merged

ashhart merged 2 commits into
ashhart:mainfrom
devopsfortunato:eos-one-rule-3701

Conversation

@devopsfortunato

Copy link
Copy Markdown
Contributor

Refs #3701. Draft until the Metal comparison below has run: host tests cannot show this one landing, as the issue's gate says.

What

The Qwen 3.5 readers now resolve EOS ids one way, and qwen27's runtime reads generation_config.json.

  • core/tokenizer/eos.zig: one precedence for every policy: the root's ids, text_config's only when the root gave none, then generation_config.json's. That is what served already did, so resolve, merge and their callers (server hf_text, dots_mocr, dory, kolibri1) behave byte-for-byte as before. The Order enum and its two other arms are gone.
  • qwen35_hip and qwen27_metal become one qwen35 policy (nested arrays, at most 8 ids, at least one). Those are validation limits, not precedence, so served keeps its own. The server-only tokenizer eos_token step stays where it is.
  • qwen27/model.zig (Model.load) reads <dir>/generation_config.json (missing is none; any other read error propagates, as in the HIP loader) and passes it to parseWhy. This is the only runtime EOS path (dflash/generation.zig reads model.config.eos); the other cfg.parse(..., null) callers are width previews, the memory budget and test fixtures, none reads the ids.

What changes

  • qwen27 on an HF-layout config gains 248046 (<|im_end|>): [248044] becomes [248044, 248046], the set the served reader already has. Without it a qwen27 DFlash run() with no stop override does not stop at <|im_end|>.
  • Only on inputs no official checkpoint ships: HIP with root and tower declaring different ids returns the root's rather than both; qwen27 with a root null or [] and a tower id takes the tower's instead of MissingEos.

Tests

  • eos_policy_test.zig: one fixture table for served and qwen35, plus mutation tests for root null, root [] and root-versus-tower disagreement, each with a planted wrong reader (ignores generation_config, falls through on a present root, reads the tower in place of the root, unions every source) that the rule must differ from.
  • qwen27/config_test.zig: an HF-layout config gives {248044, 248046} with the file passed, {248044} without (main's behaviour), and the same ids as eos.resolve.

Linux host, Zig 0.17.0, on the head of this branch:

zig build test-eos-policy-host test-checkpoint-eos     11/11 steps, 49/49 tests
zig test (HIP loader) qwen3_5/config_checks.zig        6/6
zig test (qwen27)    qwen27/config_test.zig            22/22
zig fmt --check on the touched files                   clean
python3 tools/zig/lean_check.py                        7670 files, 165 problems, as on main

test-qwen-dense-geometry-host only exists on macOS hosts, so I ran its config_test.zig part directly with the same module graph; model.zig is Metal-only, so only the new read's shape was compiled on its own here.

Not run

Overlap

atc overlap reports other open pulls touching qwen27/model.zig and qwen27/config_test.zig (#3239, #1434, #2375). My hunks there are one read block and one test with its fixture; whichever lands second rebases onto the other.

@ashhart

ashhart commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Served A/Bs of this PR's head against main (4fbeb0a6f4), Qwen3.8-27B MLX 4-bit, prompt prefill at 2K and 8K plus the greedy and seeded chat/code sweep at one and four streams, no stop override:

platform verdict tokens tok/s vs main
M3 Ultra (Metal) GREEN equal in every cell +0.0% to +0.4%
M5 Ultra (Metal) GREEN equal in every cell -0.6% to +0.9%
GB10 (CUDA) GREEN equal in every cell -0.4% to +0.1%

So on this checkpoint the one-rule change keeps every finish reason and token the same, and costs nothing. Thanks @devopsfortunato. The 24-config before/after snapshot from @jschmied's table is the remaining check before it comes out of draft.

  • Synthena

@ashhart
ashhart marked this pull request as ready for review November 23, 2026 10:24
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Both checks this draft was waiting on are in: the served A/Bs above (tokens equal on M3, M5 and GB10, no slower cell) and @jschmied's 24-config snapshot on #3701, where only qwen27's runtime EOS set changes, on the ten configs that declare it. I've marked this ready and put it in the landing queue, with you as the author. Thanks @devopsfortunato.

  • Synthena

@devopsfortunato

Copy link
Copy Markdown
Contributor Author

Thank you both — the A/B sweeps and the 24-config snapshot are exactly the gate the issue asked for, and both are green:

  • Device A/B (Qwen3.8-27B MLX, no stop override): tokens equal in every cell on M3 Ultra, M5 Ultra and GB10, tok/s within noise of main.
  • 24-config snapshot: only qwen27's runtime set changes, gaining 248046 on the 10 configs that ship a [248046, 248044] generation_config.json; served and HIP identical on all 24; nothing else moves.

With the host suite (49/49 EOS tests, HIP loader 6/6, qwen27 config 22/22) already green on this head, I've marked the PR ready for review. @jschmied, the driver + dumps would be a useful receipt to keep with the issue if you can attach them, but nothing further is needed from my side.

@ashhart
ashhart merged commit ce02643 into ashhart:main Nov 23, 2026
16 of 37 checks passed
@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thank you @devopsfortunato. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants