Repository navigation
tokenizer: \A, \z, $, \G and atomic groups, as the ERNIE 5.5 pre-tokenizer uses them - #4984
Conversation
c7f3c86 to
7c4f403
Compare
|
I reran the tokenizer checks on I separately downloaded Igor Lessio - AIFLOW LABS |
Thank you for rerunning this. Regenerating the fixture in a fresh tokenizers 0.23.3 environment is the check I could not make myself: it shows the expected outputs come from the reference and not from my machine. The host suite on Apple silicon also covers a platform I did not run locally. |
|
Thanks, @Bizuayeu. Previously accepted patterns retain their parser and matcher behavior; the new syntax takes branches that were previously refused. The independent 64-test result and exact fixture regeneration are useful. The digit-run budget limit and fixture attribution are clear. This tokenizer-core change looks ready; full ERNIE token-ID and model checks remain with the family slice.
|
Thank you for the review. The ERNIE token-ID tests (plain and chat prompts against the reference tokenizer) are in #4985, which I'll rebase onto main once this lands; the model checks come with the slices after it. |
…nizer uses them ERNIE 5.5's tokenizer.json splits digit runs into 510s and then threes from the right with `(?>...)`, `$`, `\A`, `\z` and `\G`, which the matcher refused, so the tokenizer did not load (UnsupportedRegex). Each is now a zero-width step as Oniguruma reads it in Ruby syntax: `\A` and `\z` are the piece's start and end, `$` is its end or a position before "\n", `\G` is where the search started (find_iter's last end), and `(?>...)` is the atomic step possessive quantifiers already use. A pattern that compiled before compiles to the same program. fixtures/onig_anchors.json holds what tokenizers 0.23.3 splits for each, and for the release's pre-tokenizer on digit texts and runs from 509 to 1,025 digits; tools/zig/onig_anchor_fixtures.py rebuilds it from the release's tokenizer.json.
7c4f403 to
7b65724
Compare
|
Thank you @Bizuayeu. 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. |
What this changes
The tokenizer core's split-pattern compiler refused
\A,\z,$,\Gand atomic groups(?>...)withUnsupportedRegex, so thetokenizer.jsonofbaidu/ERNIE-5.5-Flash-Preview(revisionace1100dcde7bf4eb06add6ae11ce4f43a11ddfe) did not load: three of its five Split patterns use them to group a digit run in threes from the right. It now reads them as Oniguruma reads them in Ruby syntax, the syntax the tokenizers library compiles patterns with:\Aand\zmatch at the start and the end of the piece the Split is applied to;b\zdoes not matchab\n(\Zstays refused).$matches at the end of the piece or before a\n, and not before the\rof\r\n.\Gmatches where the search started, which after the first match is the previous match's end, as Oniguruma'sfind_itersearches;\Gbfindsbtwice inbbab.(?>...)compiles to the atomic step that possessive quantifiers already use.^,\Z, these escapes inside a class, and named groups stay refused. On main each of the five constructs failed at load (the parser refused$and(?>, and its escape table refuses an alphanumeric escape it does not know), so every pattern that loaded before parses to the same tree and splits as it did.ERNIE's first digit pattern,
\p{Nd}{1,510}(?=(?>\p{Nd}{510})*(?:\P{Nd}|$))|\G\p{Nd}{510}, does work that grows with the square of a digit run's length, in the tokenizers library as well: tokenizers 0.23.3 (Python, x86-64 Windows 11) takes 35 s on a run of 1,048,576 digits and 144 s on 2,097,152. Here it stays inside the matcher's existing allowance up to about 1,400,000 digits (a scratch probe, ReleaseSafe: 22% of the allowance at 8,192 digits, 16% at 65,536, 75% at 1,048,576, 90% at 1,400,000; the share moves with the run's length mod 510), and a run of 2,097,152 digits is refused withRegexBudgetinstead of being split wrong. The three patterns together give the run's digits in threes from the right, so a linear path for that one shape could follow if longer runs are wanted; this pull request does not add one.atc check 4926 --json(atc 0.9.4,ATC_READ_ONLY=1, 2026-11-25 01:15 UTC) returnscomplete: falsewithpullRequestsLimitand adviceincomplete(it reads 300 open pull requests and 370 are open), so nothing is claimed through ATC.3795e6054c; one commit,7c4f403911. Main has since moved on to4c79cfe346;git merge-tree --write-treeof this head with it merges without a conflict, and its 42 new commits change no file underzig/src/core/tokenizer/.atc overlap --json: atc 0.9.4 withATC_READ_ONLY=1, run in this tree on 2026-11-25 at 01:08 UTC after the last rebase, base main3795e6054c, headc7f3c86ce9(the same tree as7c4f403911but for the number in theCHANGELOG.mdline):complete: false(otherPullRequestsLimit,pullFilesUnavailable,pullRequestsLimit,timeLimit). It lists 13 pull requests that share one file each with this branch,CHANGELOG.mdorTHIRD_PARTY_NOTICES.md: 3conflicts(Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835, app: control vector picker and strength in Engine advanced #1951, ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514), 7cleanand 3unknown(ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475, ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522, flashnext ranks: every byte after the key proof crosses the pair's link in sealed records #3076). For those six,git merge-tree --write-treeof the pull request's head with main3795e6054c, without this branch, already conflicts, in the same set of files and with the same number of conflict hunks inCHANGELOG.mdandTHIRD_PARTY_NOTICES.mdas with this branch. Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835 and app: control vector picker and strength in Engine advanced #1951 add their line at the top of## Unreleased, which conflicts with the lines main added there since; this branch's line falls inside that hunk. ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475 and ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514 conflict inTHIRD_PARTY_NOTICES.mdaway from this branch's section, which merges outside the hunk. ricursive: serve Ripple-65B on two GB10s with up to 1M tokens of context #2522 and flashnext ranks: every byte after the key proof crosses the pair's link in sealed records #3076 conflict only in files this branch does not touch. app: control vector picker and strength in Engine advanced #1951, ricursive: Ripple-65B-Preview's DFlash2 drafter on native CUDA #2475 and ricursive: load Ripple's EXL3 packs through main's shared EXL3 code #2514 also conflict in other files this branch does not touch. Run again after the last push, on 2026-11-25 at 02:42 UTC with base main94e0f2dc27: the same 13 pull requests with the same verdicts (main's 16 new commits add conflicts inzig/src/families/qwen27/andzig/src/native/to Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835 and app: control vector picker and strength in Engine advanced #1951, files this branch does not touch). Run once more on 2026-11-25 at 04:45 UTC with base main4c79cfe346: 18 pull requests share a file, 3conflicts(Implement GLP control vectors with a fused Metal kernel for Qwen3.8-27B #1835, app: control vector picker and strength in Engine advanced #1951, CUDA: an int4 W4A16 kernel for GPTQ group-128 routed experts and the LM head #4183), 7cleanand 8unknown; for each of the 11 that are notclean,git merge-tree --write-treeof the pull request's head (checked against itsheadRefOid) with this branch's parent3795e6054cand with this head gives the same conflicting files and the same number of conflict hunks, so this branch adds no conflict. As the list is incomplete, I also read the changed files of every open pull request (369 on 2026-11-24 at 23:24 UTC, through GraphQL and REST, tp ranks: every byte after the key proof crosses the bootstrap, fate and plan links in sealed records #3101 only up to REST's 3,000 of its 3,533 files; and again the 27 updated since, through REST past 100 files): none touchesregex.zig,regex_test.zig, the new fixture or the new script.Checks on this head
7c4f403911on main3795e6054c. The runs below are onc7f3c86ce9, which differs from7c4f403911only in the number in itsCHANGELOG.mdline and in its commit title, except where a line names the stacked head83d1fe7bdc: the ERNIE package's commit on this one, which adds files underzig/src/families/ernie5_5/, a build file, its fixtures script, one line inbuild.zig, and its own section and line inTHIRD_PARTY_NOTICES.mdandCHANGELOG.md, and changes none of this commit's code, tests, fixture or script.python3 tools/zig/lean_check.py, on the base and on this head: 165 problems on main3795e6054cand 165 on this head, 0 new (tools/zig/lean_new.py; each tree ran its ownlean_check.py, which this branch does not change). The 165 are inherited from main.zig build -Dfixed-cpu test-tokenizer-host --summary all: main3795e6054c3 of 3 steps, 61 of 61 tests passed; this head 3 of 3 steps, 64 of 64 tests passed.zig build test-tokenizer-host --summary all: main 59 of 61 passed, 2 skipped; this head 62 of 64 passed, 2 skipped (the same two skip on main).regex.zigput back: 59 passed, 2 skipped, 3 failed, the three new tests (text and line ends, the search start and atomic groups split as the tokenizers library's Oniguruma does;ERNIE 5.5's pre-tokenizer cuts digit runs into 510s and then threes from the right, as the tokenizers library does;ERNIE 5.5's 510-digit pattern, whose work grows with the square of a run, splits a long run within its allowance).tools/zig/onig_anchor_fixtures.py --tokenizer <the release's tokenizer.json> --output <file>(the script checks the library version and the file's sha256,20e7c81f36fdfb90db664583fc6426d5c2ac6d6bcaf631c910941a8d8f30f2d9) writes 19 anchored cases, 17 texts through ERNIE's pre-tokenizer and 8 digit runs of 509 to 1,025 digits; rerun on this head, its output equals the committed fixture byte for byte. The tests also refuse[\A],[\G],[\z],^a,a\Z, an unclosed(?>aand a named group.½) encode to the same ids as tokenizers 0.23.3 and decode to the same text; 4 chats from the release's chat encoding encode to its ids throughencodeMasked. The stacked ERNIE package commits that check, on 20 requests.83d1fe7bdcin a fresh tree: plainzig build -Dfixed-cpu: exit 0.zig build -Dfixed-cpu test test-golden test-kernel-contract fuzz-cortheon --test-timeout 20m --summary failures: 915 of 918 steps succeeded, 13,844 of 13,942 tests passed, 97 skipped, 1 failed,start_cli_test("Ctrl-C during a deferred download has its normal process effect"), whose forked child raises SIGINT. My job runner had started the build as a background job of a non-interactive shell, so every child process ignored SIGINT and SIGQUIT; that step's test binary, built from this branch on an earlier base (1e5072adbd, wherestart_cli_test.zigis the same), passes 29 of 29 when run directly. With the runner restoring the default handling, the same command succeeded, 918 of 918 steps (the steps that had passed came from the cache).python -m pytest -q -rs -p no:cacheproviderfrom the root, on Linux with pytest 9.2.0 and PyYAML 6.0.4 (what CI's job installs), Zig 0.17.0 and aclang++onPATH: main3795e6054c, this head and the stacked head each 808 passed, 106 skipped, 825 subtests passed, with the same skip reasons. Main's runs on3795e6054cwere cancelled before its pytest job finished; its last green pytest job, on the earlier39931281a0, has 754 passed and 104 skipped. Two of the skips here aretools/zig/test_nfkd_tables.py("this interpreter has Unicode 15.0.0").zig fmt --check zig/src/core/tokenizer/regex.zig zig/src/core/tokenizer/regex_test.zig,zig ast-checkof both, andgit diff --check origin/main..HEAD: exit 0.python3 tools/pr_check.py --base origin/main --pr 4984: 0 errors, 0 warnings.7c4f403911:fmt,zig,zig-b,zig-windows,zig-macos-dev-tools,pytest(809 passed, 105 skipped, 826 subtests passed; the Linux run above has 808 and 106, and the CI log does not print skip reasons),release-paths (ubuntu-24.04),comfyui-moss-installerand bothbenchmark-clientsjobs passed;host-nightly-linuxandhost-nightly-macoswere skipped. The annotations are GitHub's Node.js 20 deprecation warnings and a macOS runner queue notice.Receipt
n/a for decode and prompt speed: the new steps run only when a split pattern uses one of the five constructs, each of which failed at load on main, so no tokenizer that loads on main splits differently (in the repository, neither of the two
"Regex"fields in JSON fixtures nor anypretokenize_regexuses them). Split patterns reach the compiler from atokenizer.json's pre-tokenizer (steps.zig) and from a Clef checkpoint'spretokenize_regex(Tokenizer.overrideSplit, called byserver/hf_text.zig); both match throughsteps.zig'sPattern.findon a whole piece.test-goldenover the frozen server corpus passed in the suite above.3795e6054cand this head, Zig 0.17.0, x86-64 Linux (Ubuntu 24.04 under WSL 2) and x86-64 Windows 11, CPU only; thetokenizer.jsonofbaidu/ERNIE-5.5-Flash-Previewatace1100dcde7bf4eb06add6ae11ce4f43a11ddfefor the fixture and the probes, and tokenizers 0.23.3 for the expectations.THIRD_PARTY_NOTICES.mdhas a section for it.Checklist
regex.zigas above; they read only embedded fixtures, so nothing makes them skip).