Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/huggingface_tokenizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ namespace tokenizers {
*/
class HFTokenizer : public Tokenizer {
public:
explicit HFTokenizer(TokenizerHandle handle) : handle_(handle) {}
explicit HFTokenizer(TokenizerHandle handle) : handle_(handle) {
#ifdef COMPILE_WASM_RUNTIME
setenv("TOKENIZERS_PARALLELISM", "false", true);
#endif
}

HFTokenizer(const HFTokenizer&) = delete;
HFTokenizer(HFTokenizer&& other) { std::swap(other.handle_, handle_); }
Expand Down
2 changes: 1 addition & 1 deletion web/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ rustup target add wasm32-unknown-emscripten

mkdir -p build
cd build
emcmake cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3"
emcmake cmake ../.. -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-O3 -DCOMPILE_WASM_RUNTIME"
emmake make tokenizers_cpp tokenizers_c sentencepiece-static -j8
cd ..

Expand Down
13 changes: 13 additions & 0 deletions web/tests/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,21 @@ async function testLlamaTokenizer() {
}
}

// Without COMPILE_WASM_RUNTIME, this triggers parallel processing, leading to error
async function testBertTokenizer() {
console.log("Bert Tokenizer");
const modelBuffer = await (await
fetch("https://huggingface.co/Snowflake/snowflake-arctic-embed-l/raw/main/tokenizer.json")
).arrayBuffer();
const tok = await Tokenizer.fromJSON(modelBuffer);
const text = "What is the capital of Canada?";
const ids = tok.encode(text);
console.log(ids);
}

async function main() {
await testJSONTokenizer()
await testBertTokenizer();
await testLlamaTokenizer()
}

Expand Down