mirror of
https://github.com/huggingface/kernels.git
synced 2025-10-20 12:33:46 +08:00
Compare commits
2 Commits
ed048616fe
...
cc754ff93e
Author | SHA1 | Date | |
---|---|---|---|
cc754ff93e | |||
46a2a1fd6d |
@ -1,6 +1,7 @@
|
||||
import argparse
|
||||
import dataclasses
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@ -13,6 +14,8 @@ from kernels.utils import install_kernel, install_kernel_all_variants
|
||||
from .doc import generate_readme_for_kernel
|
||||
from .wheel import build_variant_to_wheel
|
||||
|
||||
BUILD_VARIANT_REGEX = re.compile(r"^(torch\d+\d+|torch-universal)")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
@ -65,14 +68,14 @@ def main():
|
||||
help="Directory of the kernel build",
|
||||
)
|
||||
upload_parser.add_argument(
|
||||
"--repo_id",
|
||||
"--repo-id",
|
||||
type=str,
|
||||
help="Repository ID to use to upload to the Hugging Face Hub",
|
||||
)
|
||||
upload_parser.add_argument(
|
||||
"--branch",
|
||||
type=None,
|
||||
help="If set, the upload will be made to a particular branch of the provided `repo_id`.",
|
||||
help="If set, the upload will be made to a particular branch of the provided `repo-id`.",
|
||||
)
|
||||
upload_parser.add_argument(
|
||||
"--private",
|
||||
@ -206,11 +209,21 @@ def lock_kernels(args):
|
||||
def upload_kernels(args):
|
||||
# Resolve `kernel_dir` to be uploaded.
|
||||
kernel_dir = Path(args.kernel_dir).resolve()
|
||||
build_dir = kernel_dir / "build"
|
||||
if not kernel_dir.is_dir():
|
||||
raise ValueError(f"{kernel_dir} is not a directory")
|
||||
if not build_dir.is_dir():
|
||||
raise ValueError("Couldn't find `build` directory inside `kernel_dir`")
|
||||
|
||||
build_dir = None
|
||||
for candidate in [kernel_dir / "build", kernel_dir]:
|
||||
variants = [
|
||||
variant_path
|
||||
for variant_path in candidate.glob("torch*")
|
||||
if BUILD_VARIANT_REGEX.match(variant_path.name) is not None
|
||||
]
|
||||
if variants:
|
||||
build_dir = candidate
|
||||
break
|
||||
if build_dir is None:
|
||||
raise ValueError(
|
||||
f"Couldn't find any build variants in: {kernel_dir.absolute()} or {(kernel_dir / 'build').absolute()}"
|
||||
)
|
||||
|
||||
repo_id = create_repo(
|
||||
repo_id=args.repo_id, private=args.private, exist_ok=True
|
||||
|
@ -528,11 +528,16 @@ def _get_user_agent(
|
||||
return None
|
||||
|
||||
if user_agent is None:
|
||||
user_agent = {
|
||||
"kernels": __version__,
|
||||
"torch": torch.__version__,
|
||||
"build_variant": build_variant(),
|
||||
"file_type": "kernel",
|
||||
}
|
||||
|
||||
user_agent = {}
|
||||
if isinstance(user_agent, dict):
|
||||
user_agent.update(
|
||||
{
|
||||
"kernels": __version__,
|
||||
"torch": torch.__version__,
|
||||
"build_variant": build_variant(),
|
||||
"file_type": "kernel",
|
||||
}
|
||||
)
|
||||
elif isinstance(user_agent, str):
|
||||
user_agent += f"; kernels/{__version__}; torch/{torch.__version__}; build_variant/{build_variant()}; file_type/kernel"
|
||||
return user_agent
|
||||
|
Reference in New Issue
Block a user