iOS swiftpm-1.4.0 prebuilts: HF tokenizers with lookahead regex abort the app (signal 6) — regex_lookahead still missing
@shoumikhin is already working on this.
Since Aug 21, 2026.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
Loading current-generation HF tokenizers through ExecuTorchLLM.TextRunner on iOS aborts the whole app when the tokenizer's pretokenizer regex uses lookahead — which most current models do: \s+(?!\S) appears in the tokenizer.json of Qwen2/3/3.5, LFM2/2.5, and other GPT-2-descended tokenizers.
Console on launch (iPhone 17 Pro, swiftpm-1.4.0 prebuilts, Qwen3.5-0.8B tokenizer.json — identical failure with LFM2.5-1.2B-Instruct):
E0000 re2.cc:237] Error parsing '((?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n...': invalid perl operator: (?!
I tokenizers:re2_regex.cpp:27] Re2 failed to compile regex: ((?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}{1,3}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+), error: invalid perl operator: (?!
E tokenizers:regex.cpp:66] RE2 doesn't support lookahead patterns. Link with `regex_lookahead` to enable support.
E tokenizers:hf_tokenizer.cpp:482] Failed to setup pretokenizer: Error: 9
App terminated due to signal 6.
Two separable problems:
regex_lookaheadis not shipped in the SwiftPM prebuilts.Package.swiftonswiftpm-1.4.0exposes no product containing lookahead support, so the "Link withregex_lookahead" hint is not actionable for SwiftPM users. This is the same situation reported onswiftpm-1.1.0in #16391 (closed without a landed fix, as far as I can tell); #14432 is the Android neighbor.- The failure mode is an abort, not an error. After
Failed to setup pretokenizer: Error: 9the process dies with signal 6, so the host app cannot catch the failure fromTextRunner.load()and degrade gracefully.
Workaround we validated
Patching the tokenizer.json pattern \s+(?!\S) → \s+$ makes RE2 accept it. We verified token-for-token identical encodings against the original tokenizer (HF tokenizers on the host) for normal single-spaced text, English and Japanese; runs of ≥2 consecutive spaces tokenize differently, so this is a stopgap, not a fix.
With that patch (plus -all_load in OTHER_LDFLAGS, without which backend/kernel registration silently fails), a Qwen3.5-0.8B 8da4w/XNNPACK export from the official config generates correctly on the device.
What would help
- Ship
regex_lookahead(or fold it intoexecutorch_llm) in the SwiftPM prebuilts, or document the supported path for HF tokenizers on iOS. - Return an error from
TextRunner.load()instead of aborting.
Versions
ExecuTorch 1.4.0 (pip) for export; SwiftPM branch swiftpm-1.4.0 prebuilts on device. iPhone 17 Pro (iPhone18,1), iOS 27.0 (24A5380h). Xcode 27.0 beta 3. Export host: macOS 15 / Apple Silicon.
cc @shoumikhin @cbilgin
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.