Skip to content

unicode : add the K2-Horizon pre-tokenizer splitter - #1

Merged
aaryamonvikram merged 4 commits into
ifm-ai:model/K2Horizonfrom
WestWaters:k2-horizon-msvc-pretokenizer
Sep 17, 2026
Merged

aaryamonvikram merged 4 commits into
ifm-ai:model/K2Horizonfrom
WestWaters:k2-horizon-msvc-pretokenizer

Conversation

@WestWaters

Copy link
Copy Markdown

Overview

Additional information

Requirements

The K2-Horizon regex had no arm in unicode_regex_split_custom and fell through to the
general std::regex fallback, which fails two ways.

On MSVC std::regex rejects \p{...}, so no K2-Horizon GGUF loads on Windows at all:
llama-quantize, llama-imatrix and llama-perplexity all abort with
regex_error(error_escape) before a token is produced.

Where the fallback does compile it is still wrong. unicode_regex_split collapses each
codepoint to a single byte naming its Unicode category before matching, and U+200C/U+200D
are category Control, which has no entry in k_ucat_cpt, so both become the 0xD0 fallback
byte. The literal ‌ and ‍ alternatives in K2's regex can then never match and
every ZWNJ or ZWJ ends a letter run.

The splitter is the existing llama3 one with a single rule widened, since K2's regex
differs from llama3's only in that a letter run also takes marks, ZWNJ and ZWJ.

tests/test-unicode.cpp gains a case for this: it fails before the change with
[Amy] [ZWNJ khaham] and passes after with the run intact.
@WestWaters
WestWaters force-pushed the k2-horizon-msvc-pretokenizer branch from 65a1362 to 69d3a4e Compare September 11, 2026 08:08
@WestWaters
WestWaters changed the base branch from master to model/K2Horizon September 11, 2026 08:12
@WestWaters WestWaters changed the title K2 horizon msvc pretokenizer unicode : add the K2-Horizon pre-tokenizer splitter Sep 11, 2026
@WestWaters

Copy link
Copy Markdown
Author

I used an ai agent to help me get this working with my tool im building out Pollard-weights. If there is anything else needed please feel free to reach out.

https://github.com/WestWaters/pollard-weights

@TaskPuppyNatani

Copy link
Copy Markdown

I independently ended up testing the same K2-Horizon Unicode path and found the runtime implementation here matches the behavior I needed. I opened a test-only PR against @WestWaters' branch with broader regression coverage; it makes no runtime changes and passes against the current PR #1 implementation: WestWaters#1

@mohitsoni48

Copy link
Copy Markdown

Independently hit this exact bug loading a Mova/K2-Horizon GGUF (`Failed to process regex` / `regex_error(error_escape)`) and root-caused it the same way — arrived at the same fix (identical `unicode_regex_split_custom_k2_horizon`, same widened letter-run predicate) before finding this PR.

For what it's worth, a couple of things I verified independently that corroborate this:

Closed my duplicate (#3) in favor of this one — the real-world Persian ZWNJ test case here is better than my synthetic cases. Would be good to see this merged so Mova loads out of the box again.

@aaryamonvikram
aaryamonvikram merged commit 42adf01 into ifm-ai:model/K2Horizon Sep 17, 2026
1 check passed
@aaryamonvikram

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants