Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
191a5be
feat: resolve repo type and fetch accordingly
drbh Apr 9, 2026
030145f
fix: lint and format and prefer pinning hfh commit
drbh Apr 9, 2026
5a769bc
fix: pin hub library from git commit
drbh Apr 9, 2026
7b4f823
fix: update tests to specify repo type
drbh Apr 9, 2026
95af15f
fix: bump overlay
drbh Apr 9, 2026
5baaf3e
fix: prefer the hfh release
drbh Apr 9, 2026
f9b90c9
fix: bump hf xet
drbh Apr 9, 2026
1f37cd9
fix: improve _resolve_repo_type
drbh Apr 9, 2026
5d2a465
fix: remove debug line
drbh Apr 9, 2026
2e346bf
fix: prefer repo_info in _resolve_repo_type and handle 401
drbh Apr 9, 2026
b263480
fix: expect repo type model for the kernels-test org kernels
drbh Apr 9, 2026
27a8511
fix: adjust error
drbh Apr 9, 2026
df77384
fix: adjust tests and reo type resolution
drbh Apr 9, 2026
3846877
fix: accept revision in _resolve_repo_type
drbh Apr 9, 2026
78beca0
fix: get file metadata in repo info and remove extra try
drbh Apr 9, 2026
a16847b
feat: run lock pytest as subprocess
drbh Apr 13, 2026
3e7dc01
feat: prefer locking kernel repo hashes
drbh Apr 13, 2026
4a9ea8a
fix: avoid deprecation warning for now
drbh Apr 13, 2026
6f71720
feat: make repo type optional and comment for siblings
drbh Apr 13, 2026
2ab8262
fix: remove repo_type from all public interfaces
drbh Apr 13, 2026
b26b7f6
fix: remove backward compat of model repo types
drbh Apr 14, 2026
d1722af
fix: improve error cases
drbh Apr 14, 2026
9c48e38
fix: bump lock files for kernel repos
drbh Apr 14, 2026
db72e5d
fix: avoid non version locking tests
drbh Apr 14, 2026
1a15029
fix: avoid upload changes
drbh Apr 14, 2026
e8095a9
fix: apply lints after rebase
drbh Apr 14, 2026
c7ef910
fix: adjust repo not found error regression
drbh Apr 15, 2026
ef80f07
fix: adjust repo not found error regression in layer test too
drbh Apr 15, 2026
ef46c95
fix: revert back to hfhub error until 401 resolved
drbh Apr 15, 2026
e553a8b
fix: avoid the unneeded removal of repo type
drbh Apr 15, 2026
5f5926f
feat: enforce kwargs
drbh Apr 15, 2026
9448ba3
fix: adjust for kwarg
drbh Apr 15, 2026
95a0316
fix: update test for kwarg changes
drbh Apr 15, 2026
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
4 changes: 2 additions & 2 deletions kernels/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ authors = [
]
license = { text = "Apache-2.0" }
readme = "README.md"
requires-python = ">= 3.9"
requires-python = ">= 3.10"
dependencies = [
"huggingface_hub>=1.3.0,<2.0",
"huggingface-hub>=1.10.0",
"packaging>=20.0",
"pyyaml>=6",
"tomli>=2.0; python_version<'3.11'",
Expand Down
9 changes: 6 additions & 3 deletions kernels/src/kernels/_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ def _get_available_versions(repo_id: str) -> dict[int, GitRefInfo]:
"""Get kernel versions that are available in the repository."""
from kernels.utils import _get_hf_api

refs = _get_hf_api().list_repo_refs(repo_id=repo_id, repo_type="kernel")

versions = {}
for branch in _get_hf_api().list_repo_refs(repo_id).branches:
for branch in refs.branches:
if not branch.name.startswith("v"):
continue
try:
Expand All @@ -33,7 +35,7 @@ def _get_available_versions_old(repo_id: str) -> dict[Version, GitRefInfo]:
from kernels.utils import _get_hf_api

versions = {}
for tag in _get_hf_api().list_repo_refs(repo_id).tags:
for tag in _get_hf_api().list_repo_refs(repo_id, repo_type="kernel").tags:
if not tag.name.startswith("v"):
continue
try:
Expand All @@ -46,13 +48,14 @@ def _get_available_versions_old(repo_id: str) -> dict[Version, GitRefInfo]:

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

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(
Expand Down
4 changes: 2 additions & 2 deletions kernels/src/kernels/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ def download_kernels(args):
if args.all_variants:
install_kernel_all_variants(
kernel_lock.repo_id,
kernel_lock.sha,
revision=kernel_lock.sha,
variant_locks=kernel_lock.variants,
)
else:
try:
install_kernel(
kernel_lock.repo_id,
kernel_lock.sha,
revision=kernel_lock.sha,
variant_locks=kernel_lock.variants,
)
except FileNotFoundError as e:
Expand Down
8 changes: 7 additions & 1 deletion kernels/src/kernels/cli/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@


def check_kernel(
*, macos: str, manylinux: str, python_abi: str, repo_id: str, revision: str
*,
macos: str,
manylinux: str,
python_abi: str,
repo_id: str,
revision: str,
):
variants_path = (
Path(
str(
_get_hf_api().snapshot_download(
repo_id,
repo_type="kernel",
allow_patterns=["build/*"],
cache_dir=CACHE_DIR,
revision=revision,
Expand Down
1 change: 0 additions & 1 deletion kernels/src/kernels/cli/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def _upload_build_dir(
repo_id=repo_id,
operations=list(chunk),
revision=revision,
repo_type="model",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no repo_type="kernel" here? (same above)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no repo_type="kernel" in this case since we plan to fully remove this upload file and all of the upload logic on the python cli in a following PR.

I removed repo_type="model" but realize that was unneeded - however in this case I don't think is technically changes any of the logic since if I understand correctly the default functionality is to push to model repos.

however as mentioned this will all be removed in the next PR I open since we are cleaning up deprecated paths for the v0.14.0 release

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed repo_type="model" but realize that was unneeded - however in this case I don't think is technically changes any of the logic since if I understand correctly the default functionality is to push to model repos.

yes indeed, "model" is the default repo type

no repo_type="kernel" in this case since we plan to fully remove this upload file and all of the upload logic on the python cli in a following PR.

Got it!

commit_message=commit_message,
)

Expand Down
5 changes: 2 additions & 3 deletions kernels/src/kernels/cli/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

def print_kernel_versions(repo_id: str):
api = _get_hf_api()

versions = _get_available_versions(repo_id).items()
versions = _get_available_versions(repo_id)
if not versions:
print(f"Repository does not support kernel versions: {repo_id}")
return

for version, ref in sorted(versions, key=lambda x: x[0]):
for version, ref in sorted(versions.items(), key=lambda x: x[0]):
variants = get_variants(api, repo_id=repo_id, revision=ref.ref)
resolved = resolve_variants(variants, None)
best = resolved[0] if resolved else None
Expand Down
21 changes: 16 additions & 5 deletions kernels/src/kernels/lockfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

from huggingface_hub.dataclasses import strict
from huggingface_hub.hf_api import RepoFile

from kernels._versions import resolve_version_spec_as_ref
from kernels.compat import tomllib
Expand Down Expand Up @@ -49,21 +50,31 @@ def get_kernel_locks(repo_id: str, version_spec: int | str) -> KernelLock:

tag_for_newest = resolve_version_spec_as_ref(repo_id, version_spec)

revision = tag_for_newest.target_commit

r = api.repo_info(
repo_id=repo_id, revision=tag_for_newest.target_commit, files_metadata=True
repo_id=repo_id,
repo_type="kernel",
revision=revision,
)
if r.sha is None:
raise ValueError(
f"Cannot get commit SHA for repo {repo_id} for tag {tag_for_newest.name}"
)

if r.siblings is None:
raise ValueError(
f"Cannot get sibling information for {repo_id} for tag {tag_for_newest.name}"
siblings = [
Comment thread
danieldk marked this conversation as resolved.
f
for f in api.list_repo_tree(
repo_id=repo_id,
repo_type="kernel",
revision=revision,
recursive=True,
)
if isinstance(f, RepoFile)
]

variant_files: dict[str, list[tuple[bytes, str]]] = {}
for sibling in r.siblings:
for sibling in siblings:
if sibling.rfilename.startswith("build/torch"):
if sibling.blob_id is None:
raise ValueError(f"Cannot get blob ID for {sibling.rfilename}")
Expand Down
8 changes: 6 additions & 2 deletions kernels/src/kernels/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from huggingface_hub import HfApi
from huggingface_hub.dataclasses import strict
from huggingface_hub.errors import RepositoryNotFoundError
from huggingface_hub.utils import EntryNotFoundError

from kernels.compat import tomllib
Expand Down Expand Up @@ -54,11 +55,14 @@ def check_status(
) -> KernelStatusKind | None:
try:
path = api.hf_hub_download(
repo_id=repo_id, filename="kernel-status.toml", revision=revision
repo_id=repo_id,
repo_type="kernel",
filename="kernel-status.toml",
revision=revision,
)
with open(path, "r") as f:
return KernelStatus.from_toml(f.read())
except EntryNotFoundError:
except (EntryNotFoundError, RepositoryNotFoundError):
return None


Expand Down
15 changes: 13 additions & 2 deletions kernels/src/kernels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def _import_from_path(

def install_kernel(
repo_id: str,
*,
Comment thread
danieldk marked this conversation as resolved.
revision: str,
local_files_only: bool = False,
backend: str | None = None,
Expand Down Expand Up @@ -176,10 +177,12 @@ def install_kernel(
)

allow_patterns = [f"build/{variant.variant_str}/*"]

repo_path = Path(
str(
api.snapshot_download(
repo_id,
repo_type="kernel",
allow_patterns=allow_patterns,
cache_dir=CACHE_DIR,
revision=revision,
Expand Down Expand Up @@ -234,15 +237,18 @@ def _find_kernel_in_repo_path(

def install_kernel_all_variants(
repo_id: str,
*,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

revision: str,
local_files_only: bool = False,
variant_locks: dict[str, VariantLock] | None = None,
) -> Path:
api = _get_hf_api()

repo_path = Path(
str(
api.snapshot_download(
repo_id,
repo_type="kernel",
allow_patterns="build/*",
cache_dir=CACHE_DIR,
revision=revision,
Expand Down Expand Up @@ -318,7 +324,10 @@ def get_kernel(
backend=backend,
)
package_name, variant_path = install_kernel(
repo_id, revision=revision, backend=backend, user_agent=user_agent
repo_id,
revision=revision,
backend=backend,
user_agent=user_agent,
)
return _import_from_path(package_name, variant_path, _repo_infos=repo_infos)

Expand Down Expand Up @@ -396,6 +405,7 @@ def has_kernel(
for init_file in ["__init__.py", f"{package_name}/__init__.py"]:
if api.file_exists(
repo_id,
repo_type="kernel",
revision=revision,
filename=f"build/{variant.variant_str}/{init_file}",
):
Expand Down Expand Up @@ -454,6 +464,7 @@ def load_kernel(
str(
api.snapshot_download(
repo_id,
repo_type="kernel",
allow_patterns=allow_patterns,
cache_dir=CACHE_DIR,
revision=locked_sha,
Expand Down Expand Up @@ -495,7 +506,7 @@ def get_locked_kernel(repo_id: str, local_files_only: bool = False) -> ModuleTyp
raise ValueError(f"Kernel `{repo_id}` is not locked")

package_name, variant_path = install_kernel(
repo_id, locked_sha, local_files_only=local_files_only
repo_id, revision=locked_sha, local_files_only=local_files_only
)

return _import_from_path(package_name, variant_path)
Expand Down
6 changes: 5 additions & 1 deletion kernels/src/kernels/variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,10 @@ def parse_variant(variant_str: str) -> Variant:
def get_variants(api: HfApi, *, repo_id: str, revision: str) -> list[Variant]:
"""Get all the build variants available from a kernel repository."""

tree = api.list_repo_tree(repo_id, path_in_repo="build", revision=revision)
tree = api.list_repo_tree(
repo_id, path_in_repo="build", repo_type="kernel", revision=revision
)

variant_strs = {
item.path.split("/")[-1] for item in tree if isinstance(item, RepoFolder)
}
Expand Down Expand Up @@ -333,6 +336,7 @@ def resolve_variant(
) -> Variant | None:
"""Return the best matching variant for the current system."""
resolved = resolve_variants(variants, backend)

return resolved[0] if resolved else None


Expand Down
Loading
Loading