mrkeyoor.com_
Wed 02 Sept 03:10 UTC
Open Source7 min read

Hugging Face's 207 WebGPU Kernels Hit 2.57x in M4 Tests

Hugging Face has released 207 versioned WebGPU operations for browser AI. Its M4 results look strong, but exclude setup costs and full-model performance.

Hugging Face's browser-AI release comes with a number that sounds like a framework benchmark: 2.57 times faster than ONNX Runtime Web by geometric mean. The result is narrower and more useful than that slogan. It covers GPU time for 809 matching, reliably timed operator cases on one Apple M4, drawn from 1,756 attempted cases. What shipped on September 1 is a collection of 207 versioned WebGPU operations, giving JavaScript developers individual building blocks for local inference rather than a new model or a finished model runner. Hugging Face published the methods and the limits alongside the release.

The software arrives as @huggingface/kernels, a JavaScript loader, and an Apache 2.0 collection on the Hugging Face Hub. The npm package is currently 0.0.1-preview.1 under the preview tag. That version label matters for anyone considering production use: the code is public and installable, while the package is still plainly identified as a preview.

A kernel is now a package

The consequential design choice is the repository boundary. Hugging Face is publishing each operation with a manifest, metadata, correctness cases, benchmark cases and parameterized WGSL shader templates. The release post says the manifest defines the inputs, outputs, attributes, type constraints and shape rules. Metadata records the kernel identifier, digests and provenance. Tests and tuning cases travel with the implementation instead of living in a separate benchmark project.

Consider elementwise addition. The public ai.onnx.Add kernel card describes multidirectional broadcasting, accepted types and the output contract. Its variants cover equal shapes, vectorized broadcasting, scalar processing and general broadcasting. An application still asks for Add through one interface; the runtime can choose a shader that fits the shape and device. This is a practical split between what the operation promises and how a GPU happens to execute it.

That split also makes review more concrete. A developer can inspect an operation's expected results before reading its shader, reproduce the supplied cases, then refer to a published version. Hugging Face says the repositories may also serve as reference implementations for custom WebGPU work. With Apache 2.0 licensing recorded on the kernel card, teams can study and adapt the implementation under a familiar open-source license.

The JavaScript path is deliberately small

Installation uses the npm package's preview tag:

npm install @huggingface/kernels@preview

The loader then takes a Hub repository ID and a contract version. Hugging Face's documented Add example reduces the call to a typed array and tensor shape:

import { getKernel } from "@huggingface/kernels";

const add = await getKernel("webgpu-kernels/ai.onnx.Add", { version: 1 });
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 manifest lets the loader derive the broadcast output shape and allocate the result. In this tiny example, dispatching work to a GPU costs more than adding six values, a limitation Hugging Face states directly. The same calling pattern applies to heavier operations such as matrix multiplication, where shader selection has more room to affect runtime. The version: 1 value refers to the JavaScript-facing kernel contract; it is separate from an ONNX opset, an operator's since_version or a model revision. That separation is part of the release's compatibility model.

A browser must expose WebGPU before any of this runs. The package documentation recommends checking "gpu" in navigator, and the Add card links to WebGPU compatibility information. Availability can depend on the browser, operating system, GPU and driver. A fallback path remains necessary for products that cannot control the user's device.

Reading the M4 numbers

Hugging Face compared its collection with ONNX Runtime Web 1.30.0-dev.20260826-b1f76d586a on an Apple M4 GPU. Of 1,756 starting cases across the 207 operations, it retained 809 cases where both sides returned matching output and produced reliable timing. Within that subset, the Hugging Face kernels recorded 629 wins, 176 losses and four ties. The geometric-mean speedup was 2.57x; the median was 1.90x. The company published these counts with the benchmark.

The published comparison shows how uneven kernel work can be:

Operation Cases Hugging Face ORT WebGPU Reported 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

These are operation-level measurements on the M4, so the 1.14x MatMul result may be more relevant to many model workloads than the larger Add figure. The mix of tensor shapes and operations in a specific model will decide how much of the reported gain survives once the graph runs as a whole.

The 947 cases outside the comparison deserve equal attention. Hugging Face says it excluded cases that lacked both matching output and reliable timing, but it does not divide the remainder into correctness mismatches and timing problems. The published 2.57x figure therefore describes the eligible subset, not all attempted tests. That is enough to establish promising operator performance on the tested M4, though it cannot establish a collection-wide result for other hardware. The methodology provides the exact inclusion rule.

Two outliers explain why a geometric mean is useful here. A bilinear Einsum case with size 4096 ran in 0.136 milliseconds in the Hugging Face test and 1,396 milliseconds in ORT WebGPU, a difference above 10,000x. A row-wise CumSum over [256, 4096] was reported at 0.016 milliseconds against 4.784 milliseconds, or 301x. Hugging Face calls these unusual slow-path cases and warns readers against treating them as typical gains. Both outliers are disclosed in the benchmark notes.

The timer covered GPU work only. It left out loading the kernel, session creation, input upload, shader compilation and reading output back. Very short jobs can also be distorted by cache effects. A web application experiences those omitted costs, and the release has no end-to-end model result yet. The authors explicitly frame the data as an operator comparison, which is the sound way to read it.

Fleet addresses hardware variance

A fast shader on an M4 may behave differently on an integrated Windows GPU or a mobile device. Workgroup size, memory access, vectorization and supported data types all change the result; browser and driver behavior add another layer. Hugging Face's answer is Fleet, an in-browser suite that runs correctness checks and timing cases on the visitor's own WebGPU device.

With consent, Fleet sends what Hugging Face describes as private performance and correctness evidence. The stated purpose is to find wrong results, unusually slow cases and device-specific variant choices that a conventional lab would miss. The release post does not document the submitted schema or retention terms, so an organization with strict data rules should inspect the tool before contributing a run. Local results are still useful even when a team chooses not to upload them.

Crowdsourced measurements could improve selection rules because the package already supports multiple implementations behind one contract. They could also reveal where the M4 numbers fail to transfer. Fleet will be most informative when results cover enough browser, driver and GPU combinations to separate a generally faster kernel from one tuned closely to Apple's hardware. The Fleet page currently requires JavaScript and a WebGPU-enabled browser.

The package boundary brings operational work

Fetching a kernel from the Hub creates a supply-chain and deployment boundary that teams must account for. The repositories include digests and provenance metadata, and the loader requests a named repository plus a contract version. A production application will still need a policy for pinning artifacts, caching them, handling an unavailable Hub and testing updates before rollout. Those concerns follow directly from the remote, versioned loading model; the preview package does not erase them.

Hugging Face says it is working with the ONNX Runtime team to upstream the improvements. That detail makes the launch more than a head-to-head benchmark: successful kernels may reach applications through ONNX Runtime Web even if developers never call getKernel themselves. The release announcement gives no merge schedule, so upstream commits and release notes will be stronger evidence than the stated intent.

The next useful results are full-model latency, memory use and first-run cost on several GPU families. Package stability matters too: the current 0.0.1-preview.1 release signals that interface changes are still plausible. Watch whether higher-level Hugging Face tooling begins selecting these kernels automatically, how many of the 947 excluded comparison cases become usable, and which changes land upstream in ONNX Runtime. Until those numbers arrive, the release is best understood as a well-instrumented operator layer with strong M4 results, not a promise that every browser model will run 2.57 times faster.

We reviewed this

  1. browser — our honest review
  2. framework — our honest review

Sources

  1. Introducing @huggingface/kernels: 200+ WebGPU Kernels for Local AI
  2. @huggingface/kernels on npm
  3. webgpu-kernels/ai.onnx.Add kernel card
  4. Fleet GPU Trials