Skip to content

Commit b0fedba

Browse files
committed
CI: restore some accidentally removed stuff and fix miscs.
* fix to support cmake -B build option * add cuda 11.8, 12.1 * use python-version==3.10 for builds. * fix wheel names for aarch64 * use conda+mamba method. disable cuda-toolkits * make wheel with all available cuda versions. * use docker-run-actions * update docker image version * drop artifact retention-days: it could be configured Settings->Actions->General.
1 parent 63c951d commit b0fedba

File tree

1 file changed

+180
-56
lines changed

1 file changed

+180
-56
lines changed

.github/workflows/python-package.yml

+180-56
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
name: Python package
22

33
on:
4-
push: {}
5-
pull_request:
4+
push:
65
branches: [ main ]
6+
pull_request:
77
paths:
88
- '.github/workflows/python-package.yml'
99
- 'bitsandbytes/**'
@@ -17,78 +17,107 @@ on:
1717
- 'pytest.ini'
1818
- '**/*.md'
1919
release:
20+
branches: [ main ]
2021
types: [ published ]
2122

23+
concurrency:
24+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
25+
cancel-in-progress: true
26+
2227
jobs:
2328

2429
##
2530
# This job matrix builds the non-CUDA versions of the libraries for all supported platforms.
2631
##
2732
build-shared-libs:
2833
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+
2937
matrix:
3038
os: [ubuntu-latest, macos-latest, windows-latest]
3139
arch: [x86_64, aarch64]
40+
build_type: [Release]
3241
exclude:
3342
- os: windows-latest # This probably requires arm64 Windows agents
3443
arch: aarch64
3544
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
3645
steps:
3746
# Check out code
3847
- 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+
4054
- name: Setup cmake
4155
uses: jwlawson/actions-setup-cmake@v1.14
4256
with:
4357
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
4762
# Check out dependencies code
4863
- uses: actions/checkout@v4
4964
name: Check out NVidia cub
5065
with:
5166
repository: nvidia/cub
5267
ref: 1.11.0
5368
path: dependencies/cub
54-
# Compile C++ code
55-
- name: Build C++
56-
shell: bash
69+
70+
- name: Prep Compilers
71+
shell: bash -el {0}
5772
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"
6778
else
68-
cmake -DCOMPUTE_BACKEND=cpu .
79+
echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV"
6980
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"
7484
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+
7598
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
99+
ls -l bitsandbytes
100+
echo " check lib files..."
101+
file bitsandbytes/libbitsandbytes*.*
76102
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
77103
- name: Upload build artifact
78104
uses: actions/upload-artifact@v4
79105
with:
80106
name: shared_library_${{ matrix.os }}_${{ matrix.arch }}
81107
path: output/*
82-
retention-days: 7
83108
##
84109
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
85110
##
86111
build-shared-libs-cuda:
87112
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+
88116
matrix:
89117
os: [ubuntu-latest, windows-latest]
90118
arch: [x86_64, aarch64]
91-
cuda_version: ['12.1.0']
119+
cuda-version: ['11.8.0', '12.1.1']
120+
build_type: [Release]
92121
exclude:
93122
- os: windows-latest # This probably requires arm64 Windows agents
94123
arch: aarch64
@@ -102,65 +131,154 @@ jobs:
102131
uses: docker/setup-qemu-action@v2
103132
# On Linux we use CMake within Docker
104133
- name: Setup cmake
105-
if: ${{ !startsWith(matrix.os, 'linux') }}
134+
if: ${{ !startsWith(matrix.os, 'ubuntu') }}
106135
uses: jwlawson/actions-setup-cmake@v1.14
107136
with:
108137
cmake-version: '3.26.x'
109138
# Windows: We install Cuda on the agent (slow)
139+
# it is too slow and sometime break
110140
- uses: Jimver/cuda-toolkit@v0.2.14
111-
if: startsWith(matrix.os, 'windows')
141+
if: startsWith(matrix.os, 'x') # disabled
112142
id: cuda-toolkit
113143
with:
114144
cuda: ${{ matrix.cuda_version }}
115145
method: 'local'
116146
# 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
120156
# Check out dependencies code
121157
- uses: actions/checkout@v4
122158
name: Check out NVidia cub
123159
with:
124160
repository: nvidia/cub
125161
ref: 1.11.0
126162
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
129262
shell: bash
130263
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
148264
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
265+
echo " check lib files..."
266+
file bitsandbytes/libbitsandbytes*.*
149267
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
150268
- name: Upload build artifact
151269
uses: actions/upload-artifact@v4
152270
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 }}
154272
path: output/*
155-
retention-days: 7
273+
156274
build-wheels:
157275
needs:
158276
- build-shared-libs
159277
- build-shared-libs-cuda
160278
strategy:
161279
matrix:
162280
os: [ubuntu-latest, macos-latest, windows-latest]
163-
python-version: ["3.9", "3.10", "3.11", "3.12"]
281+
python-version: ["3.10"]
164282
arch: [x86_64, aarch64]
165283
exclude:
166284
- os: windows-latest # This probably requires arm64 Windows agents
@@ -200,13 +318,19 @@ jobs:
200318
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
201319
- name: Build wheel
202320
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
204329
- name: Upload build artifact
205330
uses: actions/upload-artifact@v4
206331
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
210334
publish:
211335
needs: build-wheels
212336
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)