glm: fix [gMASK]<sop> tokenization without BOS metadata - #939
Open
mvid wants to merge 1 commit into
Open
Conversation
mvid
force-pushed
the
fix/glm-bos-preamble
branch
from
September 1, 2026 22:31
700216e to
3118e1e
Compare
mvid
force-pushed
the
fix/glm-bos-preamble
branch
from
September 3, 2026 21:12
3118e1e to
59cd9a1
Compare
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.
Problem
GLM chat templates start with
[gMASK]<sop>. Some converted GGUFs omittokenizer.ggml.bos_token_id, and the current fallback assigns<sop>tobos_id. That makes both direct chat construction and rendered server prompts tokenize the preamble as<sop><sop>.The rendered-token table already maps
[gMASK]tobos_id, so the fallback conflicts with the tokenizer's own intended mapping.Change
[gMASK]token when GLM BOS metadata is absent, retaining<sop>as a compatibility fallback.<sop>only when it differs frombos_id.[gMASK]<sop>tokenization, and direct-path BOS/SOP deduplication.Compatibility boundary: a tokenizer that lacks
[gMASK]entirely still has different direct and rendered behavior. The direct path emits one<sop>after deduplication, while rendered[gMASK]<sop>still maps both literals tobos_id == sop_id. Official GLM Flash vocabularies contain[gMASK]; this PR retains the old<sop>fallback without redefining that no-[gMASK]rendered-template edge.Testing
Machine: Apple M5 Max, 128 GB, Metal.
Model used for the full suite: DeepSeek V4 Flash
Layers37-42Q4KExperts-OtherExpertLayersIQ2XXSGateUp-Q2KDown-AProjQ8-SExpQ8-OutQ8.make clean make -j4 DS4_TEST_MODEL=/path/to/DeepSeek-V4-Flash-Layers37-42Q4KExperts-OtherExpertLayersIQ2XXSGateUp-Q2KDown-AProjQ8-SExpQ8-OutQ8-chat-v2-imatrix-fixed-0731.gguf make testAll tests passed, including the new
tests/test_tokenizertarget and the existing server, agent, Metal tensor-equivalence, sampling, and CLI suites.The metadata-less GLM GGUF used during diagnosis predates the current upstream GLM-5.3 metadata format, so current
mainrejects it during shape validation before tokenizer setup (expected block_count=79 for GLM 5.2, got 46). The permanent regression therefore uses a synthetic GLM vocabulary and runs without a model file.Requirements