Skip to main content

hf-kernels

Make sure you have torch==2.5.1+cu124 installed.

import torch

from hf_kernels import get_kernel

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

# 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)

Docker Reference

build and run the reference example/basic.py in a Docker container with the following commands:

docker build --platform linux/amd64 -t kernels-reference -f docker/Dockerfile.reference .
docker run --gpus all -it --rm -e HF_TOKEN=$HF_TOKEN kernels-reference

Locking kernel versions

Projects that use setuptools can lock the kernel versions that should be used. First specify the accepted versions in pyproject.toml and make sure that hf-kernels is a build dependency:

[build-system]
requires = ["hf-kernels", "setuptools"]
build-backend = "setuptools.build_meta"

[tool.kernels.dependencies]
"kernels-community/activation" = ">=0.0.1"

Then run hf-kernel lock . in the project directory. This generates a kernels.lock file with the locked revisions. The locked revision will be used when loading a kernel with get_locked_kernel:

from hf_kernels import get_locked_kernel

activation = get_locked_kernel("kernels-community/activation")

Note: the lock file is included in the package metadata, so it will only be visible to hf-kernels after doing an (editable or regular) installation of your project.

Pre-downloading locked kernels

Locked kernels can be pre-downloaded by running hf-kernel download . in your project directory. This will download the kernels to your local Hugging Face Hub cache.

The pre-downloaded kernels are used by the get_locked_kernel function. get_locked_kernel will download a kernel when it is not pre-downloaded. If you want kernel loading to error when a kernel is not pre-downloaded, you can use the load_kernel function instead:

```python
from hf_kernels import load_kernel

activation = load_kernel("kernels-community/activation")

Metadata

Release files for hf-kernels 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for hf-kernels 0.1.6
File Size Uploaded Provenance Actions
hf_kernels-0.1.6.tar.gz 8.7 kB Without provenance Details for hf_kernels-0.1.6.tar.gz

Release files / hf_kernels-0.1.6.tar.gz

Download URL hf_kernels-0.1.6.tar.gz
Size 8.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5effee5046552ce226ff86d3870a799f4ecae399bcb2beb4046c28c2dd736d2f
BLAKE2b-256 checksum
How to use checksums
01fe5aa3ea1b66bcc7d81aff19683ea04d4a9cd414c8d4ff05b150fc1f196ccd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.16

Security for hf-kernels 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page