Skip to content

Commit ccf0eeb

Browse files
sayakpauldanieldk
andauthored
[ci] e2e kernel builder tests (#416)
* add e2e tests for kernel builder cli. * fix more. * fix cargo failure. * empty * fix cachix. * up * up * remove plan * up * Apply suggestions from code review Co-authored-by: Daniël de Kok <me@danieldk.eu> * use kernel-builder buil * add * Apply suggestions from code review Co-authored-by: Daniël de Kok <me@danieldk.eu> * fix more * more * remove repo-id from the upload command. * scope the token. * upgrade forcefully. * check * switch to test_kernels runner * up * abi compilation issues. * up --------- Co-authored-by: Daniël de Kok <me@danieldk.eu>
1 parent 8ed7bb4 commit ccf0eeb

1 file changed

Lines changed: 129 additions & 0 deletions

File tree

.github/workflows/test_e2e.yaml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: "E2E: kernel-builder init + build + upload + download"
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
paths:
9+
- "kernel-builder/**"
10+
- "kernels/src/**"
11+
- "nix-builder/**"
12+
- "kernels-data/**"
13+
- ".github/workflows/test_e2e.yaml"
14+
workflow_dispatch:
15+
16+
env:
17+
E2E_REPO_ID: kernels-test/kernels-upload-test
18+
E2E_BRANCH: e2e-${{ github.event.pull_request.number || github.run_id }}-${{ github.run_attempt }}
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
22+
cancel-in-progress: true
23+
24+
jobs:
25+
init-build-upload:
26+
name: Init, build, and upload kernel
27+
runs-on:
28+
group: aws-highmemory-32-plus-nix
29+
steps:
30+
- uses: actions/checkout@v6
31+
- uses: DeterminateSystems/nix-installer-action@main
32+
with:
33+
extra-conf: |
34+
max-jobs = 8
35+
cores = 12
36+
sandbox-fallback = false
37+
- uses: cachix/cachix-action@v16
38+
with:
39+
name: huggingface
40+
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
41+
env:
42+
USER: runner
43+
44+
- name: Init kernel project
45+
run: |
46+
cd /tmp
47+
nix run $GITHUB_WORKSPACE#kernel-builder -- init \
48+
--name ${{ env.E2E_REPO_ID }} \
49+
--backends cuda
50+
51+
- name: Validate scaffold
52+
run: |
53+
cd /tmp/kernels-upload-test
54+
test -f build.toml
55+
test -f flake.nix
56+
test -f torch-ext/kernels_upload_test/__init__.py
57+
test -f torch-ext/torch_binding.cpp
58+
test -f torch-ext/torch_binding.h
59+
test -f kernels_upload_test_cuda/kernels_upload_test.cu
60+
test -f tests/test_kernels_upload_test.py
61+
test -f example.py
62+
grep -q 'name = "kernels-upload-test"' build.toml
63+
grep -q 'repo-id = "kernels-test/kernels-upload-test"' build.toml
64+
grep -q 'backend = "cuda"' build.toml
65+
66+
- name: Patch flake.nix to use local nix-builder
67+
run: |
68+
cd /tmp/kernels-upload-test
69+
sed -i 's|github:huggingface/kernels|path:'"$GITHUB_WORKSPACE"'|' flake.nix
70+
71+
- name: Build kernel
72+
run: |
73+
cd /tmp/kernels-upload-test
74+
nix run $GITHUB_WORKSPACE#kernel-builder -- build-and-copy . -L
75+
76+
- name: Verify build artifacts
77+
run: |
78+
cd /tmp/kernels-upload-test
79+
VARIANT_DIR=$(ls -d build/torch* | head -1)
80+
echo "Built variant: $VARIANT_DIR"
81+
test -f "$VARIANT_DIR/__init__.py"
82+
test -f "$VARIANT_DIR/metadata.json"
83+
ls "$VARIANT_DIR"/*.so
84+
85+
- name: Upload kernel to Hub
86+
env:
87+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
88+
run: |
89+
nix run $GITHUB_WORKSPACE#kernel-builder -- upload /tmp/kernels-upload-test --branch ${{ env.E2E_BRANCH }}
90+
91+
download-and-test:
92+
name: Download and test kernel via get_kernel
93+
needs: init-build-upload
94+
runs-on:
95+
group: aws-g6-24xlarge
96+
env:
97+
UV_PYTHON_PREFERENCE: only-managed
98+
steps:
99+
- uses: actions/checkout@v6
100+
101+
- name: Install uv and set Python version
102+
uses: astral-sh/setup-uv@v7
103+
with:
104+
python-version: "3.12"
105+
106+
- name: Install Python deps
107+
working-directory: ./kernels
108+
run: |
109+
uv sync --all-extras --dev
110+
uv pip install --upgrade torch
111+
uv run --no-sync python -c "import torch; print(f'torch={torch.__version__}, cuda={torch.version.cuda}, cxx11_abi={torch.compiled_with_cxx11_abi()}')"
112+
113+
- name: Test get_kernel download and usage
114+
working-directory: ./kernels
115+
env:
116+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
117+
run: |
118+
uv run --no-sync python -c "
119+
import torch
120+
from kernels import get_kernel
121+
122+
kernel = get_kernel('${{ env.E2E_REPO_ID }}', revision='${{ env.E2E_BRANCH }}')
123+
124+
x = torch.randn(1024, 1024, dtype=torch.float32, device='cuda')
125+
result = kernel.kernels_upload_test(x)
126+
expected = x + 1.0
127+
torch.testing.assert_close(result, expected)
128+
print('E2E test passed: get_kernel + correctness check')
129+
"

0 commit comments

Comments
 (0)