Repository navigation
tokenizer: linear sentinel scan; keep GLM turn tokens literal in prompts - #294
Merged
Merged
Conversation
encode_with_sentinel_families searched every family's opener over the whole remaining prompt on each iteration, so a message full of literal <tool_call> on GLM or Qwen4_exp scanned quadratically while the other family had no openers. A bare U+FDD0 reached the same cost on any model: each one searched the rest of the prompt for its close. Both ran in spawn_blocking before admission, and 32 MiB fits the default body limit. Keep each family's next opener between iterations and stop the close search at the longest index a sentinel can hold. Encoder calls match the old code on 1.2M random sentinel strings; only a garbage body over 20 characters, which this code never writes, now stays text. Co-Authored-By: Claude Opus 5.5 <[email protected]>
<|system|>, <|user|>, <|assistant|> and <|observation|> were outside the escape list, so a fetched page in a tool result could open a real user turn. Argument names were skipped too, and tool schemas never reached the escape at all. The SparkGLM profiles set ATLAS_USE_HF_REF_JSON_DUMPS=1, whose tojson leaves `<` raw, so schemas and nested arguments forge there. Escape the four tokens, every argument key, and tool schemas. Schemas follow SparkQwen 0.4.0, which already escapes them on both models. Qwen4_exp has none of the turn tokens; beyond 0.4.0 its prompts change only for an argument name carrying a tool marker. This departs from SparkGLM 0.2.0 for prompts containing those strings. </think> and <|endoftext|> stay native: the template splits assistant text on the first, and neither opens a turn. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
|
Merged after a pair gate on reiner + spark2 against its parent, #283's head. Receipts are in reiner's
I'm merging it into the SparkQwen stack, taking #293's side in template.rs as you suggested. |
This was referenced Oct 31, 2026
Contributor
|
GB10 single-Spark confirmation (sparky, post-merge): this PR was gated as part of
|
Merged
4 tasks done
AzeezIsh
pushed a commit
that referenced
this pull request
Nov 1, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Two request-input fixes in prompt encoding. Neither changes prompts that don't contain the affected strings, apart from the Qwen note below.
encode_with_sentinel_familiessearched each family's opener over the whole remaining prompt on every iteration. A message full of literal<tool_call>on GLM or Qwen4_exp scanned quadratically, and a bare U+FDD0 reached the same cost on any model by searching the rest of the prompt for its close. This ran inspawn_blockingbefore admission, and 32 MiB fits the default body limit.<|system|>,<|user|>,<|assistant|>and<|observation|>were outside the escape list, so a fetched page in a tool result could open a real user turn. Argument names were skipped, and tool schemas never reached the escape. The SparkGLM profiles setATLAS_USE_HF_REF_JSON_DUMPS=1, whosetojsonleaves<raw, so schemas and nested arguments forge there. Default-modetojsonencodes<and hides this.Test plan
cargo fmt --all -- --checkcargo clippy --workspace --tests, with theci.ymlenv, no warnings. The template's--all-featuresform stops onobjc2on Linux.bash scripts/check-license-headers.sh: not run, no new files.tokenizer.json: each encodes as plain text and reads back unchanged.many_sentinels_do_not_rescan_a_family_with_none,unclosed_openers_do_not_rescan_for_a_close,a_body_too_long_for_an_index_stays_textrole_tokens_in_results_arguments_and_schemas_stay_text(six cases, bothtojsonmodes)qwen_tool_markers_in_schemas_stay_textspark-serverfilterstokenizer::96,api::chat::112,literal_xml13, all passing. The workspace suite was not run locally.The scan's encoder calls matched the old code on 1.2M random sentinel strings across three family sets (26,906 spelled markers). The only difference is a garbage body over 20 characters, which this code never writes, now staying text.
Preliminary, single run, debug test build in a container: 15.9 s for 2.6 MiB and 18.3 s for 1.5 MiB before the fix; 2.9 s and 12.5 s for full 32 MiB inputs after.
Notes for reviewers
template.rs. Take grammar: SparkQwen 0.4.0 literal-dispatch convergence (ported from Enntity; replaces #288) #293's side. It moves the same call and already chainsjinja_tools.glm_tool_markup.rsmerges without a conflict. Merges cleanly with vision: SparkQwen 0.4.0 vision/video path (content-keyed vision cache, per-seq state, whole-request admission, hour video, #239 fix; ported from Enntity) #286, scheduler: SparkQwen 0.4.0 width-change amortization, depth-window tests, opt-in copy drafts (ported from Enntity) #287, tokenizer: SparkQwen 0.4.0 ids-only / large-encode gates + free the slot on a failed deferred prefill (ported from Enntity) #290 and moe t_rows on gfx1151: guard the tail-tile reads past N, then un-gate (Flash-Next C4 +26%, C8 +23%) #292.9b25f575), which escapes them on both models. So main's Qwen schemas change here, toward 0.4.0.</think>(the template splits assistant text on it) and<|endoftext|>. Neither opens a turn, andreconcile_prompt_thinkingreads only the last 8 prompt tokens.<|im_start|>in message text is unchanged and untested here. It may deserve the same look.[UNK], every spelling looked like one added token, somarkerskept them all.These are security-relevant and
SECURITY.mdasks for private reports. The commits were already public onEnntity/atlaswhen that was noticed, so this comes as a normal PR.Authorship
AI-authored (Claude Code). No human-written code.
🤖 Generated with Claude Code