Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name: Lints
on: [push, pull_request]

env:
RUFF_VERSION: "0.15.10"
GRIFFE_VERSION: "1.15.0"

jobs:
lint:
name: Run lints
Expand All @@ -10,12 +15,12 @@ jobs:
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3
with:
src: kernels
version: "0.15.10"
version: ${{ env.RUFF_VERSION }}
- name: Run ruff format check
uses: astral-sh/ruff-action@4919ec5cf1f49eff0871dbcea0da843445b837e6 # v3
with:
src: kernels
version: "0.15.10"
version: ${{ env.RUFF_VERSION }}
args: format --check

griffe:
Expand All @@ -32,7 +37,7 @@ jobs:
with:
python-version: "3.12"
- name: Check for breaking changes
run: uvx griffe check kernels --search kernels/src -a main
run: uvx griffe==${{ env.GRIFFE_VERSION }} check kernels --search kernels/src -a main

validate-dependencies:
name: Validate python_depends.json
Expand Down
9 changes: 0 additions & 9 deletions .github/workflows/test_kernels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,6 @@ jobs:
uv pip install einops nvidia-cutlass-dsl
uv run pytest tests/test_deps.py

- name: Run hub-ci upload tests
working-directory: ./kernels
env:
HF_HUB_DOWNLOAD_TIMEOUT: 60
HF_ENDPOINT: https://hub-ci.huggingface.co
HF_TOKEN: ${{ secrets.HF_HUB_CI_TOKEN }}
run: |
uv run pytest --token -m "is_staging_test" tests/
if: matrix.python-version == '3.10' && matrix.torch-version == '2.9.0'

- name: Check kernel check
working-directory: ./kernels
Expand Down
1 change: 0 additions & 1 deletion kernels/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ markers =
xpu_only: marks tests that should only run on hosts with Intel XPUs
npu_only: marks tests that should only run on Ascend NPUs
token: enable tests that require a write token
is_staging_test: Marks tests that should only run on a staging environment
73 changes: 17 additions & 56 deletions kernels/src/kernels/_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import warnings

from huggingface_hub.hf_api import GitRefInfo
from packaging.specifiers import SpecifierSet
from packaging.version import InvalidVersion, Version

logger = logging.getLogger(__name__)

Expand All @@ -26,72 +24,35 @@ def _get_available_versions(repo_id: str) -> dict[int, GitRefInfo]:
return versions


def _get_available_versions_old(repo_id: str) -> dict[Version, GitRefInfo]:
def resolve_version_spec_as_ref(repo_id: str, version_spec: int) -> GitRefInfo:
"""
Get kernel versions that are available in the repository.

This is for the old tag-based versioning scheme.
"""
from kernels.utils import _get_hf_api

versions = {}
for tag in _get_hf_api().list_repo_refs(repo_id, repo_type="kernel").tags:
if not tag.name.startswith("v"):
continue
try:
versions[Version(tag.name[1:])] = tag
except InvalidVersion:
continue

return versions


def resolve_version_spec_as_ref(repo_id: str, version_spec: int | str) -> GitRefInfo:
Get the ref for a kernel with the given version.
"""
Get the ref for a kernel with the given version spec.
versions = _get_available_versions(repo_id)

The version specifier can be any valid Python version specifier:
https://packaging.python.org/en/latest/specifications/version-specifiers/#version-specifiers
"""
if isinstance(version_spec, int):
versions = _get_available_versions(repo_id)

ref = versions.get(version_spec, None)
if ref is None:
raise ValueError(
f"Version {version_spec} not found, available versions: {', '.join(sorted(str(v) for v in versions.keys()))}"
)

latest_version = max(versions.keys())
if version_spec < latest_version:
logger.warning(
"You are using version %d of '%s', but version %d is available.",
version_spec,
repo_id,
latest_version,
)

return ref
else:
warnings.warn(
"""Version specifiers are deprecated, support will be removed in a future `kernels` version.
For more information on migrating to versions, see: https://huggingface.co/docs/kernels/migration"""
ref = versions.get(version_spec, None)
if ref is None:
raise ValueError(
f"Version {version_spec} not found, available versions: {', '.join(sorted(str(v) for v in versions.keys()))}"
)
versions_old = _get_available_versions_old(repo_id)
requirement = SpecifierSet(version_spec)
accepted_versions = sorted(requirement.filter(versions_old.keys()))

if len(accepted_versions) == 0:
raise ValueError(f"No version of `{repo_id}` satisfies requirement: {version_spec}")
latest_version = max(versions.keys())
if version_spec < latest_version:
logger.warning(
"You are using version %d of '%s', but version %d is available.",
version_spec,
repo_id,
latest_version,
)

return versions_old[accepted_versions[-1]]
return ref


def select_revision_or_version(
repo_id: str,
*,
revision: str | None,
version: int | str | None,
version: int | None,
) -> str:
if revision is not None and version is not None:
raise ValueError("Only one of `revision` or `version` must be specified.")
Expand Down
52 changes: 0 additions & 52 deletions kernels/src/kernels/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import sys
from pathlib import Path

from kernels.cli.upload import upload_kernels_dir
from kernels.cli.versions import print_kernel_versions
from kernels.compat import tomllib
from kernels.lockfile import KernelLock, get_kernel_locks
Expand Down Expand Up @@ -56,34 +55,6 @@ def main():
versions_parser.add_argument("repo_id", type=str, help="The kernel repo ID")
versions_parser.set_defaults(func=kernel_versions)

upload_parser = subparsers.add_parser(
"upload",
help="(Deprecated) Upload kernels to the Hub. Use `kernel-builder upload` instead.",
)
upload_parser.add_argument(
"kernel_dir",
type=Path,
help="Directory of the kernel build",
)
upload_parser.add_argument(
"--repo-id",
type=str,
required=True,
help="Repository ID to use to upload to the Hugging Face Hub",
)
upload_parser.add_argument(
"--branch",
type=str,
default=None,
help="If set, the upload will be made to a particular branch of the provided `repo-id`.",
)
upload_parser.add_argument(
"--private",
action="store_true",
help="If the repository should be private.",
)
upload_parser.set_defaults(func=upload_kernels)

lock_parser = subparsers.add_parser("lock", help="Lock kernel revisions")
lock_parser.add_argument(
"project_dir",
Expand Down Expand Up @@ -190,29 +161,6 @@ def lock_kernels(args):
json.dump(all_locks, f, cls=_JSONEncoder, indent=2)


def upload_kernels(args):
import warnings

warnings.warn(
"`kernels upload` is deprecated and will be removed in version 0.14. "
"Please use `kernel-builder upload` instead.",
DeprecationWarning,
stacklevel=1,
)
# Also print to stderr for visibility in CLI usage
print(
"Warning: `kernels upload` is deprecated and will be removed in version 0.14.\n"
"Please use `kernel-builder upload` instead.\n",
file=sys.stderr,
)
upload_kernels_dir(
Path(args.kernel_dir).resolve(),
repo_id=args.repo_id,
branch=args.branch,
private=args.private,
)


class _JSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o):
Expand Down
147 changes: 0 additions & 147 deletions kernels/src/kernels/cli/upload.py

This file was deleted.

7 changes: 3 additions & 4 deletions kernels/src/kernels/layer/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ class FuncRepository:
The name of the function within the kernel repository.
revision (`str`, *optional*, defaults to `"main"`):
The specific revision (branch, tag, or commit) to download. Cannot be used together with `version`.
version (`int|str`, *optional*):
The kernel version to download as an integer. The `str` variant is deprecated and will be
removed in a future release. Cannot be used together with `revision`.
version (`int`, *optional*):
The kernel version to download. Cannot be used together with `revision`.

Example:
```python
Expand All @@ -64,7 +63,7 @@ def __init__(
*,
func_name: str,
revision: str | None = None,
version: int | str | None = None,
version: int | None = None,
):
if revision is not None and version is not None:
raise ValueError("Either a revision or a version must be specified, not both.")
Expand Down
Loading
Loading