Skip to content
Open
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
2 changes: 1 addition & 1 deletion kernels/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: style

export check_dirs := src examples tests
export check_dirs := src tests

all: src/kernels/python_depends.json

Expand Down
6 changes: 2 additions & 4 deletions kernels/src/kernels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

__version__ = importlib.metadata.version("kernels")

from kernels._windows import _add_additional_dll_paths
from kernels.benchmark import Benchmark
from kernels.layer import (
CUDAProperties,
Device,
Expand All @@ -27,10 +29,6 @@
install_kernel,
load_kernel,
)
from kernels.benchmark import Benchmark


from kernels._windows import _add_additional_dll_paths

_add_additional_dll_paths()

Expand Down
22 changes: 11 additions & 11 deletions kernels/src/kernels/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
import sys
from pathlib import Path

from kernels.compat import tomllib
from kernels.lockfile import KernelLock, get_kernel_locks
from kernels.cli.upload import upload_kernels_dir
from kernels.utils import (
install_kernel,
install_kernel_all_variants,
KNOWN_BACKENDS,
)
from kernels.cli.init import run_init, parse_kernel_name
from kernels.cli.doc import generate_readme_for_kernel
from kernels.cli.init import parse_kernel_name, run_init
from kernels.cli.skills import add_skill
from kernels.cli.upload import upload_kernels_dir
from kernels.cli.versions import print_kernel_versions
from kernels.cli.doc import generate_readme_for_kernel
from kernels.compat import tomllib
from kernels.kernel_card_utils import (
_load_or_create_kernel_card,
_update_benchmark,
_update_kernel_card_available_funcs,
_update_kernel_card_license,
_update_kernel_card_backends,
_update_kernel_card_license,
_update_kernel_card_usage,
)
from kernels.lockfile import KernelLock, get_kernel_locks
from kernels.utils import (
KNOWN_BACKENDS,
install_kernel,
install_kernel_all_variants,
)


def main():
Expand Down
4 changes: 2 additions & 2 deletions kernels/src/kernels/cli/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)

from kernels.benchmark import Benchmark
from kernels.utils import _get_hf_api, _backend
from kernels.utils import _backend, _get_hf_api

MISSING_DEPS: list[str] = []

Expand Down Expand Up @@ -457,7 +457,7 @@ def run_benchmark_class(
raise RuntimeError(f"No benchmark_* methods found in {benchmark_cls.__name__}")

# Load kernel once for all workloads
from kernels import get_local_kernel, get_kernel
from kernels import get_kernel, get_local_kernel

if is_local:
kernel = get_local_kernel(Path(repo_id), "activation")
Expand Down
10 changes: 4 additions & 6 deletions kernels/src/kernels/cli/benchmark_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ def _embed_logo_in_svg(svg_path: str, logo_size: int = 24) -> None:
viewbox_match = re.search(r'viewBox="([^"]+)"', content)
if viewbox_match:
parts = viewbox_match.group(1).split()
width = float(parts[2])
height = float(parts[3])
else:
width_match = re.search(r'width="([0-9.]+)', content)
height_match = re.search(r'height="([0-9.]+)', content)
width = float(width_match.group(1)) if width_match else 800
height = float(height_match.group(1)) if height_match else 400

svg_match = re.search(r"<svg[^>]*>(.*)</svg>", logo_svg, re.DOTALL)
Expand Down Expand Up @@ -481,9 +478,10 @@ def _save_speedup_gif(
)
return

from matplotlib.patches import FancyBboxPatch, Ellipse
from urllib.request import urlopen

from matplotlib.patches import Ellipse, FancyBboxPatch

matplotlib.use("Agg")
plt.rcParams["font.family"] = _HF_FONT

Expand Down Expand Up @@ -753,10 +751,10 @@ def _save_speedup_svg(
f'<text x="{track_x+track_w+10}" y="{y+4}" font-size="10" font-weight="bold" fill="{text}">{speedup:.2f}x</text>',
f'<circle cx="{x_min}" cy="{y-6}" r="{ball_r}" fill="{_HF_ORANGE}" stroke="white" stroke-width="1.5">',
f' <animate attributeName="cx" values="{x_min};{x_max};{x_min}" dur="{kernel_dur}s" repeatCount="indefinite" calcMode="spline" keySplines="0.5 0 0.5 1;0.5 0 0.5 1"/>',
f"</circle>",
"</circle>",
f'<circle cx="{x_min}" cy="{y+6}" r="{ball_r}" fill="{_HF_GRAY}" stroke="white" stroke-width="1.5">',
f' <animate attributeName="cx" values="{x_min};{x_max};{x_min}" dur="{ref_dur}s" repeatCount="indefinite" calcMode="spline" keySplines="0.5 0 0.5 1;0.5 0 0.5 1"/>',
f"</circle>",
"</circle>",
]
)

Expand Down
3 changes: 2 additions & 1 deletion kernels/src/kernels/cli/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import yaml

from ._vendored.convert_rst_to_mdx import convert_rst_docstring_to_mdx
from kernels.utils import get_kernel

from ._vendored.convert_rst_to_mdx import convert_rst_docstring_to_mdx

_RE_PARAMETERS = re.compile(
r"<parameters>(((?!<parameters>).)*)</parameters>", re.DOTALL
)
Expand Down
2 changes: 1 addition & 1 deletion kernels/src/kernels/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from pathlib import Path
from typing import NamedTuple

import tomlkit
from huggingface_hub import snapshot_download
from huggingface_hub.utils import disable_progress_bars

import tomlkit
from kernels.utils import KNOWN_BACKENDS

KERNEL_NAME_PATTERN = re.compile(r"^[a-z][-a-z0-9]*[a-z0-9]$")
Expand Down
1 change: 0 additions & 1 deletion kernels/src/kernels/cli/skills.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from huggingface_hub.utils import get_session


DEFAULT_SKILL_ID = "cuda-kernels"
_GITHUB_RAW_BASE = (
"https://raw.githubusercontent.com/huggingface/kernels/main/" "skills/cuda-kernels"
Expand Down
3 changes: 2 additions & 1 deletion kernels/src/kernels/cli/versions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from importlib.util import find_spec
from pathlib import Path

from huggingface_hub import HfApi

from kernels._versions import _get_available_versions
from kernels.utils import _get_hf_api, _build_variants
from kernels.utils import _build_variants, _get_hf_api
from kernels.variants import BUILD_VARIANT_REGEX


Expand Down
5 changes: 3 additions & 2 deletions kernels/src/kernels/kernel_card_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import ast
import re
from pathlib import Path

from .compat import tomllib
from typing import Any

from huggingface_hub import ModelCard, ModelCardData
from huggingface_hub.errors import EntryNotFoundError, RepositoryNotFoundError

from .compat import tomllib

KERNEL_CARD_TEMPLATE_PATH = Path(__file__).parent / "card_template.md"
DESCRIPTION = """
This is the repository card of {repo_id} that has been pushed on the Hub. It was built to be used with the [`kernels` library](https://github.com/huggingface/kernels). This card was automatically generated.
Expand Down
5 changes: 2 additions & 3 deletions kernels/src/kernels/layer/kernelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from copy import deepcopy
from typing import TYPE_CHECKING

from .repos import DeviceRepos
from .device import Device
from .globals import _KERNEL_MAPPING
from .layer import kernelize_layer
from .repos import RepositoryProtocol
from .mode import Mode
from .device import Device
from .repos import DeviceRepos, RepositoryProtocol

if TYPE_CHECKING:
import torch
Expand Down
9 changes: 4 additions & 5 deletions kernels/src/kernels/layer/repos.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Protocol, Type
import sys
from abc import ABC, abstractmethod
from functools import lru_cache
from typing import TYPE_CHECKING, Protocol, Type

from .device import Device
from .mode import Mode
from ._interval_tree import IntervalTree
from .device import CUDAProperties, ROCMProperties
from .device import CUDAProperties, Device, ROCMProperties
from .mode import Mode

if TYPE_CHECKING:
from torch import nn
Expand Down
2 changes: 1 addition & 1 deletion kernels/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from huggingface_hub.errors import RepositoryNotFoundError
import pytest
import torch
import torch.nn.functional as F
from huggingface_hub.errors import RepositoryNotFoundError

from kernels import get_kernel, get_local_kernel, has_kernel, install_kernel

Expand Down
6 changes: 3 additions & 3 deletions kernels/tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import tempfile
from pathlib import Path
import argparse
import os
import tempfile
from pathlib import Path

from kernels.cli.init import run_init, parse_kernel_name
from kernels.cli.init import parse_kernel_name, run_init
from kernels.utils import KNOWN_BACKENDS


Expand Down
2 changes: 1 addition & 1 deletion kernels/tests/test_kernel_card.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import tempfile
from pathlib import Path
from dataclasses import dataclass
from pathlib import Path
from unittest.mock import patch

import pytest
Expand Down
2 changes: 1 addition & 1 deletion kernels/tests/test_layer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
from contextlib import nullcontext

from huggingface_hub.errors import RepositoryNotFoundError
import pytest
import torch
import torch.nn as nn
from huggingface_hub.errors import RepositoryNotFoundError
from torch.nn import functional as F

from kernels import (
Expand Down
Loading