Skip to content

Commit 0d787e3

Browse files
authored
GitHub workflow to build Triton wheels (#4431)
New workflow to build PyTorch wheels that will replace eventually the existing "Nightly wheels" workflow. Currently only wheels for Windows are supported to address user requests for pre-built Triton for Windows. --------- Signed-off-by: Pavel Chekin <[email protected]>
1 parent 070ee7d commit 0d787e3

File tree

3 files changed

+128
-1
lines changed

3 files changed

+128
-1
lines changed

.github/workflows/wheels-pytorch.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
branches:
77
- main
88
paths:
9-
- .github/workflows/wheels-pytorch.yml
109
- .github/pins/pytorch.txt
1110

1211
permissions: read-all

.github/workflows/wheels-triton.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Triton wheels
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions: read-all
7+
8+
env:
9+
NEW_WORKSPACE: C:\gh${{ github.run_id }}
10+
11+
jobs:
12+
windows:
13+
runs-on:
14+
- windows
15+
- b580
16+
strategy:
17+
matrix:
18+
python:
19+
- "3.9"
20+
- "3.10"
21+
- "3.11"
22+
- "3.12"
23+
- "3.13"
24+
fail-fast: false
25+
max-parallel: 2
26+
steps:
27+
- name: Checkout Triton repository
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v5
32+
with:
33+
python-version: "3.12"
34+
35+
- name: Clean up old workspaces
36+
shell: bash
37+
run: |
38+
rm -rf /c/gh*
39+
40+
# Copy workspace to a temporary location with a shorter name.
41+
- name: Copy workspace
42+
run: |
43+
Copy-Item -Path ${{ github.workspace }} -Destination ${{ env.NEW_WORKSPACE }} -Recurse
44+
45+
- name: Create venv
46+
run: |
47+
cd ${{ env.NEW_WORKSPACE }}
48+
python -m venv .venv
49+
50+
- name: Install build dependencies
51+
run: |
52+
cd ${{ env.NEW_WORKSPACE }}
53+
.venv\Scripts\activate.ps1
54+
pip install cibuildwheel
55+
56+
- name: Set Triton version
57+
shell: bash
58+
run: |
59+
cd /c/gh${{ github.run_id }}
60+
version="$(./scripts/triton-version.sh)"
61+
version="$version.post$GITHUB_RUN_NUMBER+git$(git rev-parse --short=7 HEAD)"
62+
./scripts/triton-version.sh "$version"
63+
echo "Triton version: $(./scripts/triton-version.sh)"
64+
65+
- name: Build Triton wheels
66+
run: |
67+
cd ${{ env.NEW_WORKSPACE }}
68+
.venv\Scripts\activate.ps1
69+
Invoke-BatchFile "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
70+
71+
$env:CIBW_BUILD_VERBOSITY = "1"
72+
$env:CIBW_SKIP = "cp{35,36,37}-*"
73+
$env:CIBW_BUILD = "cp" + "${{ matrix.python}}".replace(".", "") + "*-win_amd64"
74+
$env:CIBW_CACHE_PATH = "${{ env.NEW_WORKSPACE }}/cibw"
75+
76+
python -m cibuildwheel --output-dir wheelhouse
77+
78+
- name: Artifact name
79+
run: |
80+
(Get-ChildItem -Path "${{ env.NEW_WORKSPACE }}\wheelhouse\*.whl").Name | Tee-Object -Variable WHEELS_NAME
81+
echo "WHEELS_NAME=$WHEELS_NAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
82+
83+
- name: Upload wheels
84+
uses: actions/upload-artifact@v4
85+
with:
86+
name: ${{ env.WHEELS_NAME }}
87+
path: ${{ env.NEW_WORKSPACE }}\wheelhouse\*.whl
88+
89+
- name: Clean up workspace
90+
if: ${{ always() }}
91+
run: |
92+
Remove-Item -LiteralPath ${{ env.NEW_WORKSPACE }} -Force -Recurse -ErrorAction Ignore
93+
94+
- name: Clean up temporary files
95+
if: ${{ always() }}
96+
shell: bash
97+
run: |
98+
rm -rf rm -rf /tmp/triton-* /tmp/tmp*

scripts/triton-version.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
# Script to get and set Triton version.
4+
# Currently Triton does not have a single file to set a version. There are two files:
5+
# 1. In `setup.py`, the version is set to `{version}+git{sha}` and this version is used for the
6+
# Python package/wheel.
7+
# 2. In `python/triton/__init__.py`, the version is set to `{version}` and used in runtime for
8+
# `triton.__version__`.
9+
# When building a wheel, the both files need to be updated to use the same version.
10+
11+
set -euo pipefail
12+
13+
PROJECT_ROOT="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && cd .. && pwd )"
14+
15+
get_version() {
16+
# Use setup.py, as the most reliable source
17+
sed -n -E "s/^TRITON_VERSION = \"([^\"]+)\".*/\1/p" "$PROJECT_ROOT/setup.py"
18+
}
19+
20+
set_version() {
21+
local version="$1"
22+
sed -i -E "s/^TRITON_VERSION = \"([^\"]+)\".*/TRITON_VERSION = \"$version\"/" "$PROJECT_ROOT/setup.py"
23+
sed -i -E "s/^__version__ = '[^']+'/__version__ = '$version'/" "$PROJECT_ROOT/python/triton/__init__.py"
24+
}
25+
26+
if (( $# == 1 )); then
27+
set_version "$1"
28+
else
29+
get_version
30+
fi

0 commit comments

Comments
 (0)