Skip to content

Commit 57028f3

Browse files
vcruz305ashhart
authored andcommitted
fix: Qwen3.8-27B on EXL3 checkpoints stops at the end of the chat turn
The 27B's CUDA Config took its stop ids from config.json only, as Flash Next's did. turboderp's 27B EXL3 packs (3.00 and 4.00 bpw) have no top-level eos_token_id and text_config names <|endoftext|> (248044) only, so Config.read returned (248044,) and <|im_end|> (248046), which these packs list in generation_config.json alone, did not end a reply. The MLX 4-bit checkpoint lists both at the top level and reads (248046, 248044), as before. Config.read now adds generation_config.json's eos_token_id after config.json's, in order and without duplicates, and a checkpoint that names no stop id anywhere fails with a clear error. GLM-5.3-Flash is not affected: its EXL3 checkpoint lists its three stop ids in text_config, which its loader reads first.
1 parent e5d3a2a commit 57028f3

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

‎src/tensorfold/families/qwen3_5/cuda/weights.py‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,15 @@ def read(cls, model_dir: str | Path) -> "Config":
124124
t = raw.get("text_config", raw)
125125
rope = t.get("rope_parameters") or {}
126126
head_dim = int(t.get("head_dim") or t["hidden_size"] // t["num_attention_heads"])
127-
eos = raw.get("eos_token_id", t.get("eos_token_id"))
128-
eos = tuple(eos) if isinstance(eos, list) else (int(eos),)
127+
gen = Path(model_dir) / "generation_config.json"
128+
found: list[int] = []
129+
# EXL3 packs name the chat turn's end, <|im_end|>, in generation_config.json only
130+
for value in (raw.get("eos_token_id", t.get("eos_token_id")),
131+
json.loads(gen.read_text()).get("eos_token_id") if gen.exists() else None):
132+
found += [] if value is None else [int(e) for e in value] if isinstance(value, list) else [int(value)]
133+
if not found:
134+
raise ValueError("no eos_token_id in config.json or generation_config.json")
135+
eos = tuple(dict.fromkeys(found))
129136
return cls(
130137
hidden=int(t["hidden_size"]), intermediate=int(t.get("intermediate_size", 0)),
131138
layers=int(t["num_hidden_layers"]), heads=int(t["num_attention_heads"]),

‎tests/test_qwen27b_eos.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Qwen3.8-27B on CUDA stops where the checkpoint says a reply ends, reading generation_config.json too (CPU only)."""
2+
3+
import json
4+
5+
import pytest
6+
7+
pytest.importorskip("torch")
8+
9+
from tensorfold.families.qwen3_5.cuda.weights import Config # noqa: E402
10+
11+
IM_END, ENDOFTEXT = 248046, 248044
12+
TEXT = {
13+
"hidden_size": 64, "intermediate_size": 128, "num_hidden_layers": 4, "num_attention_heads": 4,
14+
"num_key_value_heads": 2, "head_dim": 16, "vocab_size": 248320, "linear_num_key_heads": 2,
15+
"linear_num_value_heads": 4, "linear_key_head_dim": 16, "linear_value_head_dim": 16, "linear_conv_kernel_dim": 4,
16+
}
17+
18+
19+
def checkpoint(tmp_path, config, generation=None):
20+
(tmp_path / "config.json").write_text(json.dumps(config))
21+
if generation is not None:
22+
(tmp_path / "generation_config.json").write_text(json.dumps(generation))
23+
return tmp_path
24+
25+
26+
def test_exl3_pack_stops_at_im_end_from_generation_config(tmp_path):
27+
# turboderp's 27B EXL3 packs: no top-level eos_token_id, text_config names <|endoftext|> only
28+
d = checkpoint(tmp_path, {"model_type": "qwen3_5", "text_config": {**TEXT, "eos_token_id": ENDOFTEXT}},
29+
{"eos_token_id": [IM_END, ENDOFTEXT]})
30+
assert Config.read(d).eos == (ENDOFTEXT, IM_END)
31+
32+
33+
def test_top_level_ids_keep_their_order(tmp_path):
34+
# the MLX checkpoint's layout: the top level already lists both
35+
d = checkpoint(tmp_path, {"model_type": "qwen3_5", "eos_token_id": [IM_END, ENDOFTEXT],
36+
"text_config": {**TEXT, "eos_token_id": ENDOFTEXT}},
37+
{"eos_token_id": [IM_END, ENDOFTEXT]})
38+
assert Config.read(d).eos == (IM_END, ENDOFTEXT)
39+
40+
41+
def test_without_generation_config_the_config_ids_are_used(tmp_path):
42+
d = checkpoint(tmp_path, {"model_type": "qwen3_5", "text_config": {**TEXT, "eos_token_id": ENDOFTEXT}})
43+
assert Config.read(d).eos == (ENDOFTEXT,)
44+
45+
46+
def test_ids_only_in_generation_config(tmp_path):
47+
d = checkpoint(tmp_path, {"model_type": "qwen3_5", "text_config": TEXT}, {"eos_token_id": IM_END})
48+
assert Config.read(d).eos == (IM_END,)
49+
50+
51+
def test_no_ids_anywhere_is_an_error(tmp_path):
52+
d = checkpoint(tmp_path, {"model_type": "qwen3_5", "text_config": TEXT}, {"temperature": 1.0})
53+
with pytest.raises(ValueError, match="eos_token_id"):
54+
Config.read(d)

0 commit comments

Comments
 (0)