Skip to content

Commit 0c582a5

Browse files
drbhsayakpauldanieldk
authored
feat: prefer unique e2e ci repo rather than branch (#573)
* feat: prefer unique e2e ci repo rather than branch * CI: fix get_kernel call in e2e test --------- Co-authored-by: Sayak Paul <spsayakpaul@gmail.com> Co-authored-by: Daniël de Kok <me@danieldk.eu>
1 parent 0ca3b4d commit 0c582a5

1 file changed

Lines changed: 40 additions & 38 deletions

File tree

.github/workflows/test_e2e.yaml

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ on:
1616
env:
1717
HF_ENDPOINT: https://hub-ci.huggingface.co
1818
HF_TOKEN: ${{ secrets.HF_HUB_CI_TOKEN }}
19-
E2E_REPO_ID: __DUMMY_KERNELS_USER__/kernels-upload-test
20-
E2E_BRANCH: e2e-${{ github.event.pull_request.number || github.run_id }}-${{ github.run_attempt }}
21-
22-
concurrency:
23-
group: ${{ github.workflow }}
24-
cancel-in-progress: true
19+
E2E_REPO_ID: __DUMMY_KERNELS_USER__/kernels-e2e-${{ github.run_id }}-${{ github.run_attempt }}
20+
E2E_REPO_NAME: kernels-e2e-${{ github.run_id }}-${{ github.run_attempt }}
21+
E2E_PKG_NAME: kernels_e2e_${{ github.run_id }}_${{ github.run_attempt }}
2522

2623
jobs:
2724
init-build-upload:
@@ -45,23 +42,6 @@ jobs:
4542
env:
4643
USER: runner
4744

48-
# Remove the existing test repo if it exists so we test repo creation in the upload step
49-
- name: Delete existing test repo
50-
run: |
51-
cat > /tmp/delete_repos.py << 'PYEOF'
52-
from huggingface_hub import HfApi
53-
import os
54-
55-
api = HfApi(
56-
endpoint=os.environ["HF_ENDPOINT"]
57-
)
58-
repo_id = os.environ["E2E_REPO_ID"]
59-
for repo_type in ["kernel", "model"]:
60-
api.delete_repo(repo_id, repo_type=repo_type, missing_ok=True)
61-
print(f"Deleted {repo_type} repo (or it did not exist)")
62-
PYEOF
63-
nix-shell -p python3Packages.huggingface-hub --run "python /tmp/delete_repos.py"
64-
6545
- name: Init kernel project
6646
run: |
6747
cd /tmp
@@ -71,47 +51,47 @@ jobs:
7151
7252
- name: Validate scaffold
7353
run: |
74-
cd /tmp/kernels-upload-test
54+
cd /tmp/${{ env.E2E_REPO_NAME }}
7555
test -f build.toml
7656
test -f flake.nix
77-
test -f torch-ext/kernels_upload_test/__init__.py
57+
test -f torch-ext/${{ env.E2E_PKG_NAME }}/__init__.py
7858
test -f torch-ext/torch_binding.cpp
7959
test -f torch-ext/torch_binding.h
80-
test -f kernels_upload_test_cuda/kernels_upload_test.cu
81-
test -f tests/test_kernels_upload_test.py
60+
test -f ${{ env.E2E_PKG_NAME }}_cuda/${{ env.E2E_PKG_NAME }}.cu
61+
test -f tests/test_${{ env.E2E_PKG_NAME }}.py
8262
test -f example.py
83-
grep -q 'name = "kernels-upload-test"' build.toml
84-
grep -q 'repo-id = "__DUMMY_KERNELS_USER__/kernels-upload-test"' build.toml
63+
grep -q 'name = "${{ env.E2E_REPO_NAME }}"' build.toml
64+
grep -q 'repo-id = "${{ env.E2E_REPO_ID }}"' build.toml
8565
grep -q 'backend = "cuda"' build.toml
8666
8767
- name: Patch flake.nix to use local nix-builder
8868
run: |
89-
cd /tmp/kernels-upload-test
69+
cd /tmp/${{ env.E2E_REPO_NAME }}
9070
sed -i 's|github:huggingface/kernels|path:'"$GITHUB_WORKSPACE"'|' flake.nix
9171
9272
- name: Make flake a Git repo
9373
run: |
94-
cd /tmp/kernels-upload-test
74+
cd /tmp/${{ env.E2E_REPO_NAME }}
9575
git config --global user.email "bottie@mcbotface.hf.co"
9676
git config --global user.name "Botty McBotface"
9777
git init && git add . && git commit -m "e2e test"
9878
9979
- name: Determine latest variant
10080
id: variant
10181
run: |
102-
cd /tmp/kernels-upload-test
82+
cd /tmp/${{ env.E2E_REPO_NAME }}
10383
VARIANT=$(nix run $GITHUB_WORKSPACE#kernel-builder -- list-variants . | tail -1)
10484
echo "name=$VARIANT" >> $GITHUB_OUTPUT
10585
echo "Building variant: $VARIANT"
10686
10787
- name: Build kernel
10888
run: |
109-
cd /tmp/kernels-upload-test
89+
cd /tmp/${{ env.E2E_REPO_NAME }}
11090
nix run $GITHUB_WORKSPACE#kernel-builder -- build --variant ${{ steps.variant.outputs.name }} . -L
11191
11292
- name: Verify build artifacts
11393
run: |
114-
cd /tmp/kernels-upload-test
94+
cd /tmp/${{ env.E2E_REPO_NAME }}
11595
VARIANT_DIR=$(ls -d result/torch* | head -1)
11696
echo "Built variant: $VARIANT_DIR"
11797
test -f "$VARIANT_DIR/__init__.py"
@@ -120,8 +100,8 @@ jobs:
120100
121101
- name: Upload kernel to Hub
122102
run: |
123-
nix run $GITHUB_WORKSPACE#kernel-builder -- upload /tmp/kernels-upload-test --branch ${{ env.E2E_BRANCH }}
124-
nix run $GITHUB_WORKSPACE#kernel-builder -- upload /tmp/kernels-upload-test --branch ${{ env.E2E_BRANCH }} --repo-type model
103+
nix run $GITHUB_WORKSPACE#kernel-builder -- upload /tmp/${{ env.E2E_REPO_NAME }}
104+
nix run $GITHUB_WORKSPACE#kernel-builder -- upload /tmp/${{ env.E2E_REPO_NAME }} --repo-type model
125105
126106
download-and-test:
127107
name: Download and test kernel via get_kernel
@@ -157,11 +137,33 @@ jobs:
157137
import torch
158138
from kernels import get_kernel
159139
160-
kernel = get_kernel('${{ env.E2E_REPO_ID }}', revision='${{ env.E2E_BRANCH }}', trust_remote_code=True)
140+
kernel = get_kernel('${{ env.E2E_REPO_ID }}', trust_remote_code=True, version=1)
161141
162142
x = torch.randn(1024, 1024, dtype=torch.float32, device='cuda')
163-
result = kernel.kernels_upload_test(x)
143+
result = kernel.${{ env.E2E_PKG_NAME }}(x)
164144
expected = x + 1.0
165145
torch.testing.assert_close(result, expected)
166146
print('E2E test passed: get_kernel + correctness check')
167147
"
148+
149+
cleanup:
150+
name: Clean up test repos
151+
needs: [init-build-upload, download-and-test]
152+
if: always()
153+
runs-on: ubuntu-latest
154+
steps:
155+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7.6.0
156+
with:
157+
python-version: "3.12"
158+
- name: Delete test repos
159+
run: |
160+
uv run --with huggingface-hub python -c "
161+
from huggingface_hub import HfApi
162+
import os
163+
164+
api = HfApi(endpoint=os.environ['HF_ENDPOINT'])
165+
repo_id = os.environ['E2E_REPO_ID']
166+
for repo_type in ['kernel', 'model']:
167+
api.delete_repo(repo_id, repo_type=repo_type, missing_ok=True)
168+
print(f'Deleted {repo_type} repo (or it did not exist)')
169+
"

0 commit comments

Comments
 (0)