← Open Source

Build compute kernels and load them from the Hub.

InfrastructureKernelsPython
Momentum
+0stars in 24 hours0.0%
804
Stars
151
Forks
+8
This week
49
Contributors
Created 2024-11-29 · Updated 2026-12-04 · #17331 today
Top developers
README

kernels


The Kernel Hub allows Python libraries and applications to load compute kernels directly from the Hub. To support this kind of dynamic loading, Hub kernels differ from traditional Python kernel packages in that they are made to be:

  • Portable: a kernel can be loaded from paths outside PYTHONPATH.
  • Unique: multiple versions of the same kernel can be loaded in the same Python process.
  • Compatible: kernels must support all recent versions of Python and the different PyTorch build configurations (various CUDA versions and C++ ABIs). Furthermore, older C library versions must be supported.

Components

  • You can load kernels from the Hub using the kernels Python package.
  • If you are a kernel author, you can build your kernels with kernel-builder.
  • Hugging Face maintains a set of kernels in kernels-community.

🚀 Quick Start

Install the kernels Python package with pip (requires torch>=2.5 and CUDA):

pip install kernels

Here is how you would use the activation kernels from the Hugging Face Hub:

import torch

from kernels import get_kernel

# Download optimized kernels from the Hugging Face hub
activation = get_kernel("kernels-community/activation", version=1)

# Random tensor
x = torch.randn((10, 10), dtype=torch.float16, device="cuda")

# Run the kernel
y = torch.empty_like(x)
activation.gelu_fast(y, x)

print(y)

Browse available kernels at huggingface.co/kernels.

🎯 Hardware Support

The kernel-builder component of the project supports a number of hardware in different tiers:

Hardware Kernels Support Kernel-Builder Support Kernels Validated in CI Tier
CUDA ✓ ✓ ✓ 1
CPU ✓ ✓ ✓ 1
ROCm ✓ ✓ ✓ 1
Metal ✓ ✓ ✓ 1
XPU ✓ ✓ ✗ 2
TPU ✓ ✓ ✗ 2
Huawei NPU ✓ ✗ ✗ 3
Neuron ✓ x x 3

Warning

Neuron support is experimental and packages are not public yet. TPU support is is experimental.

📚 Documentation

Read the documentation of kernels and kernel-builder.

Nearby in the ranking
Similar items

AI Rank for iPhone

Follow AI model rankings

Download on the App Store