Registry / ai-ml / kernels

kernels

JSON →
library0.16.1pypypi✓ verified 22d ago

The `kernels` Python library, currently at version 0.13.0, enables other Python libraries and applications to dynamically load optimized compute kernels directly from the Hugging Face Kernel Hub. These kernels are designed to be portable, unique (multiple versions can coexist), and compatible across various Python and PyTorch configurations. The library supports a rapid release cycle, with frequent updates to add new features and improve performance.

pip install kernels
INSTALL
IMPORT
SIG · KERNELS
K
kernels
ai-mlpythonv0.16.1
Install
41.3s avg
Import
1720ms
Disk
4813MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.16.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
1/2 runs
✓ 47.4s
py 3.11
1/2 runs
✓ 43.7s
py 3.12
1/2 runs
✓ 38.35s
py 3.13
1/2 runs
✓ 35.65s
py 3.9
1/2 runs
1/2 runs
4813MB installed
● package 4813MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_kernel
from kernels import get_kernel
This is the primary function for downloading and accessing kernels from the Hub.

This quickstart demonstrates how to fetch a pre-optimized activation kernel from the Hugging Face Hub and execute it using PyTorch. It highlights the importance of specifying the kernel version for stability and requires a CUDA-enabled environment for GPU execution.

import torch from kernels import get_kernel import os # NOTE: For this example to run, you need PyTorch installed with CUDA support # and a CUDA-enabled GPU. This example might fail on CPU-only setups. # Ensure 'torch' is installed: pip install torch # Download an optimized activation kernel from the Hugging Face Hub # Specifying the version is important to avoid future breaking changes (see warnings) try: activation = get_kernel("kernels-community/activation", version=1) print("Kernel downloaded successfully!") # Example usage: Generate a random tensor on a CUDA device if torch.cuda.is_available(): x = torch.randn((10, 10), dtype=torch.float16, device="cuda") y = torch.empty_like(x) # Run the kernel (e.g., gelu_fast) activation.gelu_fast(y, x) print("Kernel executed successfully on CUDA!") # print(y) else: print("CUDA is not available. Skipping kernel execution on GPU.") except Exception as e: print(f"An error occurred during quickstart: {e}") print("Please ensure 'torch' is installed with CUDA and you have a compatible GPU.")
Debug
Known issues
breakingCalling `get_kernel()` without specifying a `version` argument is deprecated in `kernels 0.12` and will become an error in `0.14` (except for local kernels).
fix
Always pass the `version` argument to `get_kernel()` (e.g., `get_kernel('org/name', version=1)`). Consult kernel documentation for available versions.
affects: >=0.12
deprecatedSupport for 'universal kernels' is being phased out in favor of 'noarch kernels'. Future versions will emit deprecation warnings, eventually leading to removal.
fix
Kernel authors should migrate to building 'noarch kernels'. Users generally won't need to change their code, but should be aware of potential changes in kernel availability or performance if relying on older 'universal' builds.
affects: Future releases (after 0.13)
gotchaMost optimized kernels from the Hugging Face Hub (especially `kernels-community`) are designed for GPU acceleration and require a compatible PyTorch installation (e.g., `torch>=2.5` with CUDA).
fix
Ensure `torch` is installed with CUDA support (`pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118` or similar for your CUDA version) and that you have a functional GPU environment. Attempting to use GPU-only kernels on a CPU-only setup will result in errors.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'kernels'
The 'kernels' Python library is not installed or is not accessible in the current Python environment.
fix
Run `pip install kernels` or `pip install -U kernels` in your terminal to install or upgrade the library. If using a virtual environment, ensure it is activated.
An error happened while trying to locate the files on the Hub and we cannot find the appropriate snapshot folder for the specified revision on the local disk. Please check your internet connection and try again.
The 'kernels' library failed to download or locate a specified compute kernel from the Hugging Face Kernel Hub. This can be due to network issues, an incorrect kernel identifier or revision, or the kernel not being publicly available/trusted.
fix
Verify your internet connection and firewall settings. Double-check the kernel's identifier and revision for typos. If loading from a non-community repository, you might need to explicitly allow it by passing `allow_all_kernels=True` to the loading function, similar to `trust_remote_code` in other Hugging Face libraries.
RuntimeError: CUDA error: no kernel image is available for execution on the device
A compute kernel loaded by the 'kernels' library is incompatible with your GPU's architecture or the installed PyTorch/CUDA version. This means the pre-compiled kernel code required for your specific device is either missing or mismatched.
fix
Ensure your PyTorch and CUDA versions are compatible with your NVIDIA GPU. Update your GPU drivers to the latest version. If the issue persists, consider re-installing PyTorch to match your CUDA version, or if using a very new GPU, you may need to compile PyTorch from source with support for your specific architecture.
Upgrade
Version history
0.16.1latest on PyPI · released Aug 24, 2026
Audit
Dependencies
torchrequiredRequired for most compute kernels, especially those leveraging GPU acceleration (e.g., CUDA).
CUDAoptionalRequired for GPU-accelerated kernels. Not a Python package, but a system dependency.
Agent activity
7 hits · last 30 days
node
6
Resources
kernels — pip install kernels · libregistry