1
1
name : Python package
2
2
3
3
on :
4
- push : {}
4
+ push :
5
+ branches : [ "main" ]
5
6
pull_request :
6
- branches : [ main ]
7
7
paths :
8
8
- ' .github/workflows/python-package.yml'
9
9
- ' bitsandbytes/**'
@@ -17,153 +17,231 @@ on:
17
17
- ' pytest.ini'
18
18
- ' **/*.md'
19
19
release :
20
+ branches : [ "main" ]
20
21
types : [ published ]
21
22
23
+ concurrency :
24
+ group : cmake-${{ 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
40
- - name : Setup cmake
41
-
42
- with :
43
- cmake-version : ' 3.26.x'
44
- - name : Add msbuild to PATH
45
-
46
- if : ${{ startsWith(matrix.os, 'windows') }}
47
- # Check out dependencies code
48
- - uses : actions/checkout@v4
49
- name : Check out NVidia cub
48
+
49
+ - name : Set up MSVC
50
+ if : matrix.os == 'windows-latest'
51
+
50
52
with :
51
- repository : nvidia/cub
52
- ref : 1.11.0
53
- path : dependencies/cub
54
- # Compile C++ code
55
- - name : Build C++
53
+ arch : amd64
54
+
55
+ - name : Set reusable strings
56
+ # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
57
+ id : strings
56
58
shell : bash
57
59
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 .
67
- else
68
- cmake -DCOMPUTE_BACKEND=cpu .
69
- fi
70
- if [ ${build_os:0:7} == windows ]; then
71
- pwsh -Command "msbuild bitsandbytes.vcxproj /property:Configuration=Release"
60
+ echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
61
+
62
+ - name : Prep build
63
+ run : python3 -m pip install cmake==3.27.9 ninja setuptools wheel
64
+
65
+ - name : Prep Compilers
66
+ shell : bash -el {0}
67
+ run : |
68
+ if [ "${{ matrix.os }}" = "windows-latest" ]; then
69
+ echo CXX_COMPILER=cl >> "$GITHUB_ENV"
72
70
else
73
- make
71
+ echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
74
72
fi
73
+
74
+
75
+ - name : Configure CPU
76
+ run : >
77
+ cmake -B ${{ steps.strings.outputs.build-output-dir }}
78
+ -G Ninja
79
+ -DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
80
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
81
+ -DCOMPUTE_BACKEND=cpu
82
+ -S ${{ github.workspace }}
83
+
84
+ - name : Build CPU
85
+ run : cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
86
+
87
+ - name : Copy libraries
88
+ shell : bash
89
+ run : |
75
90
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
76
91
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
77
92
- name : Upload build artifact
78
93
uses : actions/upload-artifact@v4
79
94
with :
80
- name : shared_library_ ${{ matrix.os }}_ ${{ matrix.arch }}
95
+ name : shared_library- ${{ matrix.os }}- ${{ matrix.arch }}
81
96
path : output/*
82
- retention-days : 7
83
97
# #
84
98
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
85
99
# #
86
100
build-shared-libs-cuda :
87
101
strategy :
102
+ # 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.
103
+ fail-fast : false
104
+
88
105
matrix :
89
106
os : [ubuntu-latest, windows-latest]
107
+ cuda-version : ['11.8', '12.1']
90
108
arch : [x86_64, aarch64]
91
- cuda_version : ['12.1.0' ]
109
+ build_type : [Release ]
92
110
exclude :
93
111
- os : windows-latest # This probably requires arm64 Windows agents
94
112
arch : aarch64
113
+
95
114
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
96
115
steps :
97
116
# Check out code
98
117
- uses : actions/checkout@v4
99
- # Linux: We use Docker to build cross platform Cuda (aarch64 is built in emulation)
100
- - name : Set up Docker multiarch
101
- if : startsWith(matrix.os, 'ubuntu')
102
- uses : docker/setup-qemu-action@v2
103
- # On Linux we use CMake within Docker
104
- - name : Setup cmake
105
- if : ${{ !startsWith(matrix.os, 'linux') }}
106
-
118
+ - name : Set up Python 3.10
119
+ uses : actions/setup-python@v5
107
120
with :
108
- cmake -version : ' 3.26.x '
109
- # Windows: We install Cuda on the agent (slow)
110
-
111
- if : startsWith( matrix.os, 'windows')
112
- id : cuda-toolkit
121
+ python -version : " 3.10 "
122
+
123
+ - name : Set up MSVC
124
+ if : matrix.os == 'windows-latest'
125
+
113
126
with :
114
- cuda : ${{ matrix.cuda_version }}
115
- method : ' local'
116
- # sub-packages: '["nvcc","cudart","nvrtc_dev","cublas_dev","cusparse_dev","visual_studio_integration"]'
117
- - name : Add msbuild to PATH
118
-
119
- if : ${{ startsWith(matrix.os, 'windows') }}
120
- # Check out dependencies code
121
- - uses : actions/checkout@v4
122
- name : Check out NVidia cub
127
+ arch : amd64
128
+
129
+ - name : Setup Mambaforge
130
+ uses :
conda-incubator/[email protected]
123
131
with :
124
- repository : nvidia/cub
125
- ref : 1.11.0
126
- path : dependencies/cub
127
- # Compile C++ code
128
- - name : Build C++
132
+ miniforge-variant : Mambaforge
133
+ miniforge-version : latest
134
+ activate-environment : bnb-env
135
+ use-mamba : true
136
+
137
+ -
uses :
conda-incubator/[email protected]
138
+ with :
139
+ auto-update-conda : true
140
+ activate-environment : bnb-env
141
+ environment-file : environment-bnb.yml
142
+ use-only-tar-bz2 : false
143
+ auto-activate-base : true
144
+ python-version : " 3.10"
145
+ mamba-version : " *"
146
+
147
+ - name : Set reusable strings
148
+ # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file.
149
+ id : strings
150
+ shell : bash
151
+ run : |
152
+ echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT"
153
+
154
+ - name : CUDA Toolkit
155
+ shell : bash -el {0}
156
+ run : |
157
+ if [ "${{ matrix.os }}" = "ubuntu-latest" ]; then
158
+ # to prepare space
159
+ sudo rm -rf /usr/share/dotnet
160
+ sudo rm -rf /opt/ghc
161
+ sudo rm -rf /usr/local/share/boost
162
+ fi
163
+ addon=""
164
+ cuda_version=${{ matrix.cuda-version }}
165
+ [ "$cuda_version" = "12.1" ] && [ "${{ matrix.os }}" = "ubuntu-latest" ] && addon="cuda-cudart-static cuda-nvrtc"
166
+ [ "$cuda_version" = "12.1" ] && [ "${{ matrix.os }}" = "windows-latest" ] && addon="cuda-nvrtc"
167
+ [ "$cuda_version" = "11.8" ] && cuda_version="11.8.0"
168
+ [ "$cuda_version" = "12.1" ] && cuda_version="12.1.1"
169
+
170
+ conda install pytorch-cuda=${{ matrix.cuda-version }} -c pytorch # it's dependency not correctly resolved sometime
171
+ conda install cuda-python=${{ matrix.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"
172
+
173
+ [ "${{ matrix.os }}" = "windows-latest" ] && conda install "clang>=17.0.6" "clangxx>=17.0.6" -c conda-forge
174
+
175
+ CUDA_HOME="${{ env.CONDA }}/envs/bnb-env"
176
+ echo CUDA_HOME=$CUDA_HOME >> "$GITHUB_ENV"
177
+ echo CUDA_PATH=$CUDA_HOME >> "$GITHUB_ENV"
178
+
179
+ if [ "${{ matrix.os }}" = "windows-latest" ]; then
180
+ echo CXX_COMPILER=cl >> "$GITHUB_ENV"
181
+ echo C_COMPILER=cl >> "$GITHUB_ENV"
182
+ # without -DCMAKE_CUDA_COMPILER=nvcc, cmake config always fail for cuda-11.8
183
+ echo DCMAKE_CUDA_COMPILER=-DCMAKE_CUDA_COMPILER=nvcc >> "$GITHUB_ENV"
184
+ else
185
+ echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
186
+ echo C_COMPILER=gcc >> "$GITHUB_ENV"
187
+ fi
188
+
189
+ nvcc --version
190
+
191
+ - name : Update environment
192
+ run : mamba env update -n bnb-env -f environment-bnb.yml
193
+
194
+ - name : Prep build
195
+ run : python -m pip install cmake==3.27.9 ninja setuptools wheel
196
+
197
+ # TODO: the following steps (CUDA, NOBLASLT, CPU) could be moved to the matrix, so they're built in parallel
198
+
199
+ - name : Configure CUDA
200
+ run : >
201
+ cmake -B ${{ steps.strings.outputs.build-output-dir }}
202
+ -G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
203
+ -DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
204
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
205
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
206
+ -DCOMPUTE_BACKEND=cuda
207
+ -S ${{ github.workspace }}
208
+
209
+ - name : Build CUDA
210
+ run : cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
211
+
212
+ - name : Configure NOBLASLT
213
+ run : >
214
+ cmake -B ${{ steps.strings.outputs.build-output-dir }}
215
+ -G Ninja ${{ env.DCMAKE_CUDA_COMPILER }}
216
+ -DCMAKE_CXX_COMPILER=${{ env.CXX_COMPILER }}
217
+ -DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
218
+ -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90"
219
+ -DNO_CUBLASLT=ON
220
+ -S ${{ github.workspace }}
221
+
222
+ - name : Build NOBLASLT
223
+ run : cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
224
+
225
+ - name : Copy libraries
129
226
shell : bash
130
227
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
228
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
149
229
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
150
230
- name : Upload build artifact
151
231
uses : actions/upload-artifact@v4
152
232
with :
153
- name : shared_library_cuda_ ${{ matrix.os }}_ ${{ matrix.arch }}_ ${{ matrix.cuda_version }}
233
+ name : shared_library_cuda- ${{ matrix.os }}- ${{ matrix.cuda-version }}- ${{ matrix.arch }}
154
234
path : output/*
155
- retention-days : 7
156
235
build-wheels :
157
236
needs :
158
237
- build-shared-libs
159
238
- build-shared-libs-cuda
160
239
strategy :
161
240
matrix :
162
241
os : [ubuntu-latest, macos-latest, windows-latest]
163
- python-version : ["3.9", "3.10", "3.11", "3.12"]
164
242
arch : [x86_64, aarch64]
165
243
exclude :
166
- - os : windows-latest # This probably requires arm64 Windows agents
244
+ - os : windows-latest
167
245
arch : aarch64
168
246
runs-on : ${{ matrix.os }}
169
247
steps :
@@ -174,18 +252,18 @@ jobs:
174
252
uses : actions/download-artifact@v4
175
253
with :
176
254
merge-multiple : true
177
- pattern : " shared_library*_ ${{ matrix.os }}_${{ matrix.arch }} *"
255
+ pattern : " shared_library*- ${{ matrix.os }}- *"
178
256
path : output/
179
257
- name : Copy correct platform shared library
180
258
shell : bash
181
259
run : |
182
260
ls -lR output/
183
261
cp output/${{ matrix.os }}/${{ matrix.arch }}/* bitsandbytes/
184
262
# Set up the Python version needed
185
- - name : Set up Python ${{ matrix.python-version }}
263
+ - name : Set up Python 3.10
186
264
uses : actions/setup-python@v5
187
265
with :
188
- python-version : ${{ matrix.python-version }}
266
+ python-version : " 3.10 "
189
267
cache : pip
190
268
- name : Install build package
191
269
shell : bash
@@ -200,13 +278,13 @@ jobs:
200
278
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
201
279
- name : Build wheel
202
280
shell : bash
203
- run : python -m build .
204
- - name : Upload build artifact
281
+ run : python -m build . --wheel
282
+ - name : Upload Build Artifacts
205
283
uses : actions/upload-artifact@v4
206
284
with :
207
- name : bdist_wheel_ ${{ matrix.os }}_ ${{ matrix.arch }}_${{ matrix.python-version }}
208
- path : dist/bitsandbytes-*.whl
209
- retention-days : 7
285
+ name : bdist_wheel- ${{ matrix.os }}- ${{ matrix.arch }}
286
+ path : |
287
+ ${{ github.workspace }}/dist/
210
288
publish :
211
289
needs : build-wheels
212
290
runs-on : ubuntu-latest
@@ -217,7 +295,7 @@ jobs:
217
295
with :
218
296
path : dist/
219
297
merge-multiple : true
220
- pattern : " bdist_wheel_ *"
298
+ pattern : " bdist_wheel- *"
221
299
- run : |
222
300
ls -lR dist/
223
301
- name : Publish to PyPi
0 commit comments