Skip to content

Commit 2ae6487

Browse files
committed
GitHub workflow to build PyTorch wheels
Signed-off-by: Pavel Chekin <[email protected]>
1 parent 9054446 commit 2ae6487

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: PyTorch wheels
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
branches:
7+
- main
8+
paths:
9+
- .github/workflows/wheels-pytorch.yml
10+
- .github/pins/pytorch.txt
11+
push:
12+
branches:
13+
- main
14+
paths:
15+
- .github/workflows/wheels-pytorch.yml
16+
- .github/pins/pytorch.txt
17+
18+
permissions: read-all
19+
20+
env:
21+
NEW_WORKSPACE: C:\gh${{ github.run_id }}
22+
23+
jobs:
24+
windows:
25+
runs-on:
26+
- windows
27+
- b580
28+
strategy:
29+
matrix:
30+
python:
31+
- "3.9"
32+
- "3.10"
33+
- "3.11"
34+
- "3.12"
35+
- "3.13"
36+
fail-fast: false
37+
max-parallel: 2
38+
steps:
39+
- name: Checkout Triton repository
40+
uses: actions/checkout@v4
41+
42+
- name: Setup Python
43+
uses: actions/setup-python@v5
44+
with:
45+
python-version: "3.12"
46+
47+
- name: Clean up old workspaces
48+
shell: bash
49+
run: |
50+
rm -rf /c/gh*
51+
52+
# Copy workspace to a temporary location with a shorter name.
53+
- name: Copy workspace
54+
run: |
55+
Copy-Item -Path ${{ github.workspace }} -Destination ${{ env.NEW_WORKSPACE }} -Recurse
56+
57+
- name: Checkout PyTorch repository
58+
run: |
59+
cd ${{ env.NEW_WORKSPACE }}
60+
$pytorch_commit = Get-Content .github/pins/pytorch.txt
61+
git clone --single-branch -b main --recurse-submodules -j8 https://github.com/pytorch/pytorch.git
62+
cd pytorch
63+
git checkout $pytorch_commit
64+
git submodule update --init --recursive
65+
bash -c '../scripts/patch-pytorch.sh'
66+
67+
- name: Create venv
68+
run: |
69+
cd ${{ env.NEW_WORKSPACE }}
70+
python -m venv .venv
71+
72+
- name: Install build dependencies
73+
run: |
74+
cd ${{ env.NEW_WORKSPACE }}
75+
.venv\Scripts\activate.ps1
76+
cd pytorch
77+
pip install cibuildwheel
78+
79+
- name: Identify runtime dependencies
80+
run: |
81+
cd ${{ env.NEW_WORKSPACE }}
82+
.venv\Scripts\activate.ps1
83+
cd pytorch/.github/scripts
84+
python -c 'from generate_binary_build_matrix import PYTORCH_EXTRA_INSTALL_REQUIREMENTS; print(PYTORCH_EXTRA_INSTALL_REQUIREMENTS["xpu"])' | Tee-Object -Variable PYTORCH_EXTRA_INSTALL_REQUIREMENTS
85+
echo "PYTORCH_EXTRA_INSTALL_REQUIREMENTS=$PYTORCH_EXTRA_INSTALL_REQUIREMENTS" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
86+
87+
- name: Build PyTorch wheels
88+
run: |
89+
cd ${{ env.NEW_WORKSPACE }}
90+
.venv\Scripts\activate.ps1
91+
Invoke-BatchFile "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
92+
93+
cd pytorch
94+
95+
# Required to build on Windows
96+
$env:CMAKE_SHARED_LINKER_FLAGS = "/FORCE:MULTIPLE"
97+
$env:CMAKE_MODULE_LINKER_FLAGS = "/FORCE:MULTIPLE"
98+
$env:CMAKE_EXE_LINKER_FLAGS = "/FORCE:MULTIPLE"
99+
$env:TORCH_XPU_ARCH_LIST = "bmg,dg2,arl-h,mtl-h"
100+
101+
$env:CIBW_BUILD_VERBOSITY = "1"
102+
$env:CIBW_SKIP = "cp{35,36,37}-*"
103+
$env:CIBW_BUILD = "cp" + "${{ matrix.python}}".replace(".", "") + "*-win_amd64"
104+
$env:CIBW_CACHE_PATH = "${{ env.NEW_WORKSPACE }}/cibw"
105+
$env:USE_XCCL = "1"
106+
$env:CIBW_BEFORE_BUILD = "pip install -r requirements.txt"
107+
108+
python -m cibuildwheel --output-dir wheelhouse
109+
110+
- name: Artifact name
111+
run: |
112+
(Get-ChildItem -Path "${{ env.NEW_WORKSPACE }}\pytorch\wheelhouse\*.whl").Name | Tee-Object -Variable WHEELS_NAME
113+
echo "WHEELS_NAME=$WHEELS_NAME" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
114+
115+
- name: Upload wheels
116+
uses: actions/upload-artifact@v4
117+
with:
118+
name: ${{ env.WHEELS_NAME }}
119+
path: ${{ env.NEW_WORKSPACE }}\pytorch\wheelhouse\*.whl
120+
121+
- name: Clean up workspace
122+
if: ${{ always() }}
123+
run: |
124+
Remove-Item -LiteralPath ${{ env.NEW_WORKSPACE }} -Force -Recurse -ErrorAction Ignore
125+
126+
- name: Clean up temporary files
127+
if: ${{ always() }}
128+
shell: bash
129+
run: |
130+
rm -rf rm -rf /tmp/triton-* /tmp/tmp*

0 commit comments

Comments
 (0)