From c84f92eb6870242d7fb81923087b7b446ad00e32 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 10:34:55 +0530 Subject: [PATCH 1/6] catch styling bugs in the prs better. --- .github/workflows/lint.yml | 33 +++++++++++++++++++++++------ .github/workflows/test_kernels.yaml | 4 ++++ kernels/Makefile | 7 +++++- kernels/tests/test_layer.py | 2 +- kernels/tests/test_status.py | 13 ++++++++---- 5 files changed, 47 insertions(+), 12 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e433eb8c..c7c16112 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -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 @@ -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 @@ -28,8 +31,26 @@ jobs: run: uv pip install black - name: Check formatting - run: | - uv run black --check kernels + run: uv run 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: Install isort + run: uv pip install isort + + - name: Check import sorting + run: uv run isort --check-only --diff kernels/src kernels/tests validate-dependencies: name: Validate python_depends.json diff --git a/.github/workflows/test_kernels.yaml b/.github/workflows/test_kernels.yaml index 39368c4e..224257e1 100644 --- a/.github/workflows/test_kernels.yaml +++ b/.github/workflows/test_kernels.yaml @@ -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 diff --git a/kernels/Makefile b/kernels/Makefile index 580f53ab..94fcf78c 100644 --- a/kernels/Makefile +++ b/kernels/Makefile @@ -1,4 +1,4 @@ -.PHONY: style +.PHONY: style quality export check_dirs := src tests @@ -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} diff --git a/kernels/tests/test_layer.py b/kernels/tests/test_layer.py index 17dc11c0..ca804e8c 100644 --- a/kernels/tests/test_layer.py +++ b/kernels/tests/test_layer.py @@ -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) diff --git a/kernels/tests/test_status.py b/kernels/tests/test_status.py index d9d5bd2b..f746c7bc 100644 --- a/kernels/tests/test_status.py +++ b/kernels/tests/test_status.py @@ -1,9 +1,10 @@ -import pytest from unittest.mock import MagicMock +import pytest + from kernels.status import ( - Redirect, KernelStatus, + Redirect, resolve_status, ) @@ -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": @@ -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": From 2d37824227bcd66876f95732b9188c44ce9062a7 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 10:41:49 +0530 Subject: [PATCH 2/6] fix --- .github/workflows/lint.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c7c16112..bc59aeea 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -27,11 +27,8 @@ jobs: with: python-version: 3.12 - - name: Install black - run: uv pip install black - - name: Check formatting - run: uv run black --check kernels/src kernels/tests + run: uv run --with black black --check kernels/src kernels/tests isort: name: Run isort check @@ -46,11 +43,8 @@ jobs: with: python-version: 3.12 - - name: Install isort - run: uv pip install isort - - name: Check import sorting - run: uv run isort --check-only --diff kernels/src kernels/tests + run: uv run --with isort isort --check-only --diff kernels/src kernels/tests validate-dependencies: name: Validate python_depends.json From d7494123a04d05c083d8b4be59aa350d6444a3d4 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 10:43:53 +0530 Subject: [PATCH 3/6] make style --- kernels/tests/test_kernel_card.py | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/kernels/tests/test_kernel_card.py b/kernels/tests/test_kernel_card.py index 94777333..b638287b 100644 --- a/kernels/tests/test_kernel_card.py +++ b/kernels/tests/test_kernel_card.py @@ -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] name = "test_kernel" backends = ["cuda", "metal"] license = "apache-2.0" @@ -36,23 +35,19 @@ 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(): @@ -60,8 +55,7 @@ def func2(): def func3(): pass -""" - ) +""") yield kernel_dir @@ -72,8 +66,7 @@ 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 @@ -81,8 +74,7 @@ def benchmark(): # ... benchmark code ... end = time.time() return end - start -""" - ) +""") return mock_kernel_dir @@ -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 From 370048650edc0b65fd3b70a30385e40745cd3ebf Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 10:52:31 +0530 Subject: [PATCH 4/6] fix step --- .github/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index bc59aeea..49044148 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -59,7 +59,7 @@ jobs: - name: Validate python_depends.json is up-to-date run: | - python ( cd kernels && update_python_depends.py --validate ) || { + (cd kernels && python update_python_depends.py --validate) || { echo "Error: python_depends.json is out of date." echo "Please run: python update_python_depends.py" exit 1 From acfe9ef035e97c7d775eb2f9d5d5513875438c50 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 15:44:12 +0530 Subject: [PATCH 5/6] remove from test_kernels.yaml --- .github/workflows/test_kernels.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/test_kernels.yaml b/.github/workflows/test_kernels.yaml index 224257e1..39368c4e 100644 --- a/.github/workflows/test_kernels.yaml +++ b/.github/workflows/test_kernels.yaml @@ -13,11 +13,7 @@ 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 From 835c76e15747aaca44f0ce6ba9bdb81a461c74e4 Mon Sep 17 00:00:00 2001 From: sayakpaul Date: Tue, 10 Mar 2026 15:45:20 +0530 Subject: [PATCH 6/6] up --- .github/workflows/lint.yml | 6 ++---- kernels/tests/test_layer.py | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 49044148..8b784fd9 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,8 +1,6 @@ name: Styling and lints -on: - push: - pull_request: - workflow_call: +on: [push, pull_request] + jobs: lint: name: Run lints diff --git a/kernels/tests/test_layer.py b/kernels/tests/test_layer.py index ca804e8c..e9988fd3 100644 --- a/kernels/tests/test_layer.py +++ b/kernels/tests/test_layer.py @@ -102,7 +102,6 @@ def __init__(self): def forward(self, input: torch.Tensor) -> torch.Tensor: self.n_calls += 1 - _ = input.shape[-1] // 2 return F.relu(input)