-
Notifications
You must be signed in to change notification settings - Fork 651
441 lines (394 loc) · 15.6 KB
/
python-package.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
name: Python package
on:
push:
branches: [ main ]
pull_request:
paths:
- '.github/workflows/python-package.yml'
- 'bitsandbytes/**'
- 'csrc/**'
- 'include/**'
- 'tests/**'
- 'CMakeLists.txt'
- 'requirements*.txt'
- 'setup.py'
- 'pyproject.toml'
- 'pytest.ini'
- '**/*.md'
release:
branches: [ main ]
types: [ published ]
concurrency:
group: cmake-${{ github.ref }}
cancel-in-progress: true
jobs:
##
# This job matrix builds the non-CUDA versions of the libraries for all supported platforms.
##
build-shared-libs:
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [x86_64, aarch64]
build_type: [Release]
exclude:
- os: windows-latest # This probably requires arm64 Windows agents
arch: aarch64
runs-on: ${{ matrix.os }} # One day, we could run them on native agents. Azure supports this now but it's planned only for Q3 2023 for hosted agents
steps:
# Check out code
- uses: actions/checkout@v4
- name: Allow cross-compile on aarch64
if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' }}
run: |
# Allow cross-compile on aarch64
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'
- name: Set up MSVC
if: startsWith(matrix.os, 'windows')
uses: ilammy/[email protected]
# Check out dependencies code
- uses: actions/checkout@v4
name: Check out NVidia cub
with:
repository: nvidia/cub
ref: 1.11.0
path: dependencies/cub
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Prep Compilers
shell: bash -el {0}
run: |
python3 -m pip install cmake==3.27.9 ninja
if [ "${{ matrix.os }}" = "windows-latest" ]; then
echo CXX_COMPILER=cl >> "$GITHUB_ENV"
else
echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
fi
if [ "${{ matrix.os }}" = "macos-latest" -a "${{ matrix.arch }}" == "aarch64" ]; then
echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV"
fi
- name: Configure CPU
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja ${{ env.DCMAKE_OSX_ARCHITECTURES }}
-DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCOMPUTE_BACKEND=cpu
-S ${{ github.workspace }}
- name: Build CPU
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Copy libraries
shell: bash
run: |
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: shared_library_${{ matrix.os }}_${{ matrix.arch }}
path: output/*
##
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Windows)
##
build-shared-libs-cuda:
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
matrix:
os: [windows-latest]
arch: [x86_64]
cuda-version: ['11.8.0', '12.1.1']
build_type: [Release]
runs-on: ${{ matrix.os }} # One day, we could run them on native agents. Azure supports this now but it's planned only for Q3 2023 for hosted agents
steps:
# Check out code
- uses: actions/checkout@v4
# Linux: We use Docker to build cross platform Cuda (aarch64 is built in emulation)
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Set up MSVC
if: startsWith(matrix.os, 'windows')
uses: ilammy/[email protected]
# Check out dependencies code
- uses: actions/checkout@v4
name: Check out NVidia cub
with:
repository: nvidia/cub
ref: 1.11.0
path: dependencies/cub
- name: Setup Mambaforge
uses: conda-incubator/[email protected]
with:
miniforge-variant: Mambaforge
miniforge-version: latest
activate-environment: bnb-env
use-mamba: true
- uses: conda-incubator/[email protected]
with:
auto-update-conda: true
activate-environment: bnb-env
environment-file: environment-bnb.yml
use-only-tar-bz2: false
auto-activate-base: true
python-version: "3.10"
mamba-version: "*"
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Allow cross-compile on aarch64
if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' }}
run: |
# Allow cross-compile on aarch64
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
- name: CUDA Toolkit
shell: bash -el {0}
run: |
if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
# to prepare space
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf /usr/local/share/boost
fi
addon=""
cuda_version=${{ matrix.cuda-version }}
[ "$cuda_version" = "12.1.1" ] && [ "${{ matrix.os }}" = "ubuntu-latest" ] && addon="cuda-cudart-static cuda-nvrtc"
[ "$cuda_version" = "11.8.0" ] && [ "${{ matrix.os }}" = "windows-latest" ] && addon="cuda-nvrtc"
[ "$cuda_version" = "11.8.0" ] && cuda__version="11.8"
[ "$cuda_version" = "12.1.1" ] && cuda__version="12.1"
conda install pytorch-cuda=$cuda__version -c pytorch # it's dependency not correctly resolved sometime
conda install cuda-python=$cuda__version cuda-libraries-dev cuda-nvcc cuda-nvtx cuda-cupti cuda-cudart cuda-cudart-dev cuda-runtime cuda-libraries $addon -c "nvidia/label/cuda-$cuda_version"
CUDA_HOME="${{ env.CONDA }}/envs/bnb-env"
echo CUDA_HOME=$CUDA_HOME >> "$GITHUB_ENV"
echo CUDA_PATH=$CUDA_HOME >> "$GITHUB_ENV"
if [ "${{ matrix.os }}" = "windows-latest" ]; then
echo CXX_COMPILER=cl >> "$GITHUB_ENV"
# without -DCMAKE_CUDA_COMPILER=nvcc, cmake config always fail for cuda-11.8
echo DCMAKE_CUDA_COMPILER=-DCMAKE_CUDA_COMPILER=nvcc >> "$GITHUB_ENV"
else
echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
fi
nvcc --version
- name: Update environment
run: mamba env update -n bnb-env -f environment-bnb.yml
- name: Prep build
run: python -m pip install cmake==3.27.9 ninja
# TODO: the following steps (CUDA, NOBLASLT, CPU) could be moved to the matrix, so they're built in parallel
- name: Configure CUDA
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
-DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
-DCOMPUTE_BACKEND=cuda
-S ${{ github.workspace }}
- name: Build CUDA
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Configure NOBLASLT
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
-DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
-DCOMPUTE_BACKEND=cuda
-DNO_CUBLASLT=ON
-S ${{ github.workspace }}
- name: Build NOBLASLT
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Copy libraries
shell: bash
run: |
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda-version }}
path: output/*
##
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64)
##
build-shared-libs-cuda-docker:
strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64, aarch64]
cuda-version: ['11.8.0', '12.1.1']
build_type: [Release]
exclude:
- os: windows-latest # This probably requires arm64 Windows agents
arch: aarch64
runs-on: ${{ matrix.os }} # One day, we could run them on native agents. Azure supports this now but it's planned only for Q3 2023 for hosted agents
container:
image: ${{ matrix.os == 'windows-latest' && 'null' || format('nvidia/cuda:{0}-{1}', matrix.cuda-version, 'devel-ubuntu22.04') }}
volumes:
- /home/runner/work:/home/runner/work
steps:
# Check out code
- uses: actions/checkout@v4
# Linux: We use Docker to build cross platform Cuda (aarch64 is built in emulation)
- name: Setup cmake
uses: jwlawson/[email protected]
with:
cmake-version: '3.26.x'
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Setup Docker image
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
apt-get update
DEBIAN_FRONTEND=noninteractive apt-get install -y sudo cmake
- name: Set reusable strings
# Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
id: strings
shell: bash
run: |
echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
- name: Allow cross-compile on aarch64
if: ${{ matrix.os == 'ubuntu-latest' && matrix.arch == 'aarch64' }}
run: |
# Allow cross-compile on aarch64
sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
- name: CUDA Toolkit
shell: bash -el {0}
run: |
cuda_version=${{ matrix.cuda-version }}
[ "$cuda_version" = "11.8.0" ] && cuda__version="11.8"
[ "$cuda_version" = "12.1.1" ] && cuda__version="12.1"
CUDA_HOME="${{ env.CONDA }}/envs/bnb-env"
echo CUDA_HOME=$CUDA_HOME >> "$GITHUB_ENV"
echo CUDA_PATH=$CUDA_HOME >> "$GITHUB_ENV"
echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
nvcc --version
- name: Prep build
run: python -m pip install cmake==3.27.9 ninja
# TODO: the following steps (CUDA, NOBLASLT, CPU) could be moved to the matrix, so they're built in parallel
- name: Configure CUDA
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
-DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
-DCOMPUTE_BACKEND=cuda
-S ${{ github.workspace }}
- name: Build CUDA
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Configure NOBLASLT
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
-DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
-DCOMPUTE_BACKEND=cuda
-DNO_CUBLASLT=ON
-S ${{ github.workspace }}
- name: Build NOBLASLT
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
- name: Copy libraries
shell: bash
run: |
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda-version }}
path: output/*
build-wheels:
needs:
- build-shared-libs
- build-shared-libs-cuda
- build-shared-libs-cuda-docker
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
arch: [x86_64, aarch64]
exclude:
- os: windows-latest # This probably requires arm64 Windows agents
arch: aarch64
runs-on: ${{ matrix.os }}
steps:
# Check out code
- uses: actions/checkout@v4
# Download shared libraries
- name: Download build artifact
uses: actions/download-artifact@v4
with:
merge-multiple: true
pattern: "shared_library*_${{ matrix.os }}_${{ matrix.arch }}*"
path: output/
- name: Copy correct platform shared library
shell: bash
run: |
ls -lR output/
cp output/${{ matrix.os }}/${{ matrix.arch }}/* bitsandbytes/
# Set up the Python version needed
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: pip
- name: Install build package
shell: bash
run: pip install build
- name: Install Python test dependencies
shell: bash
run: pip install -r requirements-ci.txt
# TODO: How to run CUDA tests on GitHub actions?
#- name: Run unit tests
# if: ${{ matrix.arch == 'x86_64' }} # Tests are too slow to run in emulation. Wait for real aarch64 agents
# run: |
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
- name: Build wheel
shell: bash
run: python -m build . --wheel
- name: Upload build artifact
uses: actions/upload-artifact@v4
with:
name: bdist_wheel_${{ matrix.os }}-${{ matrix.arch }}
path: ${{ github.workspace }}/dist/bitsandbytes-*.whl
publish:
needs: build-wheels
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download build artifact
uses: actions/download-artifact@v4
with:
path: dist/
merge-multiple: true
pattern: "bdist_wheel_*"
- run: |
ls -lR dist/
- name: Publish to PyPi
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.pypi }}