Embla 1 on WebGPU
Embla 1 is a language model from sevren.ai: 10 billion parameters in total, but only about 1 billion of them are used for each token, and it ships in a 4-bit checkpoint small enough to think about running on a laptop. The question here was whether it could run in a web page at all, with the weights streamed from the Hugging Face Hub once, cached by the browser, and every token computed on the visitor’s own graphics card. Nothing a visitor types leaves the machine.
It can. Try it at rasgaard.com/embla-webgpu in desktop Chrome or Edge with WebGPU enabled. The first load downloads about 6 GB, so later visits are much quicker.
The first working version managed about 1.6 tokens a second, which is far too slow to be a chat. Getting it to about 185 tokens a second on an Apple M4 Pro, roughly 180 in the chat, took a long series of steps. The biggest jumps came from replacing ONNX Runtime’s generic kernels with a hand-written WebGPU decoder, and then from removing every round trip between the CPU and the GPU during decoding. The full log in optimizations.md records each step with the measurement that justified it, and the dead ends that were not kept.
| Milestone | Decode speed |
|---|---|
| First working graph in the browser | ~1.6 tokens/s |
| Fused 4-bit operations in the graph | ~6.5 tokens/s |
| ONNX Runtime engine and graph rewrites | ~15 tokens/s |
| Hand-written WGSL decoder | ~57 tokens/s |
| GPU sampling, no CPU in the decode loop | ~139 tokens/s |
| Subgroup mixes and packed scales | ~185 tokens/s |
Two things were hard to see from the outside. WebGPU reports validation errors silently: a bad dispatch just does nothing and the output comes back as zeros, so every check compares against a PyTorch reference and against the ONNX graph, token by token. And the GPU clocks down when it waits, so a pause between steps makes the next one slower; keeping the next step queued before the current token is read back was worth a lot.
The code is on GitHub under the MIT license. It builds on the authors’ Metal engine, embla-metal, and on onnxruntime-web and Transformers.js. The numbers come from one machine, so they show relative progress rather than a benchmark, and the project has only been tested on Apple silicon in Chromium. Without WebGPU subgroups it falls back to the slower ONNX path, at about 15 tokens a second.