diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3a9633..f8185ab 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Test hf-kernels +name: Test kernels on: push: diff --git a/README.md b/README.md index f2e1605..b7baab1 100644 --- a/README.md +++ b/README.md @@ -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") ``` diff --git a/docker/Dockerfile.reference b/docker/Dockerfile.reference index 0d34096..1f9581d 100644 --- a/docker/Dockerfile.reference +++ b/docker/Dockerfile.reference @@ -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"] diff --git a/examples/basic.py b/examples/basic.py index 8c8f32b..b7c423d 100644 --- a/examples/basic.py +++ b/examples/basic.py @@ -1,6 +1,6 @@ import torch -from hf_kernels import get_kernel +from kernels import get_kernel print("Starting examples/basic.py demo") diff --git a/pyproject.toml b/pyproject.toml index 44987d2..203438a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] -name = "hf-kernels" -version = "0.1.6" +name = "kernels" +version = "0.1.7" description = "Download cuda kernels" authors = [ { name = "OlivierDehaene", email = "olivier@huggingface.co" }, @@ -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"] diff --git a/src/hf_kernels/__init__.py b/src/hf_kernels/__init__.py deleted file mode 100644 index 16c1335..0000000 --- a/src/hf_kernels/__init__.py +++ /dev/null @@ -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"] diff --git a/src/kernels/__init__.py b/src/kernels/__init__.py new file mode 100644 index 0000000..c75e040 --- /dev/null +++ b/src/kernels/__init__.py @@ -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"] diff --git a/src/hf_kernels/build.py b/src/kernels/build.py similarity index 96% rename from src/hf_kernels/build.py rename to src/kernels/build.py index 69952f9..8341931 100644 --- a/src/hf_kernels/build.py +++ b/src/kernels/build.py @@ -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") diff --git a/src/hf_kernels/cli.py b/src/kernels/cli.py similarity index 82% rename from src/hf_kernels/cli.py rename to src/kernels/cli.py index f52db99..8c4d35d 100644 --- a/src/hf_kernels/cli.py +++ b/src/kernels/cli.py @@ -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) diff --git a/src/hf_kernels/compat.py b/src/kernels/compat.py similarity index 100% rename from src/hf_kernels/compat.py rename to src/kernels/compat.py diff --git a/src/hf_kernels/lockfile.py b/src/kernels/lockfile.py similarity index 98% rename from src/hf_kernels/lockfile.py rename to src/kernels/lockfile.py index d0cb2e1..4d84237 100644 --- a/src/hf_kernels/lockfile.py +++ b/src/kernels/lockfile.py @@ -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. diff --git a/src/hf_kernels/utils.py b/src/kernels/utils.py similarity index 98% rename from src/hf_kernels/utils.py rename to src/kernels/utils.py index 331ec6d..2ae6306 100644 --- a/src/hf_kernels/utils.py +++ b/src/kernels/utils.py @@ -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) diff --git a/tests/hash_validation/hf-kernels.lock b/tests/hash_validation/kernels.lock similarity index 100% rename from tests/hash_validation/hf-kernels.lock rename to tests/hash_validation/kernels.lock diff --git a/tests/test_basic.py b/tests/test_basic.py index 411f7b6..4afe126 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -1,6 +1,6 @@ import pytest import torch -from hf_kernels import get_kernel +from kernels import get_kernel @pytest.fixture diff --git a/tests/test_benchmarks.py b/tests/test_benchmarks.py index ed8568d..8ba0473 100644 --- a/tests/test_benchmarks.py +++ b/tests/test_benchmarks.py @@ -1,6 +1,6 @@ import pytest import torch -from hf_kernels import get_kernel +from kernels import get_kernel @pytest.fixture diff --git a/tests/test_hash_validation.py b/tests/test_hash_validation.py index e88931f..31d162f 100644 --- a/tests/test_hash_validation.py +++ b/tests/test_hash_validation.py @@ -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.