Hugging Face @huggingface/kernels Release
Hugging Face has released @huggingface/kernels, a JavaScript library and a collection of 207 optimized WebGPU kernels. This release aims to accelerate local AI inference by providing a foundational layer of high-performance GPU operations that are discoverable, versioned, and testable directly from the Hugging Face Hub.
Optimized WebGPU Kernel Collection
Hugging Face has published 207 kernels as individual repositories under the webgpu-kernels organization on the Hub. These kernels cover a wide range of machine learning architectures and workloads, utilizing the WebGPU API and WGSL (WebGPU Shading Language) for portable, high-performance execution across modern browsers.
Each kernel is treated as a versioned software artifact rather than a simple shader. Every repository includes:
manifest.json: The source of truth for the operation contract, defining inputs, outputs, attributes, type constraints, and shape derivation rules.metadata.json: Records the kernel identifier, digests, and provenance.test.json: Contains correctness cases to verify implementation behavior.bench.json: Contains benchmark and tuning cases for evaluation.*.wgsl.jinja: Parameterized WGSL implementations used to generate shaders for specific devices and requests.
The @huggingface/kernels Loader
The @huggingface/kernels npm package provides the bridge between the Hub repositories and JavaScript applications. It allows developers to load a kernel by its Hub repository ID and contract version, then execute it with typed input data and tensor shapes.
For example, the loader can automatically derive output shapes and logical data types from the manifest contract. It also supports multiple kernel variants (e.g., vectorized vs. scalar processing) to ensure the most efficient implementation is selected based on the current call and device without altering the application-facing API.
Performance Benchmarks
In head-to-head comparisons against ORT WebGPU (using ONNX Runtime Web 1.30.0-dev.20260826-b1f76d586a) on an Apple M4 GPU, the Hugging Face kernels demonstrated significant speedups. Across 809 matching test cases, the kernels were 2.57x faster by geometric mean and 1.90x faster at the median.
Specific operation speedups include:
| 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 |
In extreme cases, specialized kernels provided massive gains: a bilinear Einsum case ran over 10,000x faster (0.136 ms vs 1,396 ms), and a row-wise CumSum was 301x faster (0.016 ms vs 4.784 ms).
Fleet: Crowdsourced Hardware Evidence
Because WebGPU performance varies significantly across different GPUs, browsers, and drivers, Hugging Face launched Fleet, an in-browser benchmarking and testing suite. Fleet allows the community to run correctness and performance checks on their own hardware and privately contribute evidence. This crowdsourced data helps the Hugging Face team identify device-specific failures, compare kernel variants, and optimize selection rules for real-world hardware.
Integration and Ecosystem
These WebGPU kernels are part of a broader Hub ecosystem that includes kernels for CUDA, ROCm, and Metal. By publishing kernels independently, Hugging Face provides a shared foundation where contracts can be inspected and implementations can be improved without requiring every shader to be embedded directly into a runtime. Hugging Face is also working with the ONNX Runtime team to upstream these improvements to the broader ONNX Runtime Web ecosystem.