hf-kernels -> kernels

This commit is contained in:
Lysandre
2025-02-25 15:05:38 +01:00
parent c7516b9e50
commit 386c2a104e
15 changed files with 45 additions and 45 deletions

View File

@ -1,4 +1,4 @@
name: Test hf-kernels
name: Test kernels
on:
push:

View File

@ -1,4 +1,4 @@
# hf-kernels
# kernels
The Kernel Hub allows Python libraries and applications to load compute
kernels directly from the [Hub](https://hf.co/). To support this kind
@ -21,7 +21,7 @@ Here is how you would use the [activation](https://huggingface.co/kernels-commun
```python
import torch
from hf_kernels import get_kernel
from kernels import get_kernel
# Download optimized kernels from the Hugging Face hub
activation = get_kernel("kernels-community/activation")
@ -44,10 +44,10 @@ please take a look at the following guide:
## Installation
To install `hf-kernels`, we recommend installing from the pypi package:
To install `kernels`, we recommend installing from the pypi package:
```bash
pip install hf-kernels
pip install kernels
```
You should then be able to run the script above (also in [examples/basic.py](examples/basic.py)):
@ -68,33 +68,33 @@ docker run --gpus all -it --rm -e HF_TOKEN=$HF_TOKEN kernels-reference
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:
sure that `kernels` is a build dependency:
```toml
[build-system]
requires = ["hf-kernels", "setuptools"]
requires = ["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
Then run `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`:
```python
from hf_kernels import get_locked_kernel
from 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.
to `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
Locked kernels can be pre-downloaded by running `kernel download .` in your
project directory. This will download the kernels to your local Hugging Face
Hub cache.
@ -104,7 +104,7 @@ 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
from kernels import load_kernel
activation = load_kernel("kernels-community/activation")
```

View File

@ -31,13 +31,13 @@ WORKDIR /app/kernel-test
# install python depdencies
RUN uv add torch==2.5.0 numpy
# copy hf-kernels lib
COPY src ./hf-kernels/src
COPY pyproject.toml ./hf-kernels/pyproject.toml
COPY README.md ./hf-kernels/README.md
# copy kernels lib
COPY src ./kernels/src
COPY pyproject.toml ./kernels/pyproject.toml
COPY README.md ./kernels/README.md
# install library
RUN uv pip install -e hf-kernels
RUN uv pip install -e kernels
# copy examples
COPY examples ./examples
@ -48,4 +48,4 @@ ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility
# command to run the script
CMD ["uv", "run", "examples/basic.py"]
# CMD ["ls", "hf-kernels"]
# CMD ["ls", "kernels"]

View File

@ -1,6 +1,6 @@
import torch
from hf_kernels import get_kernel
from kernels import get_kernel
print("Starting examples/basic.py demo")

View File

@ -1,5 +1,5 @@
[project]
name = "hf-kernels"
name = "kernels"
version = "0.1.6"
description = "Download cuda kernels"
authors = [
@ -29,12 +29,12 @@ dev = [
]
[project.scripts]
hf-kernels = "hf_kernels.cli:main"
kernels = "kernels.cli:main"
[project.entry-points."egg_info.writers"]
"hf-kernels.lock" = "hf_kernels.lockfile:write_egg_lockfile"
"kernels.lock" = "kernels.lockfile:write_egg_lockfile"
#[build-system]
#requires = ["torch", "huggingface_hub", "numpy", "tomli;python_version<='3.10'"]
#build-backend = "hf_kernels.build"
#build-backend = "kernels.build"
#backend-path = ["src"]

View File

@ -1,3 +0,0 @@
from hf_kernels.utils import get_kernel, install_kernel, load_kernel, get_locked_kernel
__all__ = ["get_kernel", "get_locked_kernel", "load_kernel", "install_kernel"]

3
src/kernels/__init__.py Normal file
View File

@ -0,0 +1,3 @@
from kernels.utils import get_kernel, install_kernel, load_kernel, get_locked_kernel
__all__ = ["get_kernel", "get_locked_kernel", "load_kernel", "install_kernel"]

View File

@ -16,7 +16,7 @@ don't require importing typing but then quote them so earlier Python version ign
them while IDEs and type checker can see through the quotes.
"""
from hf_kernels.compat import tomllib
from kernels.compat import tomllib
TYPE_CHECKING = False
if TYPE_CHECKING:
@ -49,9 +49,9 @@ def call(
data = tomllib.load(f)
for kernel, _ in (
data.get("tool", {}).get("hf-kernels", {}).get("dependencies", {}).items()
data.get("tool", {}).get("kernels", {}).get("dependencies", {}).items()
):
from hf_kernels.utils import install_kernel
from kernels.utils import install_kernel
install_kernel(kernel, revision="main")
uv_bin = shutil.which("uv")

View File

@ -4,14 +4,14 @@ import json
import sys
from pathlib import Path
from hf_kernels.compat import tomllib
from hf_kernels.lockfile import KernelLock, get_kernel_locks
from hf_kernels.utils import build_variant, install_kernel, install_kernel_all_variants
from kernels.compat import tomllib
from kernels.lockfile import KernelLock, get_kernel_locks
from kernels.utils import build_variant, install_kernel, install_kernel_all_variants
def main():
parser = argparse.ArgumentParser(
prog="hf-kernel", description="Manage compute kernels"
prog="kernel", description="Manage compute kernels"
)
subparsers = parser.add_subparsers(required=True)
@ -41,13 +41,13 @@ def main():
def download_kernels(args):
lock_path = args.project_dir / "hf-kernels.lock"
lock_path = args.project_dir / "kernels.lock"
if not lock_path.exists():
print(f"No hf-kernels.lock file found in: {args.project_dir}", file=sys.stderr)
print(f"No kernels.lock file found in: {args.project_dir}", file=sys.stderr)
sys.exit(1)
with open(args.project_dir / "hf-kernels.lock", "r") as f:
with open(args.project_dir / "kernels.lock", "r") as f:
lock_json = json.load(f)
all_successful = True
@ -87,7 +87,7 @@ def lock_kernels(args):
for kernel, version in kernel_versions.items():
all_locks.append(get_kernel_locks(kernel, version))
with open(args.project_dir / "hf-kernels.lock", "w") as f:
with open(args.project_dir / "kernels.lock", "w") as f:
json.dump(all_locks, f, cls=_JSONEncoder, indent=2)

View File

@ -7,7 +7,7 @@ from huggingface_hub import HfApi
from packaging.specifiers import SpecifierSet
from packaging.version import InvalidVersion, Version
from hf_kernels.compat import tomllib
from kernels.compat import tomllib
@dataclass
@ -123,7 +123,7 @@ def write_egg_lockfile(cmd, basename, filename):
if kernel_versions is None:
return
lock_path = cwd / "hf-kernels.lock"
lock_path = cwd / "kernels.lock"
if not lock_path.exists():
logging.warning(f"Lock file {lock_path} does not exist")
# Ensure that the file gets deleted in editable installs.

View File

@ -15,8 +15,8 @@ from typing import Dict, List, Optional, Tuple
from huggingface_hub import hf_hub_download, snapshot_download
from packaging.version import parse
from hf_kernels.compat import tomllib
from hf_kernels.lockfile import KernelLock, VariantLock
from kernels.compat import tomllib
from kernels.lockfile import KernelLock, VariantLock
CACHE_DIR: Optional[str] = os.environ.get("HF_KERNELS_CACHE", None)
@ -177,7 +177,7 @@ def get_locked_kernel(repo_id: str, local_files_only: bool = False):
def _get_caller_locked_kernel(repo_id: str) -> Optional[str]:
for dist in _get_caller_distributions():
lock_json = dist.read_text("hf-kernels.lock")
lock_json = dist.read_text("kernels.lock")
if lock_json is not None:
for kernel_lock_json in json.loads(lock_json):
kernel_lock = KernelLock.from_json(kernel_lock_json)

View File

@ -1,6 +1,6 @@
import pytest
import torch
from hf_kernels import get_kernel
from kernels import get_kernel
@pytest.fixture

View File

@ -1,6 +1,6 @@
import pytest
import torch
from hf_kernels import get_kernel
from kernels import get_kernel
@pytest.fixture

View File

@ -1,7 +1,7 @@
from dataclasses import dataclass
from pathlib import Path
from hf_kernels.cli import download_kernels
from kernels.cli import download_kernels
# Mock download arguments class.