The world is too loud. Read what matters.

Hugging Face

Browser AI Speedup: 200+ GPU Kernels Generated On the Fly, Not Precompiled

There is no 'universally optimal kernel' for running AI in the browser: a kernel is the implementation of an operator on specific hardware, and different devices have different optima. The 200+ kernels are not hardcoded programs but templates that are generated in the browser according to your device.

Browser AIWebGPUKernel OptimizationOpen SourceLocal Inference
An 11-minute solo release demo, no back-and-forth, medium density. The point that kernels must be tailored to the device is made intuitively; the templated kernels and Fleet's crowdsourced tuning mechanism are worth a closer look.

The argument · tap a timestamp to hear it

2:05

Operators define, kernels execute on hardware

The transcript first distinguishes two concepts: a model is a large graph of operators, and an operator is just a mathematical definition—addition is A+B; a kernel is the implementation that brings that definition to specific hardware. The same add, in the browser, goes through WebGPU/WGSL, while other ecosystems correspond to CUDA or Metal kernels. The two are often conflated, but the speed difference lies precisely in the latter: if the underlying kernel is fast, the entire inference graph can be fast. This also explains why it's worth repeatedly polishing a kernel for a simple operation rather than vaguely tuning a 'general math library'.

4:08

What's released are Jinja templates, not hardcoded kernels

The difference in approach is worth noting: the repository does not contain hardcoded WGSL files one by one, but several Jinja templates that use if/else to describe branches for different devices. At runtime, the library validates the template, selects the appropriate data types and workgroup sizes, and renders the WGSL most suitable for the current GPU adapter to run. For example, in the same addition function, the left side has narrower data types and smaller workgroups; the right side runs faster for the same add because the device supports wider data types and larger workgroups. The official release of 200+ kernel entries delivers the ability to 'make kernels on the fly per hardware'.

7:12

Attention mechanism in the browser takes only about 20 lines of JS

The demo brings abstraction back to reality: running a small attention mechanism in the browser required only about 20 lines of JavaScript. The flow is text→token→vector, but a token's vector cannot be viewed in isolation; you must see the influence of other tokens on it in context. The code only pulls in four kernels—matmul, softmax, add, and layer normalization—from the Hub; the rest of the scheduling and GPU data exchange is hidden by the Hugging Face Kernels library. The heavy lifting is all at the kernel layer, which is why the barrier to 'local inference in the browser' has dropped.

8:12

The entire wave animation is just one matrix multiplication

The same demo gives an intuitive comparison: 128 waves traverse a 1024×1024 matrix, and each cell's color is an RGBA computed by a matrix multiplication. The animation of over a million pixels runs at about 60fps under WebGPU—60 is not the compute limit, but requestAnimationFrame locks rendering to 60; the kernel itself can compute at about 400fps. Running the same logic with plain JavaScript yields only about 6.75fps. The gap is not in the math but in whether someone has written an implementation that hugs this particular GPU—that's what those kernels do.

10:15

Fleet turns user devices into tuning data via tests

Fleet is ostensibly a benchmark page: anyone can run their own GPU and see how it performs in comparison. But the team says it plainly: they only have a few devices of their own, yet the real world has thousands of WebGPU devices, possibly with edge cases they haven't thought of—some kernels may perform poorly or even fail on your machine. Fleet collects runtime data from real devices to continue optimization, and the improved kernels, being open source, return to all users. When you click 'Run Benchmark', you're not just seeing a score; you're also helping the project run a round of real-world adaptation testing.

In their own words · checked verbatim

the kernel is the implementation that can actually run the operation.

we don't ship WGSL files. We do ship Jinja files, so Jinja templates.

we basically have implemented an attention mechanism in pure JavaScript.

We only need one kernel. We only need the matrix multiplication.

All of that data is so valuable for us.

Figures

Number of WebGPU kernels released200+0:03
Number of encoding units in the opening animationabout 80000:03
Lines of JS needed to implement attentionabout 207:12
Wave animation matrix size1024 rows × 1024 columns / 128 waves8:12
Wave animation pixel countover 1 million8:12
Actual GPU frame rateabout 60 fps (limited by requestAnimationFrame)8:12
Theoretical GPU frame rateabout 400 fps9:14
Frame rate for the same task in pure JavaScriptabout 6.75 fps9:14

Glossary

kernel
The implementation of an operator on specific hardware; the same addition requires different kernels on different GPUs.
WGSL
WebGPU Shading Language, the language for writing kernels in the WebGPU environment, serving as the bridge to the GPU in the browser.
Jinja
A Python templating engine; HF uses .jinja files to describe kernels, then renders them into WGSL at runtime based on the device.
WebGPU
The next-generation API for accessing the GPU from the browser, the computational foundation for local AI inference on the browser side.
requestAnimationFrame
The browser's loop callback that drives animation frames, typically capping the frame rate at about 60fps.

How to listen

Who it's for

Engineers running LLMs in the browser or building high-performance front-end AI applications, as well as technical decision-makers interested in WebGPU and WASM local inference solutions.

Skip

The code walkthrough in the opening demo and the release channel introduction at the end can be sped up; focus on the kernel templating mechanism and the Fleet data feedback section.