-
Notifications
You must be signed in to change notification settings - Fork 7
247 lines (215 loc) · 7.12 KB
/
build_wheels.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
name: Build Wheels
on:
workflow_dispatch:
inputs:
repo:
description: "Repository name with owner, as in actions/checkout"
required: true
type: string
repo-tag:
description: "Repository tag, as in actions/checkout"
type: string
repo-subdir:
description: "Relative path to package dir (or empty if root)"
type: string
torch-version:
description: "Torch versions, separated with a comma"
required: true
type: string
limit-python:
description: "Python versions, separated with a comma"
type: string
limit-compute-platform:
description: "PyTorch compute platforms, separated with a comma"
type: string
include-hash:
description: "Include commit hash in version"
type: boolean
default: false
linux-wheels:
description: "Build Linux wheels"
type: boolean
default: true
windows-wheels:
description: "Build Windows wheels"
type: boolean
default: true
macos-wheels:
description: "Build MacOS wheels"
type: boolean
default: true
jobs:
get-jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Checkout package repository
uses: actions/checkout@v4
- name: Set job matrix
id: job-matrix
env:
TORCH_VERSION: ${{ inputs.torch-version }}
LIMIT_PYTHON: ${{ inputs.limit-python }}
LIMIT_COMPUTE_PLATFORM: ${{ inputs.limit-compute-platform }}
LINUX_WHEELS: ${{ inputs.linux-wheels }}
WINDOWS_WHEELS: ${{ inputs.windows-wheels }}
MACOS_WHEELS: ${{ inputs.macos-wheels }}
run: |
set -eu
echo "matrix=$(python get_jobs.py)" >> $GITHUB_OUTPUT
outputs:
matrix: ${{ steps.job-matrix.outputs.matrix }}
build-wheels:
needs: get-jobs
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.get-jobs.outputs.matrix) }}
steps:
- name: Checkout package repository
uses: actions/checkout@v4
with:
repository: ${{ inputs.repo }}
ref: ${{ inputs.repo-tag }}
sparse-checkout: ${{ inputs.repo-subdir }}
# To overcome Windows path length problems
- name: Move files
if: ${{ inputs.repo-subdir != '' }}
env:
SUBDIR: ${{ inputs.repo-subdir }}
run: |
shopt -s dotglob
mv $SUBDIR _tmp
rm -R ${SUBDIR%%/*}
mv -f _tmp/* .
rm -R _tmp
shell: bash
- name: Set version suffix in setup.py
run: |
set -eu
I_ARG=""
if [[ "${{ runner.os }}" == "macOS" ]]; then
I_ARG="''"
fi
HASH=""
if [[ "${{ inputs.include-hash }}" == "true" ]]; then
HASH=$(git rev-parse --short HEAD)
fi
VERSION_SUFFIX=+${HASH}pt${{ matrix.torch-version }}${{ matrix.compute-platform }}
sed -i $I_ARG "s/\( version=\)\(.*\)\(\,$\)/\1\2 + \"$VERSION_SUFFIX\"\3/" setup.py
shell: bash
- name: Checkout
uses: actions/checkout@v4
with:
path: _builder
- name: Install CUDA
if: ${{ matrix.compute-platform != 'cpu' }}
env:
CUDA_VERSION: ${{ matrix.compute-platform }}
run: |
source _builder/.github/workflows/cuda/${{ runner.os }}_install.sh
shell: bash
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install PyTorch ${{ matrix.torch-version }}+${{ matrix.compute-platform }}
run: |
versionlte() {
[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
versionlt() {
[ "$1" = "$2" ] && return 1 || versionlte $1 $2
}
SETUPTOOLS_VERSION_LIMIT=""
if versionlt ${{ matrix.torch-version }} "2.2.0" ; then
SETUPTOOLS_VERSION_LIMIT="<70"
fi
NUMPY_VERSION_LIMIT=""
if versionlt ${{ matrix.torch-version }} "2.4.0" ; then
NUMPY_VERSION_LIMIT="<2"
fi
pip install --upgrade \
wheel \
setuptools$SETUPTOOLS_VERSION_LIMIT \
build \
--extra-index-url https://download.pytorch.org/whl/${{ matrix.compute-platform }} \
torch==${{ matrix.torch-version }} \
ninja \
numpy$NUMPY_VERSION_LIMIT
shell: bash
- name: Apply package specific steps
env:
OS: ${{ runner.os }}
REPO: ${{ inputs.repo }}
TORCH_VERSION: ${{ matrix.torch-version }}
PYTHON_VERSION: ${{ matrix.python-version }}
COMPUTE_PLATFORM: ${{ matrix.compute-platform }}
run: bash _builder/package_specific.sh
shell: bash
- name: Build CPU wheel
if: ${{ matrix.compute-platform == 'cpu' }}
env:
OS: ${{ runner.os }}
run: |
source _builder/.github/workflows/env.sh
python -m build --wheel --no-isolation --outdir dist
shell: bash
- name: Build CUDA wheel
if: ${{ matrix.compute-platform != 'cpu' }}
env:
OS: ${{ runner.os }}
CUDA_VERSION: ${{ matrix.compute-platform }}
run: |
source _builder/.github/workflows/cuda/${{ runner.os }}_env.sh
source _builder/.github/workflows/env.sh
python -m build --wheel --no-isolation --outdir dist
shell: bash
- uses: actions/upload-artifact@v4
name: Upload wheels as artifacts
with:
name: wheel-${{ matrix.os }}-py${{ matrix.python-version }}-pt${{ matrix.torch-version }}-${{ matrix.compute-platform }}
path: dist/*.whl
compression-level: 0
retention-days: 7
if-no-files-found: error
create-release:
needs: build-wheels
runs-on: ubuntu-latest
permissions:
contents: write
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Get wheels from artifacts
uses: actions/download-artifact@v4
with:
pattern: wheel-*
merge-multiple: true
- name: Get release name
id: data
run: |
set -eu
wheels=(*.whl)
wheel=${wheels[0]}
release_name=${wheel%%+*}
if [[ "${{ inputs.include-hash }}" == "true" ]]; then
after_plus=${wheel##*+}
hash=${after_plus:0:7}
release_name="${release_name}+${hash}"
fi
echo "release_name=${release_name}" >> $GITHUB_OUTPUT
- uses: ncipollo/release-action@v1
with:
tag: ${{ steps.data.outputs.release_name }}
artifacts: "*.whl"
allowUpdates: true
make-packages-index:
needs: create-release
permissions:
pages: write
id-token: write
if: ${{ github.ref == 'refs/heads/main' }}
uses: ./.github/workflows/make_packages_index.yml