]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
unicode : add custom Qwen2 regex handler to fix segfault on long input (#21257)
authorSon H. Nguyen <redacted>
Tue, 7 Apr 2026 13:13:38 +0000 (22:13 +0900)
committerGitHub <redacted>
Tue, 7 Apr 2026 13:13:38 +0000 (16:13 +0300)
commit0d049d6a9245ccffc6073743ff8b6bb24ac6a47b
tree1c0d9a4660bef072067d19cf4bf9d0a1d842979a
parenta8ec0df4617692ef0f18b212f2e16bba540e053a
unicode : add custom Qwen2 regex handler to fix segfault on long input (#21257)

* unicode : add custom Qwen2 regex handler to fix segfault on long input

std::regex uses recursive backtracking internally, which causes a stack
overflow (segfault) when tokenizing long sequences of repeated characters
(e.g. 43K 'A's). The Qwen2 tokenizer regex differs from Llama3 only in
the digit pattern (\p{N} vs \p{N}{1,3}), so it was falling through to
the std::regex fallback path instead of using a custom handler.

Add unicode_regex_split_custom_qwen2() following the established pattern
used by gpt2, llama3, kimi_k2, and afmoe custom handlers.

Closes: https://github.com/ggml-org/llama.cpp/issues/21113
* cont : remove TODO comment

* cont : update comment to reflect original regex

* use the correct regex in the comment this time... [no ci]

---------

Co-authored-by: Aldehir Rojas <redacted>
src/unicode.cpp