Repository navigation
[Wasm] Let the tokenizer bindings load HF and Tekken tokenizers - #25103
Open
abdelaziz-mahdy wants to merge 1 commit into
Open
abdelaziz-mahdy wants to merge 1 commit into
abdelaziz-mahdy wants to merge 1 commit into
Conversation
Two build settings were missing for EXECUTORCH_BUILD_TOKENIZERS_WASM:
- The tokenizers library catches its own exceptions in normal operation
(HFTokenizer probes optional JSON keys and {"String": ...} patterns).
Emscripten runs no catch blocks without -fexceptions, so the throw
escaped to JS and HFTokenizer.load() failed.
- HF and Tekken patterns use lookahead, which needs regex_lookahead.
SUPPORT_REGEX_LOOKAHEAD was only set for the LLM runners.
Fixes pytorch#25102
This PR needs a
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #25102.
Bug: the Wasm tokenizer bindings can't load HF or Tekken tokenizers. That includes
test_hf_tokenizer.jsonandtest_tekken.jsonfrom this repo.Two causes, two fixes
-fexceptions.extension/wasm/tokenizers/CMakeLists.txtcompilestokenizersandregex_lookaheadwith-fexceptions, and passes it on to the final link throughtokenizers_wasm.regex_lookahead. It was only enabled for the LLM runners.CMakeLists.txtalso setsSUPPORT_REGEX_LOOKAHEADforEXECUTORCH_BUILD_TOKENIZERS_WASM.Native builds don't change: both settings apply only to the Wasm tokenizers build.
Test plan
Built
tokenizers_wasm_libexactly as the README describes (Emscripten 4.0.10, Release), then loaded the repo's test tokenizers in node and encoded"Hello world":HFTokenizerTekkenTiktoken/SPTokenizer-fexceptionsonlySo both changes are needed.
Repro script (node)
The Wasm tokenizers have no CI test today. I can add a jest test like
extension/wasm/testhas for the runtime, if you'd like it in this PR.