1
1
name : Python package
2
2
3
3
on :
4
- push : {}
5
- pull_request :
4
+ push :
6
5
branches : [ main ]
6
+ pull_request :
7
7
paths :
8
8
- ' .github/workflows/python-package.yml'
9
9
- ' bitsandbytes/**'
17
17
- ' pytest.ini'
18
18
- ' **/*.md'
19
19
release :
20
+ branches : [ main ]
20
21
types : [ published ]
21
22
23
+ concurrency :
24
+ group : ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25
+ cancel-in-progress : true
26
+
22
27
jobs :
23
28
24
29
# #
25
30
# This job matrix builds the non-CUDA versions of the libraries for all supported platforms.
26
31
# #
27
32
build-shared-libs :
28
33
strategy :
34
+ # 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.
35
+ fail-fast : false
36
+
29
37
matrix :
30
38
os : [ubuntu-latest, macos-latest, windows-latest]
31
39
arch : [x86_64, aarch64]
40
+ build_type : [Release]
32
41
exclude :
33
42
- os : windows-latest # This probably requires arm64 Windows agents
34
43
arch : aarch64
35
44
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
36
45
steps :
37
46
# Check out code
38
47
- uses : actions/checkout@v4
39
- # On Linux we use CMake within Docker
48
+ - name : Allow cross-compile on aarch64
49
+ if : ${{ startsWith(matrix.os, 'ubuntu') && matrix.arch == 'aarch64' }}
50
+ run : |
51
+ # Allow cross-compile on aarch64
52
+ sudo apt-get install -y g++-aarch64-linux-gnu binutils-aarch64-linux-gnu
53
+
40
54
- name : Setup cmake
41
55
uses : jwlawson/actions-setup-cmake@v1.14
42
56
with :
43
57
cmake-version : ' 3.26.x'
44
- - name : Add msbuild to PATH
45
- uses : microsoft/setup-msbuild@v1.1
46
- if : ${{ startsWith(matrix.os, 'windows') }}
58
+ - name : Setup MSVC
59
+ if : startsWith(matrix.os, 'windows')
60
+ # uses: microsoft/setup-msbuild@v1.1 # to use msbuild
61
+ uses : ilammy/msvc-dev-cmd@v1.13.0 # to use cl
47
62
# Check out dependencies code
48
63
- uses : actions/checkout@v4
49
64
name : Check out NVidia cub
50
65
with :
51
66
repository : nvidia/cub
52
67
ref : 1.11.0
53
68
path : dependencies/cub
54
- # Compile C++ code
55
- - name : Build C++
56
- shell : bash
69
+
70
+ - name : Prep Compilers
71
+ shell : bash -el {0}
57
72
run : |
58
- set -ex
59
- build_os=${{ matrix.os }}
60
- build_arch=${{ matrix.arch }}
61
- if [ ${build_os:0:6} == ubuntu -a ${build_arch} == aarch64 ]; then
62
- # Allow cross-compile om aarch64
63
- sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
64
- fi
65
- if [ ${build_os:0:5} == macos -a ${build_arch} == aarch64 ]; then
66
- cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCOMPUTE_BACKEND=cpu .
73
+ python3 -m pip install cmake==3.27.9 ninja
74
+ if [[ "${{ matrix.os }}" = windows-* ]]; then
75
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV"
76
+ elif [[ "${{ matrix.os }}" = ubuntu-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
77
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ >> "$GITHUB_ENV"
67
78
else
68
- cmake -DCOMPUTE_BACKEND=cpu .
79
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV"
69
80
fi
70
- if [ ${build_os:0:7} == windows ]; then
71
- pwsh -Command "msbuild bitsandbytes.vcxproj /property:Configuration=Release"
72
- else
73
- make
81
+
82
+ if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
83
+ echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV"
74
84
fi
85
+
86
+ - name : Build CPU
87
+ shell : bash -el {0}
88
+ run : |
89
+ cmake -B build \
90
+ -G Ninja ${{ env.DCMAKE_OSX_ARCHITECTURES }} \
91
+ ${{ env.CXX_COMPILER }} \
92
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
93
+ -DCOMPUTE_BACKEND=cpu \
94
+ -S .
95
+
96
+ cmake --build build --config ${{ matrix.build_type }}
97
+
75
98
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
99
+ ls -l bitsandbytes
100
+ echo " check lib files..."
101
+ file bitsandbytes/libbitsandbytes*.*
76
102
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
77
103
- name : Upload build artifact
78
104
uses : actions/upload-artifact@v4
79
105
with :
80
106
name : shared_library_${{ matrix.os }}_${{ matrix.arch }}
81
107
path : output/*
82
- retention-days : 7
83
108
# #
84
109
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
85
110
# #
86
111
build-shared-libs-cuda :
87
112
strategy :
113
+ # 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.
114
+ fail-fast : false
115
+
88
116
matrix :
89
117
os : [ubuntu-latest, windows-latest]
90
118
arch : [x86_64, aarch64]
91
- cuda_version : ['12.1.0']
119
+ cuda-version : ['11.8.0', '12.1.1']
120
+ build_type : [Release]
92
121
exclude :
93
122
- os : windows-latest # This probably requires arm64 Windows agents
94
123
arch : aarch64
@@ -102,65 +131,154 @@ jobs:
102
131
uses : docker/setup-qemu-action@v2
103
132
# On Linux we use CMake within Docker
104
133
- name : Setup cmake
105
- if : ${{ !startsWith(matrix.os, 'linux ') }}
134
+ if : ${{ !startsWith(matrix.os, 'ubuntu ') }}
106
135
uses : jwlawson/actions-setup-cmake@v1.14
107
136
with :
108
137
cmake-version : ' 3.26.x'
109
138
# Windows: We install Cuda on the agent (slow)
139
+ # it is too slow and sometime break
110
140
- uses : Jimver/cuda-toolkit@v0.2.14
111
- if : startsWith(matrix.os, 'windows')
141
+ if : startsWith(matrix.os, 'x') # disabled
112
142
id : cuda-toolkit
113
143
with :
114
144
cuda : ${{ matrix.cuda_version }}
115
145
method : ' local'
116
146
# sub-packages: '["nvcc","cudart","nvrtc_dev","cublas_dev","cusparse_dev","visual_studio_integration"]'
117
- - name : Add msbuild to PATH
118
- uses : microsoft/setup-msbuild@v1.1
119
- if : ${{ startsWith(matrix.os, 'windows') }}
147
+ - name : Set up Python 3.10
148
+ uses : actions/setup-python@v5
149
+ with :
150
+ python-version : " 3.10"
151
+
152
+ - name : Setup MSVC
153
+ if : startsWith(matrix.os, 'windows')
154
+ # uses: microsoft/setup-msbuild@v1.1 # to use msbuild
155
+ uses : ilammy/msvc-dev-cmd@v1.13.0 # to use cl
120
156
# Check out dependencies code
121
157
- uses : actions/checkout@v4
122
158
name : Check out NVidia cub
123
159
with :
124
160
repository : nvidia/cub
125
161
ref : 1.11.0
126
162
path : dependencies/cub
127
- # Compile C++ code
128
- - name : Build C++
163
+ - name : Setup Mambaforge
164
+ if : startsWith(matrix.os, 'windows')
165
+ uses : conda-incubator/setup-miniconda@v3.0.1
166
+ with :
167
+ miniforge-variant : Mambaforge
168
+ miniforge-version : latest
169
+ activate-environment : bnb-env
170
+ use-mamba : true
171
+
172
+ - uses : conda-incubator/setup-miniconda@v3.0.1
173
+ if : startsWith(matrix.os, 'windows')
174
+ with :
175
+ auto-update-conda : true
176
+ activate-environment : bnb-env
177
+ environment-file : environment-bnb.yml
178
+ use-only-tar-bz2 : false
179
+ auto-activate-base : true
180
+ python-version : " 3.10"
181
+ mamba-version : " *"
182
+
183
+ - name : Setup CUDA
184
+ if : startsWith(matrix.os, 'windows')
185
+ shell : bash -el {0}
186
+ run : |
187
+ addon=""
188
+ cuda_version=${{ matrix.cuda-version }}
189
+ [[ "$cuda_version" = 12.1.* ]] && [[ "${{ matrix.os }}" = ubuntu-* ]] && addon="cuda-cudart-static cuda-nvrtc"
190
+ [[ "$cuda_version" = 11.8.* ]] && [[ "${{ matrix.os }}" = windows-* ]] && addon="cuda-nvrtc"
191
+ [[ "$cuda_version" = 11.8.* ]] && cuda__version="11.8"
192
+ [[ "$cuda_version" = 12.1.* ]] && cuda__version="12.1"
193
+
194
+ conda install pytorch-cuda=$cuda__version -c pytorch # it's dependency not correctly resolved sometime
195
+ 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"
196
+
197
+ CUDA_HOME="${{ env.CONDA }}/envs/bnb-env"
198
+ echo CUDA_HOME=$CUDA_HOME >> "$GITHUB_ENV"
199
+ echo CUDA_PATH=$CUDA_HOME >> "$GITHUB_ENV"
200
+
201
+ if [[ "${{ matrix.os }}" = windows-* ]]; then
202
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV"
203
+ # without -DCMAKE_CUDA_COMPILER=nvcc, cmake config always fail for cuda-11.8
204
+ echo DCMAKE_CUDA_COMPILER=-DCMAKE_CUDA_COMPILER=nvcc >> "$GITHUB_ENV"
205
+ else
206
+ echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV"
207
+ fi
208
+
209
+ if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then
210
+ echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV"
211
+ fi
212
+
213
+ nvcc --version
214
+
215
+ - name : Update environment
216
+ if : startsWith(matrix.os, 'windows')
217
+ run : mamba env update -n bnb-env -f environment-bnb.yml
218
+
219
+ - name : Prep build
220
+ if : startsWith(matrix.os, 'windows')
221
+ run : python -m pip install cmake==3.27.9 ninja
222
+
223
+ - name : Build CUDA
224
+ if : startsWith(matrix.os, 'windows')
225
+ shell : bash -el {0}
226
+ run : |
227
+ cmake -B build \
228
+ -G Ninja ${{ env.DCMAKE_CUDA_COMPILER }} \
229
+ ${{ env.CXX_COMPILER }} \
230
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
231
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \
232
+ -DCOMPUTE_BACKEND=cuda \
233
+ -S .
234
+
235
+ cmake --build build --config ${{ matrix.build_type }}
236
+
237
+ - name : Build CUDA (docker)
238
+ if : startsWith(matrix.os, 'ubuntu')
239
+ uses : addnab/docker-run-action@v3
240
+ with :
241
+ image : ${{ format('nvidia/cuda:{0}-{1}', matrix.cuda-version, 'devel-ubuntu22.04') }}
242
+ options : --platform linux/${{ matrix.arch }} -w /src -v ${{ github.workspace }}:/src
243
+ run : |
244
+ apt-get update
245
+ DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake python3 python3-pip
246
+ # install cmake, ninja to prepare cmake
247
+ python3 -m pip install cmake==3.27.9 ninja
248
+
249
+ for NO_CUBLASLT in OFF ON; do
250
+ cmake -B build \
251
+ -G Ninja \
252
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
253
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \
254
+ -DCOMPUTE_BACKEND=cuda \
255
+ -DNO_CUBLASLT=$NO_CUBLAST \
256
+ -S .
257
+
258
+ cmake --build build --config ${{ matrix.build_type }}
259
+ done
260
+
261
+ - name : Copy libraries
129
262
shell : bash
130
263
run : |
131
- set -ex
132
- build_os=${{ matrix.os }}
133
- build_arch=${{ matrix.arch }}
134
- for NO_CUBLASLT in ON OFF; do
135
- if [ ${build_os:0:6} == ubuntu ]; then
136
- image=nvidia/cuda:${{ matrix.cuda_version }}-devel-ubuntu22.04
137
- echo "Using image $image"
138
- docker run --platform linux/$build_arch -i -w /src -v $PWD:/src $image sh -c \
139
- "apt-get update \
140
- && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake \
141
- && cmake -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} . \
142
- && make"
143
- else
144
- cmake -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} .
145
- pwsh -Command "msbuild bitsandbytes.vcxproj /property:Configuration=Release"
146
- fi
147
- done
148
264
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
265
+ echo " check lib files..."
266
+ file bitsandbytes/libbitsandbytes*.*
149
267
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
150
268
- name : Upload build artifact
151
269
uses : actions/upload-artifact@v4
152
270
with :
153
- name : shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda_version }}
271
+ name : shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda-version }}
154
272
path : output/*
155
- retention-days : 7
273
+
156
274
build-wheels :
157
275
needs :
158
276
- build-shared-libs
159
277
- build-shared-libs-cuda
160
278
strategy :
161
279
matrix :
162
280
os : [ubuntu-latest, macos-latest, windows-latest]
163
- python-version : ["3.9", "3.10", "3.11", "3.12 "]
281
+ python-version : ["3.10 "]
164
282
arch : [x86_64, aarch64]
165
283
exclude :
166
284
- os : windows-latest # This probably requires arm64 Windows agents
@@ -200,13 +318,19 @@ jobs:
200
318
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
201
319
- name : Build wheel
202
320
shell : bash
203
- run : python -m build .
321
+ run : |
322
+ python -m build . --wheel
323
+ # fix wheel name
324
+ if [ "${{ matrix.arch }}" = "aarch64" ]; then
325
+ o=$(ls dist/*.whl)
326
+ n=$(echo $o | sed 's@_x86_64@_aarch64@')
327
+ [ "$n" != "$o" ] && mv $o $n
328
+ fi
204
329
- name : Upload build artifact
205
330
uses : actions/upload-artifact@v4
206
331
with :
207
- name : bdist_wheel_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.python-version }}
208
- path : dist/bitsandbytes-*.whl
209
- retention-days : 7
332
+ name : bdist_wheel_${{ matrix.os }}-${{ matrix.arch }}
333
+ path : ${{ github.workspace }}/dist/bitsandbytes-*.whl
210
334
publish :
211
335
needs : build-wheels
212
336
runs-on : ubuntu-latest
0 commit comments