Kernels documentation

Kernels CLI Reference

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

Kernels CLI Reference

The kernels CLI provides commands for managing compute kernels.

Commands

Command Description
init Initialize a new kernel project from template
upload Upload kernels to the Hub
benchmark Run benchmark results for a kernel
check Check a kernel for compliance
versions Show kernel versions
generate-readme Generate README snippets for a kernel’s public functions
lock Lock kernel revisions
download Download locked kernels
create-and-upload-card Create and upload a model card for a kernel
skills Add skills for AI coding assistants

Quick Start

Create a new kernel project

kernels init my-username/my-kernel
cd my-kernel

Build and test locally

cachix use huggingface
nix run -L --max-jobs 1 --cores 8 .#build-and-copy
uv run example.py

Upload to the Hub

kernels upload ./build --repo-id my-username/my-kernel

Use kernels in your project

Directly from the Hub

import torch

from kernels import get_kernel

# Download optimized kernels from the Hugging Face hub
my_kernel = get_kernel("my-username/my-kernel", version=1)

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

# Run the kernel
y = torch.empty_like(x)
my_kernel.my_kernel_function(y, x)

print(y)

or

Locked and downloaded

Add to pyproject.toml:

[tool.kernels.dependencies]
"my-username/my-kernel" = "1"

Then lock and download:

kernels lock .
kernels download .

See help

kernels --help
Update on GitHub