Skip to content

fix(serialize): honor the regex backend when reading Split - #2547

Merged
ArthurZucker merged 4 commits into
huggingface:mainfrom
dlowzzxx:fix/json-split-regex-backend
Oct 21, 2026
Merged

ArthurZucker merged 4 commits into
huggingface:mainfrom
dlowzzxx:fix/json-split-regex-backend

Conversation

@dlowzzxx

@dlowzzxx dlowzzxx commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Related to #2511; complements #2536's binding feature changes.

read_split always uses Split::native, leaving regex search unavailable even when fancy-regex is enabled. A JSON WordLevel tokenizer with vocab {a: 0, b: 1, <unk>: 2} and Split(Regex(" +"), Removed) errors on a b instead of encoding [0, 1].

Use Split::new when the backend is enabled. Keep native construction without it so DeepSeek's individually unrecognized regexes can still form the fused sequence. Pipeline canonicalization remains unchanged.

The regression idea follows #2534. Following review, the regression is a single direct Split encode test gated on wordlevel and fancy-regex, as suggested by SBrandeis. The extra native-pattern test and Sequence/disabled-backend assertions have been removed.

Validation on Linux Docker with Rust 1.98.1, rerun after the review changes:

  • Backend on: tk-encode 232 tests and tk-serialize 43 tests pass.
  • Backend off: tk-encode 228 tests and tk-serialize 42 tests pass.
  • Both configurations pass two integration tests, two doctests and affected-crate Clippy with warnings denied. Existing ignored tests remain.
  • Rust formatting and whitespace checks pass.

Full Python/Node bindings and workspace matrices were not run. This does not claim BLOOMZ end-to-end compatibility or replace the binding fix.

AI-assisted, disclosed in the commit trailers.

@dlowzzxx
dlowzzxx marked this pull request as ready for review October 18, 2026 10:23

@SBrandeis SBrandeis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, thanks!
Let's simplify the tests too

Co-authored-by: Simon Brandeis <[email protected]>

Assisted-by: OpenAI Codex
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@SBrandeis SBrandeis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, let's wait on review from @ArthurZucker

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty

@ArthurZucker
ArthurZucker merged commit fb55b11 into huggingface:main Oct 21, 2026
30 checks passed
SBrandeis added a commit that referenced this pull request Oct 22, 2026
ByteLevel, Metaspace, Split, Digits and Punctuation, with 0.23.3's argument
order, defaults and JSON key order (all positional or keyword, like 0.23.3).
Readable attributes: ByteLevel.add_prefix_space, Metaspace.replacement and
Metaspace.split. ByteLevel.alphabet() returns the core's 256 byte-to-unicode
characters as a list.

Split and Punctuation share one conversion of `behavior` to its JSON
spelling. An unknown behavior or prepend_scheme raises ValueError like
0.23.3, with our own message.

The core refuses ByteLevel(add_prefix_space=True), 0.23's default, when it
compiles a tokenizer, so that case is pinned on its JSON only. A regex Split
fails at encode on this stack, which predates #2547; its JSON is pinned too.

Includes the encode check of a regex Split, which main's #2547 enables.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants