Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub
by Hugging Face
Swap FlashAttention, RMSNorm and MoE layers for prebuilt Hub kernels in one line, or build and publish your own across CUDA, ROCm, Metal and CPU.
Overview
Kernels is the Hugging Face documentation for two connected tools: the kernels Python package, which loads compute kernels straight from the Hugging Face Hub, and kernel-builder, which builds, packages and uploads them. The Quickstart shows the core call, get_kernel("kernels-community/activation", version=1), and explains why Hub kernels must now be loaded with an explicit version or revision, with major versions mapped to branches such as v1. The Layers guide covers the decorator use_kernel_forward_from_hub, replace_kernel_forward_from_hub for layers you do not own, and kernelize(model, mode=Mode.INFERENCE), with TRAINING, TORCH_COMPILE and FALLBACK modes, plus kernel mappings and per-CUDA-capability registration. The kernel-builder CLI reference documents init, build, build-and-upload, check-abi and the other subcommands; builds run under Nix and target cpu, cuda, metal, rocm and xpu backends. The README groups hardware into tiers: CUDA, CPU, ROCm and Metal are validated in CI, while XPU and TPU are not. Maintained kernels live under kernels-community on the Hub, including flash-attn, triton-layer-norm, quantization and moe. The project is Apache-2.0, and the GitHub repo had commits on November 25, 2026 and a v0.19.0 release on November 23 that added MLX kernels on Apple Silicon and experimental Rust CUDA kernels. It is maintained by the Hugging Face team behind Transformers and TGI, which both use it.
At a Glance
- Topic
- ML
- Level
- Intermediate
- Format
- Documentation
- Cost
- Free
- Duration
- ~2 hours to load and kernelize a model, self-paced; building and publishing your own kernel takes longer
- Provider
- Hugging Face
- Hands-on
- Yes — code/exercises
- Certificate
- None
What You’ll Learn
- ✓Load a versioned compute kernel from the Hub with get_kernel and call its functions
- ✓Check kernel availability and variants with has_kernel, get_kernel_variants and the cache CLI
- ✓Replace a model's layer forwards with optimized Hub kernels using use_kernel_forward_from_hub
- ✓Run kernelize in inference, training or torch.compile modes and control fallback behaviour
- ✓Register kernel mappings per device and per CUDA compute capability range
- ✓Scaffold, build and upload your own kernel with kernel-builder init and build-and-upload
- ✓Target CUDA, ROCm, Metal, XPU and CPU backends from a single kernel project
- ✓Validate kernel ABI and build outputs with check-abi and check-builds before publishing
Highlights
- •Pulls a prebuilt FlashAttention-class kernel in one call, where compiling FlashAttention from source can take hours and around 96 GB of RAM (per Hugging Face's launch post)
- •Actively maintained: v0.19.0 shipped November 23, 2026 and commits landed on November 25, 2026
- •Covers both sides of the workflow, using community kernels and authoring your own with Nix-based reproducible builds
- •Used by Hugging Face's own Transformers and TGI, so the patterns match production inference stacks
- •The June 2025 launch blog predates the mandatory version argument, so follow the docs rather than older tutorials
Who It’s For
Best For
- ✓ML engineers speeding up PyTorch inference or fine-tuning without writing CUDA
- ✓Inference engineers standardizing optimized attention, norm and MoE layers across GPU types
- ✓Kernel authors who want to distribute CUDA, ROCm or Metal kernels through the Hub
- ✓Teams running models on mixed hardware, including Apple Silicon and AMD GPUs
Prerequisites
- •Working PyTorch knowledge, including nn.Module and model forward passes
- •torch 2.5 or later and a supported accelerator (CUDA per the README; other backends are tiered)
- •C++/CUDA or Triton experience and familiarity with Nix if you plan to build your own kernels
FAQ
What is Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub?
The official documentation for Hugging Face's kernels library and kernel-builder, written for PyTorch engineers who want faster training and inference without compiling CUDA code themselves. After working through it you can load versioned kernels from the Hub, swap optimized forwards into a model with kernelize, and package your own kernels for others to use.
Is Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub free?
Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub is free to access.
What level is Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub for?
Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub is aimed at a intermediate audience. Recommended background: Working PyTorch knowledge, including nn.Module and model forward passes, torch 2.5 or later and a supported accelerator (CUDA per the README; other backends are tiered), C++/CUDA or Triton experience and familiarity with Nix if you plan to build your own kernels.
How long does Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub take?
Expect roughly ~2 hours to load and kernelize a model, self-paced; building and publishing your own kernel takes longer. Most learners work through it at their own pace.
What will I learn from Kernels Documentation — Load and Build Compute Kernels from the Hugging Face Hub?
You'll learn: Load a versioned compute kernel from the Hub with get_kernel and call its functions; Check kernel availability and variants with has_kernel, get_kernel_variants and the cache CLI; Replace a model's layer forwards with optimized Hub kernels using use_kernel_forward_from_hub; Run kernelize in inference, training or torch.compile modes and control fallback behaviour; Register kernel mappings per device and per CUDA compute capability range; Scaffold, build and upload your own kernel with kernel-builder init and build-and-upload; Target CUDA, ROCm, Metal, XPU and CPU backends from a single kernel project; Validate kernel ABI and build outputs with check-abi and check-builds before publishing.
Topics
Sources
This page was written from 8 sources, 3 on domains other than huggingface.co.