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 kernelsVerified import paths — ran on the pinned version, not inferred.
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.
Always pass the `version` argument to `get_kernel()` (e.g., `get_kernel('org/name', version=1)`). Consult kernel documentation for available versions.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.
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.
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.
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.
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.