feat: add wasm web support - #138
Merged
Merged
Conversation
jhen0409
marked this pull request as ready for review
June 3, 2026 05:14
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
Adds browser WebAssembly support for llama.node through a new
@fugood/node-llama-wasmpackage. The package keeps the high-level llama.node API shape for browser use, loads GGUF models by URL by default, supports session save/load with buffers and URLs, and includes CPU plus WebGPU WASM artifacts.The CPU path now auto-selects the pthread artifact on cross-origin isolated pages and defaults
n_threadstomin(4, navigator.hardwareConcurrency). The WASM runtime runs in a dedicated worker by default so model loading, tokenize/detokenize, completion, state, embedding/rerank, multimodal staging, and bench calls do not block the UI thread.Validation
node --check packages/node-llama-wasm/index.jsnode --check packages/node-llama-wasm/worker.jsnode --check scripts/build-wasm-package.jsnode --check scripts/build-wasm-docker.jsnpm run typechecknpm pack --dry-run ./packages/node-llama-wasmnpm run build-wasm-dockerselectedemscripten/emsdk:4.0.14-arm64 (linux/arm64)and copied the CPU WASM artifactMac Docker Benchmark
Clean CPU WASM build on Apple Silicon Docker Desktop with
JOBS=4and isolated Emscripten caches:emscripten/emsdk:4.0.13with--platform linux/amd64: 1268.44semscripten/emsdk:4.0.14-arm64with--platform linux/arm64: 122.51sThe native arm64 image is about 10.4x faster for this build on Mac, so
npm run build-wasm-dockernow selects4.0.14-arm64on arm64 hosts.Workflow Dispatches
Dispatched
.github/workflows/build-release.ymlon branchcodex/add-wasm-web-supportwithupload-artifacts=YESandpublish=NO:target=wasm: run 26815857397, build-wasm job - successtarget=darwin-arm64: run 26815867290, node-llama-darwin-arm64 job - success