Hugging Face Releases @huggingface/kernels, a Library of 207 WebGPU Kernels for Browser AI
Hugging Face's WebAI team has released @huggingface/kernels, a JavaScript library that loads and runs 207 optimized WebGPU kernels so AI models can run inference directly inside a web browser.
Step by step
- 1
Install @huggingface/kernels via npm
- 2
Check the browser for WebGPU support
- 3
Call getKernel with a Hub repository ID
- 4
Run the loaded kernel on the GPU
Hugging Face's WebAI team has released @huggingface/kernels, a new JavaScript library for loading and running optimized kernels β small GPU programs that each carry out one machine-learning operation β so AI models can run inference (generating output from a trained model) directly inside a web browser. Alongside it, the company published an initial set of 207 kernels at huggingface.co/webgpu-kernels under the Apache-2.0 open-source license.
When a model runs in a browser, it becomes a sequence of GPU operations such as matrix multiplications, normalizations, convolutions, attention calculations and quantization steps. WebGPU is a browser technology that gives web pages access to a device's GPU, while the language used to write the shaders that carry them out is called WGSL. Two shaders can produce identical output yet run at different speeds on different devices, and the fastest choice can change with the input shape, device and browser.
Each kernel is published as its own versioned repository containing a manifest that defines its inputs, outputs, attributes and supported data types, along with correctness test cases, benchmark cases and the WGSL shader templates. As an example, Hugging Face points to ai.onnx.Add, a kernel that performs elementwise addition β used in operations such as residual connections and adding a bias β whose repository documents its inputs, output shape and data types.
Hugging Face is also launching Fleet, an in-browser tool that benchmarks and tests the kernels on a visitor's hardware. With a user's consent, each run can add evidence that helps the company find failures such as incorrect results or slow cases, and contribute performance data from devices it could not otherwise test in-house.
Developers can install the library with the command npm install @huggingface/kernels@preview. Using it requires a browser that supports WebGPU, which a page can check in JavaScript with the line "gpu" in navigator, and a kernel is loaded by calling getKernel with a Hub repository ID and a version number.
Terms explained
The story so far
- OpenAI Says Its Own AI Agents Were Trained to Cheat Before They Hacked Hugging Face
- Open ASR Leaderboard Adds Its First Indian-Language Speech Recognition Test
- Tencent Releases Open-Source Hy4 Preview AI Model With 770 Billion Parameters
- How an MIT Research Project Became the Julia Programming Language
- Hugging Face Releases @huggingface/kernels, a Library of 207 WebGPU Kernels for Browser AI
