mirror of
https://github.com/huggingface/kernels.git
synced 2025-10-20 12:33:46 +08:00
Revert "hf-kernels -> kernels"
This reverts commit 386c2a104ef4c251912e63bfcdbfaa588dc09605.
This commit is contained in:
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@ -1,4 +1,4 @@
|
||||
name: Test kernels
|
||||
name: Test hf-kernels
|
||||
|
||||
on:
|
||||
push:
|
||||
|
22
README.md
22
README.md
@ -1,4 +1,4 @@
|
||||
# kernels
|
||||
# hf-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 kernels import get_kernel
|
||||
from hf_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 `kernels`, we recommend installing from the pypi package:
|
||||
To install `hf-kernels`, we recommend installing from the pypi package:
|
||||
|
||||
```bash
|
||||
pip install kernels
|
||||
pip install hf-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 `kernels` is a build dependency:
|
||||
sure that `hf-kernels` is a build dependency:
|
||||
|
||||
```toml
|
||||
[build-system]
|
||||
requires = ["kernels", "setuptools"]
|
||||
requires = ["hf-kernels", "setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[tool.kernels.dependencies]
|
||||
"kernels-community/activation" = ">=0.0.1"
|
||||
```
|
||||
|
||||
Then run `kernel lock .` in the project directory. This generates a `kernels.lock` file with
|
||||
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`:
|
||||
|
||||
```python
|
||||
from kernels import 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 `kernels` after doing an (editable or regular) installation of your project.
|
||||
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 `kernel download .` in your
|
||||
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.
|
||||
|
||||
@ -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 kernels import load_kernel
|
||||
from hf_kernels import load_kernel
|
||||
|
||||
activation = load_kernel("kernels-community/activation")
|
||||
```
|
||||
|
@ -31,13 +31,13 @@ WORKDIR /app/kernel-test
|
||||
# install python depdencies
|
||||
RUN uv add torch==2.5.0 numpy
|
||||
|
||||
# copy kernels lib
|
||||
COPY src ./kernels/src
|
||||
COPY pyproject.toml ./kernels/pyproject.toml
|
||||
COPY README.md ./kernels/README.md
|
||||
# copy hf-kernels lib
|
||||
COPY src ./hf-kernels/src
|
||||
COPY pyproject.toml ./hf-kernels/pyproject.toml
|
||||
COPY README.md ./hf-kernels/README.md
|
||||
|
||||
# install library
|
||||
RUN uv pip install -e kernels
|
||||
RUN uv pip install -e hf-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", "kernels"]
|
||||
# CMD ["ls", "hf-kernels"]
|
||||
|
@ -1,6 +1,6 @@
|
||||
import torch
|
||||
|
||||
from kernels import get_kernel
|
||||
from hf_kernels import get_kernel
|
||||
|
||||
print("Starting examples/basic.py demo")
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
[project]
|
||||
name = "kernels"
|
||||
name = "hf-kernels"
|
||||
version = "0.1.6"
|
||||
description = "Download cuda kernels"
|
||||
authors = [
|
||||
@ -29,12 +29,12 @@ dev = [
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
kernels = "kernels.cli:main"
|
||||
hf-kernels = "hf_kernels.cli:main"
|
||||
|
||||
[project.entry-points."egg_info.writers"]
|
||||
"kernels.lock" = "kernels.lockfile:write_egg_lockfile"
|
||||
"hf-kernels.lock" = "hf_kernels.lockfile:write_egg_lockfile"
|
||||
|
||||
#[build-system]
|
||||
#requires = ["torch", "huggingface_hub", "numpy", "tomli;python_version<='3.10'"]
|
||||
#build-backend = "kernels.build"
|
||||
#build-backend = "hf_kernels.build"
|
||||
#backend-path = ["src"]
|
||||
|
3
src/hf_kernels/__init__.py
Normal file
3
src/hf_kernels/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from hf_kernels.utils import get_kernel, install_kernel, load_kernel, get_locked_kernel
|
||||
|
||||
__all__ = ["get_kernel", "get_locked_kernel", "load_kernel", "install_kernel"]
|
@ -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 kernels.compat import tomllib
|
||||
from hf_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("kernels", {}).get("dependencies", {}).items()
|
||||
data.get("tool", {}).get("hf-kernels", {}).get("dependencies", {}).items()
|
||||
):
|
||||
from kernels.utils import install_kernel
|
||||
from hf_kernels.utils import install_kernel
|
||||
|
||||
install_kernel(kernel, revision="main")
|
||||
uv_bin = shutil.which("uv")
|
@ -4,14 +4,14 @@ import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="kernel", description="Manage compute kernels"
|
||||
prog="hf-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 / "kernels.lock"
|
||||
lock_path = args.project_dir / "hf-kernels.lock"
|
||||
|
||||
if not lock_path.exists():
|
||||
print(f"No kernels.lock file found in: {args.project_dir}", file=sys.stderr)
|
||||
print(f"No hf-kernels.lock file found in: {args.project_dir}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
with open(args.project_dir / "kernels.lock", "r") as f:
|
||||
with open(args.project_dir / "hf-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 / "kernels.lock", "w") as f:
|
||||
with open(args.project_dir / "hf-kernels.lock", "w") as f:
|
||||
json.dump(all_locks, f, cls=_JSONEncoder, indent=2)
|
||||
|
||||
|
@ -7,7 +7,7 @@ from huggingface_hub import HfApi
|
||||
from packaging.specifiers import SpecifierSet
|
||||
from packaging.version import InvalidVersion, Version
|
||||
|
||||
from kernels.compat import tomllib
|
||||
from hf_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 / "kernels.lock"
|
||||
lock_path = cwd / "hf-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.
|
@ -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 kernels.compat import tomllib
|
||||
from kernels.lockfile import KernelLock, VariantLock
|
||||
from hf_kernels.compat import tomllib
|
||||
from hf_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("kernels.lock")
|
||||
lock_json = dist.read_text("hf-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)
|
@ -1,3 +0,0 @@
|
||||
from kernels.utils import get_kernel, install_kernel, load_kernel, get_locked_kernel
|
||||
|
||||
__all__ = ["get_kernel", "get_locked_kernel", "load_kernel", "install_kernel"]
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
import torch
|
||||
from kernels import get_kernel
|
||||
from hf_kernels import get_kernel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -1,6 +1,6 @@
|
||||
import pytest
|
||||
import torch
|
||||
from kernels import get_kernel
|
||||
from hf_kernels import get_kernel
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -1,7 +1,7 @@
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
|
||||
from kernels.cli import download_kernels
|
||||
from hf_kernels.cli import download_kernels
|
||||
|
||||
|
||||
# Mock download arguments class.
|
||||
|
Reference in New Issue
Block a user