Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
33 changes: 24 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Lints
on: [push, pull_request]
name: Styling and lints
on:
push:
pull_request:
workflow_call:
jobs:
lint:
name: Run lints
Expand All @@ -8,8 +11,8 @@ jobs:
- uses: actions/checkout@v6
- name: Run ruff
uses: astral-sh/ruff-action@v3
src: >-
kernels
with:
src: kernels/src kernels/tests

black:
name: Run black check
Expand All @@ -24,12 +27,24 @@ jobs:
with:
python-version: 3.12

- name: Install black
run: uv pip install black

- name: Check formatting
run: |
uv run black --check kernels
run: uv run --with black black --check kernels/src kernels/tests

isort:
name: Run isort check
runs-on: ubuntu-latest
env:
UV_PYTHON_PREFERENCE: only-managed
steps:
- uses: actions/checkout@v6

- name: Install uv and set the python version
uses: astral-sh/setup-uv@v7
with:
python-version: 3.12

- name: Check import sorting
run: uv run --with isort isort --check-only --diff kernels/src kernels/tests

validate-dependencies:
name: Validate python_depends.json
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test_kernels.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ concurrency:
cancel-in-progress: true

jobs:
styling-and-lints:
uses: ./.github/workflows/lint.yml

build:
needs: [styling-and-lints]
name: Run kernels tests
runs-on:
group: aws-g6-24xlarge
Expand Down
7 changes: 6 additions & 1 deletion kernels/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: style
.PHONY: style quality

export check_dirs := src tests

Expand All @@ -11,3 +11,8 @@ style:
black ${check_dirs}
isort ${check_dirs}
ruff check ${check_dirs} --fix

quality:
black --check ${check_dirs}
isort --check-only --diff ${check_dirs}
ruff check ${check_dirs}
30 changes: 10 additions & 20 deletions kernels/tests/test_kernel_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ def mock_kernel_dir():
kernel_dir = Path(tmpdir)

build_toml = kernel_dir / "build.toml"
build_toml.write_text(
"""[general]
build_toml.write_text("""[general]
Copy link
Member Author

@sayakpaul sayakpaul Mar 10, 2026

Choose a reason for hiding this comment

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

Result of make style.

We could consider fixing the black version (same for isort and ruff) but I don't think it's a big deal.

name = "test_kernel"
backends = ["cuda", "metal"]
license = "apache-2.0"
Expand All @@ -36,32 +35,27 @@ def mock_kernel_dir():
[kernel._test]
backend = "cuda"
cuda-capabilities = ["8.0", "8.9"]
"""
)
""")

torch_ext_dir = kernel_dir / "torch-ext" / "test_kernel"
torch_ext_dir.mkdir(parents=True)

init_file = torch_ext_dir / "__init__.py"
init_file.write_text(
"""from .core import func1, func2
init_file.write_text("""from .core import func1, func2

__all__ = ["func1", "func2", "func3"]
"""
)
""")

core_file = torch_ext_dir / "core.py"
core_file.write_text(
"""def func1():
core_file.write_text("""def func1():
pass

def func2():
pass

def func3():
pass
"""
)
""")

yield kernel_dir

Expand All @@ -72,17 +66,15 @@ def mock_kernel_dir_with_benchmark(mock_kernel_dir):
benchmarks_dir.mkdir()

benchmark_file = benchmarks_dir / "benchmark.py"
benchmark_file.write_text(
"""import time
benchmark_file.write_text("""import time

def benchmark():
# Simple benchmark
start = time.time()
# ... benchmark code ...
end = time.time()
return end - start
"""
)
""")

return mock_kernel_dir

Expand All @@ -93,12 +85,10 @@ def mock_kernel_dir_minimal():
kernel_dir = Path(tmpdir)

build_toml = kernel_dir / "build.toml"
build_toml.write_text(
"""[general]
build_toml.write_text("""[general]
name = "minimal_kernel"
backends = ["cuda"]
"""
)
""")

yield kernel_dir

Expand Down
2 changes: 1 addition & 1 deletion kernels/tests/test_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def __init__(self):

def forward(self, input: torch.Tensor) -> torch.Tensor:
self.n_calls += 1
d = input.shape[-1] // 2
_ = input.shape[-1] // 2
return F.relu(input)


Expand Down
13 changes: 9 additions & 4 deletions kernels/tests/test_status.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
from unittest.mock import MagicMock

import pytest

from kernels.status import (
Redirect,
KernelStatus,
Redirect,
resolve_status,
)

Expand Down Expand Up @@ -60,7 +61,9 @@ def test_redirect(self, tmp_path):
from huggingface_hub.utils import EntryNotFoundError

status_file = tmp_path / "kernel-status.toml"
status_file.write_text('kind = "redirect"\ndestination = "kernels-community/new-kernel"')
status_file.write_text(
'kind = "redirect"\ndestination = "kernels-community/new-kernel"'
)

def mock_download(repo_id, filename, revision):
if repo_id == "kernels-test/old-kernel":
Expand All @@ -78,7 +81,9 @@ def test_redirect_with_revision(self, tmp_path):
from huggingface_hub.utils import EntryNotFoundError

status_file = tmp_path / "kernel-status.toml"
status_file.write_text('kind = "redirect"\ndestination = "kernels-community/new-kernel"\nrevision = "v2"')
status_file.write_text(
'kind = "redirect"\ndestination = "kernels-community/new-kernel"\nrevision = "v2"'
)

def mock_download(repo_id, filename, revision):
if repo_id == "kernels-test/old-kernel":
Expand Down
Loading