Commit 714cd4c
fix(tokenizer): respect GGUF tokenizer.ggml.add_bos_token (R8)
Generalises R7 from Qwen3.6 family-only heuristic to a model-agnostic
GGUF metadata read.
Adds tq_tokenizer_t.add_bos_token tristate field:
1 = explicit true
-1 = explicit false (suppress BOS prepend even if vocab lookup
would have enabled it)
0 = unset (fall through to existing heuristics)
tq_load_tokenizer_from_gguf parses tokenizer.ggml.add_bos_token (bool)
and sets the field accordingly.
tq_generate.c BOS-decision block consults the tristate before any
heuristic, so models that explicitly declare add_bos_token=false
(both Qwen3.6-27B Q4_K_M and 35B-A3B-UD-IQ4_XS do, per direct GGUF
metadata read) are honoured regardless of vocab content.
Verification (clean rebuild, Metal=ON):
- 35B-A3B IQ4_XS quantum: 149 tok natural EOS (matches baseline,
Tier 2 — restored from 94 rep loop seen with R1 BOS auto-enable)
- add_bos=-1 logged at load time confirms the metadata path fires
Note: an earlier incremental rebuild after the struct change produced
an ABI mismatch (102 rep loop instead of 149 EOS). Always do a clean
rebuild after touching tokenizer struct layout. Also rediscovered:
src/engine/tq_moe.c uses `goto moe_shared_expert` outside the
`#ifdef TQ_HAS_METAL` block but the label is inside, so non-Metal
configurations fail to build — keep TQ_BUILD_METAL=ON for now.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 475799a commit 714cd4c
3 files changed
Lines changed: 29 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
459 | 459 | | |
460 | 460 | | |
461 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
462 | 467 | | |
463 | 468 | | |
464 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
337 | 341 | | |
338 | | - | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
339 | 347 | | |
340 | 348 | | |
341 | 349 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
950 | 950 | | |
951 | 951 | | |
952 | 952 | | |
953 | | - | |
954 | | - | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
955 | 967 | | |
956 | 968 | | |
957 | 969 | | |
| |||
0 commit comments