The Dawn of High-Performance WebGPU Kernels
Running AI models directly in the browser has always been a tantalizing goal: no server costs, no data privacy concerns, and instant access for users. But the reality has been a frustrating bottleneck. While WebGPU provides a portable API for GPU acceleration, and WGSL offers a shading language, achieving performance across the diverse landscape of devices, browsers, and drivers is a monumental challenge. A naive shader can be 10x or even 10000x slower than a well-tuned one for the same operation.
Hugging Face has taken a bold step to solve this problem. Today, they are releasing @huggingface/kernels, a minimal JavaScript library for loading and running optimized WebGPU kernels directly from the Hugging Face Hub, along with an initial collection of 207 kernels covering a wide range of machine learning operations. This is not just a set of shaders; it's a complete, versioned, and testable software artifact ecosystem. As they state in their official announcement, this is the foundational layer for a new wave of browser-based AI.
Why Kernels are the Foundation
Think of any AI model as a pipeline. In the browser, this pipeline eventually becomes a sequence of GPU operations: matrix multiplications (MatMul), normalizations, convolutions, attention primitives, and more. The performance of these individual operations dictates the overall speed of the model. You can have the most elegant high-level runtime, but if the underlying operations are slow, the entire application suffers.
This is why Hugging Face is focusing on the kernel level. By making each operation individually discoverable, testable, benchmarkable, and versioned, they create a stable contract for higher-level runtimes. This allows for independent improvement of the foundation, ensuring that the entire ecosystem benefits from each optimization. The result? A 2.57x speedup (geometric mean) over ONNX Runtime Web on an Apple M4 GPU in their initial benchmarks.
A Kernel Repository, Not Just a Shader
Each of the 207 kernels lives in its own repository, complete with a kernel card that documents its semantics, inputs, outputs, and supported data types. But the real magic is in the repository's structure. It includes:
manifest.json: The source of truth for the operation contract.metadata.json: For kernel identifier, digests, and provenance.test.json: Contains correctness cases for validation.bench.json: Benchmark and tuning cases for performance evaluation.*.wgsl.jinja: Parameterized WGSL implementations.
This structure transforms a simple shader into a reusable, inspectable, and verifiable artifact. For developers building custom WebGPU kernels or integrating these into their own runtimes, these serve as excellent reference implementations.
![]()
How to Load and Run a Kernel
Getting started with @huggingface/kernels is straightforward. First, install the package:
npm install @huggingface/kernels@preview
Then, you can load and run a kernel with just a few lines of JavaScript. Here’s a simple example of a bias-add operation:
import { getKernel } from "@huggingface/kernels";
// Load the Add kernel from the Hub
const add = await getKernel("webgpu-kernels/ai.onnx.Add", { version: 1 });
// Define your inputs (tensors)
const { c } = await add({
a: {
data: new Float32Array([1, 2, 3, 4, 5, 6]),
shape: [2, 3],
},
b: {
data: new Float32Array([10, 20, 30]),
shape: [3],
},
});
// The output 'c' is automatically allocated and filled with the result.
// This operation uses broadcasting, so the shape of 'c' will be [2, 3].
The library handles shape derivation and data type allocation for you, based on the kernel's manifest. This pattern is identical for more complex operations like ai.onnx.MatMul; only the repository ID and inputs change. The library also supports kernel variants, allowing the runtime to select the most optimized implementation for a given device and input shape without changing the application-facing API.

Fleet: Crowdsourcing GPU Performance Data
One of the biggest challenges in WebGPU development is the sheer diversity of hardware. A kernel that is fast on a high-end NVIDIA GPU might be pathologically slow on an integrated Intel GPU. To address this, Hugging Face is also launching Fleet, a browser-based benchmarking and testing suite.
Fleet allows anyone to run correctness and performance checks on their own hardware, contributing valuable evidence to the community. With user consent, each run privately shares results that help identify device-specific failures, compare kernel variants, and improve selection rules. This crowdsourced approach is brilliant; it provides a level of real-world coverage that is impossible in a conventional test lab.
Performance Highlights: A Deeper Dive
The initial benchmarks are impressive. Here’s a quick look at how their kernels compare to ORT WebGPU on an Apple M4 GPU:
| Operation | Compared Cases | Our WebGPU Kernel | ORT WebGPU | Speedup |
|---|---|---|---|---|
| Add | 5 | 0.064 ms | 0.227 ms | 3.52x |
| MatMul | 29 | 0.115 ms | 0.131 ms | 1.14x |
| Softmax | 12 | 0.114 ms | 0.240 ms | 2.11x |
| LayerNormalization | 6 | 0.061 ms | 0.135 ms | 2.22x |
While these are aggregate numbers, some individual cases were dramatically faster. A particularly difficult bilinear Einsum case ran in 0.136 ms versus 1,396 ms with ORT WebGPU—a 10,000x speedup. These are not typical, but they highlight the potential of specialized kernels when general implementations hit a slow path.
Limitations and Caveats
It's crucial to have a balanced perspective. The speedups were measured on GPU time only, excluding setup like shader compilation and data transfer. For very small operations, the GPU round trip cost can dominate, making the overhead not worthwhile. Also, these are results for individual operations, not complete models. The end-to-end performance will vary significantly across different GPUs and browsers. Furthermore, the project is a preview (@preview version), so the API and kernel collection are subject to change. This is a promising start, but not a silver bullet for all browser AI performance issues.

Conclusion: A Shared Foundation for WebAI
The release of @huggingface/kernels and Fleet is a significant milestone for WebAI. By publishing reproducible, versioned kernels and creating a community-driven benchmarking platform, Hugging Face is building a shared foundation that benefits everyone. This is not just about making their own tools faster; it's about accelerating the entire ecosystem.
The collection is already part of the broader kernel ecosystem on the Hub, sitting alongside CUDA, ROCm, and Metal kernels. If you're venturing into on-device AI, this is a resource you can't ignore. For more insights into building performant AI applications, check out our guide on building on-device AI agents with ADK for Kotlin. And to understand how large-scale systems handle massive data processing, read about Netflix's graph abstraction for handling 10M ops/sec on 650TB of graph data.
What's Next?
To get started, explore the WebGPU kernel collection on the Hub and try running Fleet on your own device. The future of AI is increasingly local, and this is a foundational step in that direction. Your contributions, whether it's running a benchmark or providing feedback, can help make these kernels faster and more reliable for everyone. The next steps will likely involve connecting these kernels to higher-level model tooling, making it even easier to run complex models directly in your browser.