Skip to content

Commit 77db267

Browse files
Run unit tests on GH Actions
1 parent 10b9d4c commit 77db267

File tree

2 files changed

+181
-4
lines changed

2 files changed

+181
-4
lines changed

.github/scripts/build-cuda.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
declare build_arch
33
declare build_os
44
declare cuda_version
5+
declare cuda_targets
56

67
set -xeuo pipefail
78

8-
# By default, target Maxwell through Hopper.
9-
build_capability="50;52;60;61;70;75;80;86;89;90"
9+
if [ -n "${cuda_targets}" ]; then
10+
# By default, target Maxwell through Hopper.
11+
build_capability="50;52;60;61;70;75;80;86;89;90"
1012

11-
# CUDA 12.8: Add sm100 and sm120; remove < sm75 to align with PyTorch 2.7+cu128 minimum
12-
[[ "${cuda_version}" == 12.8.* ]] && build_capability="75;80;86;89;90;100;120"
13+
# CUDA 12.8: Add sm100 and sm120; remove < sm75 to align with PyTorch 2.7+cu128 minimum
14+
[[ "${cuda_version}" == 12.8.* ]] && build_capability="75;80;86;89;90;100;120"
15+
else
16+
build_capability="${cuda_targets}"
17+
fi
1318

1419
[[ "${build_os}" = windows-* ]] && python3 -m pip install ninja
1520

.github/workflows/tests.yml

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
name: Unit tests
2+
3+
on:
4+
workflow_dispatch:
5+
6+
7+
jobs:
8+
9+
build-cpu:
10+
strategy:
11+
matrix:
12+
os: [ubuntu-22.04, windows-2025]
13+
arch: [x86_64]
14+
runs-on: ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup MSVC
19+
if: startsWith(matrix.os, 'windows')
20+
uses: ilammy/[email protected] # to use cl
21+
22+
- name: Build C++
23+
run: bash .github/scripts/build-cpu.sh
24+
env:
25+
build_os: ${{ matrix.os }}
26+
build_arch: ${{ matrix.arch }}
27+
28+
- name: Upload build artifact
29+
uses: actions/upload-artifact@v4
30+
with:
31+
name: lib_cpu_${{ matrix.os }}_${{ matrix.arch }}
32+
path: output/*
33+
retention-days: 7
34+
35+
build-cuda:
36+
strategy:
37+
matrix:
38+
cuda_version: ["11.8.0", "12.8.1"]
39+
include:
40+
- os: ubuntu-22.04
41+
arch: x86_64
42+
- os: windows-2025
43+
arch: x86_64
44+
45+
runs-on: ${{ matrix.os }}
46+
47+
steps:
48+
- uses: actions/checkout@v4
49+
50+
- name: Install CUDA Toolkit
51+
uses: Jimver/[email protected]
52+
if: startsWith(matrix.os, 'windows')
53+
id: cuda-toolkit
54+
with:
55+
cuda: ${{ matrix.cuda_version }}
56+
method: "network"
57+
sub-packages: '["nvcc","cudart","cusparse","cublas","thrust","nvrtc_dev","cublas_dev","cusparse_dev"]'
58+
59+
- name: Setup MSVC
60+
if: startsWith(matrix.os, 'windows')
61+
uses: ilammy/[email protected] # to use cl
62+
63+
# We're running on T4 only for now, so we only target sm75.
64+
- name: Build C++ / CUDA
65+
run: bash .github/scripts/build-cuda.sh
66+
env:
67+
build_os: ${{ matrix.os }}
68+
build_arch: x86_64
69+
cuda_version: ${{ matrix.cuda_version }}
70+
cuda_targets: "75"
71+
72+
- name: Upload build artifact
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: lib_cuda_${{matrix.cuda_version}}_${{ matrix.os }}_${{ matrix.arch }}
76+
path: output/*
77+
retention-days: 7
78+
79+
cpu-tests:
80+
needs: build-cpu
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
os: [ubuntu-22.04, windows-2025]
85+
arch: [x86_64]
86+
torch_version: ["2.4.1", "2.7.0"]
87+
runs-on: ${{ matrix.os }}
88+
env:
89+
BNB_TEST_DEVICE: cpu
90+
steps:
91+
- name: Show CPU Information
92+
run: |
93+
if [[ $RUNNER_OS == 'Linux' ]]; then
94+
lscpu
95+
else
96+
systeminfo | findstr /C:"Processor"
97+
fi
98+
99+
- uses: actions/checkout@v4
100+
101+
- name: Download build artifact
102+
uses: actions/download-artifact@v4
103+
with:
104+
name: lib_cpu_${{ matrix.os }}_${{ matrix.arch }}
105+
path: bitsandbytes/
106+
merge-multiple: true
107+
108+
- name: Setup Python
109+
uses: actions/setup-python@v5
110+
with:
111+
python-version: 3.9
112+
113+
- name: Install dependencies
114+
run: |
115+
pip install torch==${{ matrix.torch_version }} --index-url https://download.pytorch.org/whl/cpu
116+
pip install -e ".[test]"
117+
pip install pytest-cov
118+
119+
- name: Show installed packages
120+
run: pip list
121+
122+
- name: Run tests
123+
run: pytest
124+
125+
cuda-tests:
126+
needs: build-cuda
127+
strategy:
128+
fail-fast: false
129+
matrix:
130+
os: [ubuntu-22.04, windows-2025]
131+
arch: [x86_64]
132+
torch_version: ["2.4.1", "2.7.0"]
133+
include:
134+
- torch_version: "2.4.1"
135+
cuda_version: "11.8.0"
136+
pypi_index: "https://download.pytorch.org/whl/cu118"
137+
- torch_version: "2.7.0"
138+
cuda_version: "12.8.1"
139+
pypi_index: "https://download.pytorch.org/whl/cu128"
140+
runs-on:
141+
labels: ${{ contains(matrix.os, 'windows') && 'CUDA-Windows-x64' || 'CUDA-Linux-x64' }}
142+
env:
143+
BNB_TEST_DEVICE: cuda
144+
steps:
145+
- name: Show GPU Information
146+
run: nvidia-smi
147+
148+
- uses: actions/checkout@v4
149+
150+
- name: Download build artifact
151+
uses: actions/download-artifact@v4
152+
with:
153+
name: lib_cuda_${{ matrix.cuda_version }}_${{ matrix.os }}_${{ matrix.arch }}
154+
path: bitsandbytes/
155+
merge-multiple: true
156+
157+
- name: Setup Python
158+
uses: actions/setup-python@v5
159+
with:
160+
python-version: 3.9
161+
162+
- name: Install dependencies
163+
run: |
164+
pip install torch==${{ matrix.torch_version }} --index-url ${{ matrix.pypi_index }}
165+
pip install -e ".[test]"
166+
pip install pytest-cov
167+
168+
- name: Show installed packages
169+
run: pip list
170+
171+
- name: Run tests
172+
run: pytest

0 commit comments

Comments
 (0)