Skip to content

Commit c4f0b37

Browse files
committed
CI: revert already merged stuff, accidentally reverted by PR bitsandbytes-foundation#949 without reason.
1 parent 54cbd25 commit c4f0b37

File tree

1 file changed

+171
-93
lines changed

1 file changed

+171
-93
lines changed

.github/workflows/python-package.yml

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

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

23+
concurrency:
24+
group: cmake-${{ 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
40-
- name: Setup cmake
41-
uses: jwlawson/[email protected]
42-
with:
43-
cmake-version: '3.26.x'
44-
- name: Add msbuild to PATH
45-
uses: microsoft/[email protected]
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+
uses: ilammy/[email protected]
5052
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
5658
shell: bash
5759
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"
7270
else
73-
make
71+
echo CXX_COMPILER=g++ >> "$GITHUB_ENV"
7472
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: |
7590
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
7691
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
7792
- name: Upload build artifact
7893
uses: actions/upload-artifact@v4
7994
with:
80-
name: shared_library_${{ matrix.os }}_${{ matrix.arch }}
95+
name: shared_library-${{ matrix.os }}-${{ matrix.arch }}
8196
path: output/*
82-
retention-days: 7
8397
##
8498
# This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64)
8599
##
86100
build-shared-libs-cuda:
87101
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+
88105
matrix:
89106
os: [ubuntu-latest, windows-latest]
107+
cuda-version: ['11.8', '12.1']
90108
arch: [x86_64, aarch64]
91-
cuda_version: ['12.1.0']
109+
build_type: [Release]
92110
exclude:
93111
- os: windows-latest # This probably requires arm64 Windows agents
94112
arch: aarch64
113+
95114
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
96115
steps:
97116
# Check out code
98117
- 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-
uses: jwlawson/[email protected]
118+
- name: Set up Python 3.10
119+
uses: actions/setup-python@v5
107120
with:
108-
cmake-version: '3.26.x'
109-
# Windows: We install Cuda on the agent (slow)
110-
- uses: Jimver/[email protected]
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+
uses: ilammy/[email protected]
113126
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-
uses: microsoft/[email protected]
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]
123131
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
129226
shell: bash
130227
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
148228
mkdir -p output/${{ matrix.os }}/${{ matrix.arch }}
149229
( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ )
150230
- name: Upload build artifact
151231
uses: actions/upload-artifact@v4
152232
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 }}
154234
path: output/*
155-
retention-days: 7
156235
build-wheels:
157236
needs:
158237
- build-shared-libs
159238
- build-shared-libs-cuda
160239
strategy:
161240
matrix:
162241
os: [ubuntu-latest, macos-latest, windows-latest]
163-
python-version: ["3.9", "3.10", "3.11", "3.12"]
164242
arch: [x86_64, aarch64]
165243
exclude:
166-
- os: windows-latest # This probably requires arm64 Windows agents
244+
- os: windows-latest
167245
arch: aarch64
168246
runs-on: ${{ matrix.os }}
169247
steps:
@@ -174,18 +252,18 @@ jobs:
174252
uses: actions/download-artifact@v4
175253
with:
176254
merge-multiple: true
177-
pattern: "shared_library*_${{ matrix.os }}_${{ matrix.arch }}*"
255+
pattern: "shared_library*-${{ matrix.os }}-*"
178256
path: output/
179257
- name: Copy correct platform shared library
180258
shell: bash
181259
run: |
182260
ls -lR output/
183261
cp output/${{ matrix.os }}/${{ matrix.arch }}/* bitsandbytes/
184262
# Set up the Python version needed
185-
- name: Set up Python ${{ matrix.python-version }}
263+
- name: Set up Python 3.10
186264
uses: actions/setup-python@v5
187265
with:
188-
python-version: ${{ matrix.python-version }}
266+
python-version: "3.10"
189267
cache: pip
190268
- name: Install build package
191269
shell: bash
@@ -200,13 +278,13 @@ jobs:
200278
# PYTHONPATH=. pytest --log-cli-level=DEBUG tests
201279
- name: Build wheel
202280
shell: bash
203-
run: python -m build .
204-
- name: Upload build artifact
281+
run: python -m build . --wheel
282+
- name: Upload Build Artifacts
205283
uses: actions/upload-artifact@v4
206284
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/
210288
publish:
211289
needs: build-wheels
212290
runs-on: ubuntu-latest
@@ -217,7 +295,7 @@ jobs:
217295
with:
218296
path: dist/
219297
merge-multiple: true
220-
pattern: "bdist_wheel_*"
298+
pattern: "bdist_wheel-*"
221299
- run: |
222300
ls -lR dist/
223301
- name: Publish to PyPi

0 commit comments

Comments
 (0)