mirror of
https://github.com/huggingface/kernels.git
synced 2025-10-22 05:48:52 +08:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
3212affd9e | |||
7ff40a859c | |||
cf64113c8b | |||
ba4f88f5aa | |||
d61971ad46 | |||
d7f3831992 |
@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "hf-kernels"
|
||||
version = "0.1.3"
|
||||
version = "0.1.6"
|
||||
description = "Download cuda kernels"
|
||||
authors = [
|
||||
{ name = "OlivierDehaene", email = "olivier@huggingface.co" },
|
||||
|
@ -89,7 +89,12 @@ def write_egg_lockfile(cmd, basename, filename):
|
||||
import logging
|
||||
|
||||
cwd = Path.cwd()
|
||||
with open(cwd / "pyproject.toml", "rb") as f:
|
||||
pyproject_path = cwd / "pyproject.toml"
|
||||
if not pyproject_path.exists():
|
||||
# Nothing to do if the project doesn't have pyproject.toml.
|
||||
return
|
||||
|
||||
with open(pyproject_path, "rb") as f:
|
||||
data = tomllib.load(f)
|
||||
|
||||
kernel_versions = data.get("tool", {}).get("kernels", {}).get("dependencies", None)
|
||||
|
@ -1,3 +1,4 @@
|
||||
import ctypes
|
||||
import importlib
|
||||
import importlib.metadata
|
||||
import inspect
|
||||
@ -15,6 +16,8 @@ from packaging.version import parse
|
||||
from hf_kernels.compat import tomllib
|
||||
from hf_kernels.lockfile import KernelLock
|
||||
|
||||
CACHE_DIR: Optional[str] = os.environ.get("HF_KERNELS_CACHE", None)
|
||||
|
||||
|
||||
def build_variant():
|
||||
import torch
|
||||
@ -29,6 +32,12 @@ def build_variant():
|
||||
|
||||
|
||||
def import_from_path(module_name: str, file_path):
|
||||
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
||||
# it would also be used for other imports. So, we make a module name that
|
||||
# depends on the path for it to be unique using the hex-encoded hash of
|
||||
# the path.
|
||||
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path)).value)
|
||||
module_name = f"{module_name}_{path_hash}"
|
||||
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
sys.modules[module_name] = module
|
||||
@ -43,6 +52,7 @@ def install_kernel(repo_id: str, revision: str, local_files_only: bool = False):
|
||||
repo_path = snapshot_download(
|
||||
repo_id,
|
||||
allow_patterns=f"build/{build_variant()}/*",
|
||||
cache_dir=CACHE_DIR,
|
||||
revision=revision,
|
||||
local_files_only=local_files_only,
|
||||
)
|
||||
@ -55,6 +65,7 @@ def install_kernel_all_variants(
|
||||
snapshot_download(
|
||||
repo_id,
|
||||
allow_patterns="build/*",
|
||||
cache_dir=CACHE_DIR,
|
||||
revision=revision,
|
||||
local_files_only=local_files_only,
|
||||
)
|
||||
@ -63,7 +74,11 @@ def install_kernel_all_variants(
|
||||
def get_metadata(repo_id: str, revision: str, local_files_only: bool = False):
|
||||
with open(
|
||||
hf_hub_download(
|
||||
repo_id, "build.toml", revision=revision, local_files_only=local_files_only
|
||||
repo_id,
|
||||
"build.toml",
|
||||
cache_dir=CACHE_DIR,
|
||||
revision=revision,
|
||||
local_files_only=local_files_only,
|
||||
),
|
||||
"rb",
|
||||
) as f:
|
||||
@ -83,7 +98,11 @@ def load_kernel(repo_id: str):
|
||||
raise ValueError(f"Kernel `{repo_id}` is not locked")
|
||||
|
||||
filename = hf_hub_download(
|
||||
repo_id, "build.toml", local_files_only=True, revision=locked_sha
|
||||
repo_id,
|
||||
"build.toml",
|
||||
cache_dir=CACHE_DIR,
|
||||
local_files_only=True,
|
||||
revision=locked_sha,
|
||||
)
|
||||
with open(filename, "rb") as f:
|
||||
metadata = tomllib.load(f)
|
||||
|
Reference in New Issue
Block a user