@huggingface/kernels: 200+ WebGPU Kernels for Local AI

Hugging Face‘s WebAI team introduces @huggingface/kernels, a minimal JavaScript library for loading and running optimized WebGPU kernels directly from the Hugging Face Hub, alongside an initial collection of 207 kernels published as individual versioned repositories.

The library provides explicit contracts via manifests, correctness tests, benchmark cases, and WGSL shader templates for each operation, covering operations like matrix multiplication, normalization, convolution, attention, and quantization.

To address performance portability—where the same shader can behave differently across devices, browsers, and input shapes—each kernel includes variants (e.g.

, equal-shape, broadcast, scalar, general) so the runtime can select the best implementation.

Hugging Face also launches Fleet, a browser-based benchmarking and testing suite that crowdsources correctness and performance evidence from real-world GPUs (with user consent) to identify failures and improve kernel variants.

Benchmarking against ONNX Runtime Web 1.30.0 on an Apple M4 GPU across 809 comparable test cases shows the kernels are 2.57x faster by geometric mean (median 1.

90x), with 629 wins, 176 losses, and 4 ties. Notable individual wins include a bilinear Einsum case over 10,000x faster and a CumSum case 301x faster, though these are outliers.

Measurements focus on GPU execution time, excluding setup overhead, and results vary across devices. The project is open-source (Apache-2.

0) and aims to provide a shared, testable foundation for browser-based AI inference, with plans to upstream improvements to ONNX Runtime Web and expand coverage.

Introducing @huggingface/kernels: 200+ WebGPU Kernels for Local AI

View Original