Skip to content

Commit a41c817

Browse files
CI: Run tests on PRs, refactor nightly test workflow
1 parent 221b4b4 commit a41c817

File tree

3 files changed

+423
-0
lines changed

3 files changed

+423
-0
lines changed

.github/workflows/test-runner.yml

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
name: Test Runner
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
platform:
7+
type: string
8+
required: true
9+
description: "Platform: linux-x64, linux-aarch64, windows, macos"
10+
backend:
11+
type: string
12+
required: true
13+
description: "Backend: cpu, cuda"
14+
torch_version:
15+
type: string
16+
required: true
17+
description: "PyTorch version to install"
18+
pypi_index:
19+
type: string
20+
default: "https://download.pytorch.org/whl/cpu"
21+
description: "PyPI index URL for torch installation"
22+
cuda_version:
23+
type: string
24+
default: ""
25+
description: "CUDA version (required for cuda backend)"
26+
gpu_type:
27+
type: string
28+
default: ""
29+
description: "GPU type for CUDA testing: T4, L40S"
30+
# cpu_type currently only affects linux x64 CPU testing to select specific CPU architectures
31+
cpu_type:
32+
type: string
33+
default: ""
34+
description: "CPU architecture for testing: icelake, cascadelake (default: platform default runner)"
35+
36+
env:
37+
BNB_SKIP_CMAKE: 1
38+
39+
jobs:
40+
setup:
41+
runs-on: ubuntu-latest
42+
outputs:
43+
build_runner: ${{ steps.map.outputs.build_runner }}
44+
test_runner: ${{ steps.map.outputs.test_runner }}
45+
build_os: ${{ steps.map.outputs.build_os }}
46+
arch: ${{ steps.map.outputs.arch }}
47+
artifact_name: ${{ steps.map.outputs.artifact_name }}
48+
steps:
49+
- name: Map configuration to runners
50+
id: map
51+
run: |
52+
# Map platform to concrete runner names, OS identifiers, and architecture
53+
case "${{ inputs.platform }}" in
54+
linux-x64)
55+
BUILD_OS="ubuntu-22.04"
56+
BUILD_RUNNER="ubuntu-22.04"
57+
ARCH="x64"
58+
if [[ "${{ inputs.backend }}" == "cuda" ]]; then
59+
case "${{ inputs.gpu_type }}" in
60+
T4)
61+
TEST_RUNNER="bandb-aws-g4dn-4xlarge-plus-use1-public-80"
62+
;;
63+
L40S)
64+
TEST_RUNNER="bandb-aws-g6e-4xlarge-plus-use1-public-80"
65+
;;
66+
*)
67+
echo "::error::Must specify gpu_type (T4 or L40S) for linux-x64 cuda backend"
68+
exit 1
69+
;;
70+
esac
71+
else
72+
# CPU backend
73+
case "${{ inputs.cpu_type }}" in
74+
icelake)
75+
TEST_RUNNER="banb-aws-general-8-plus-use1-public-80"
76+
;;
77+
cascadelake)
78+
TEST_RUNNER="bandb-aws-g4dn-4xlarge-plus-use1-public-80"
79+
;;
80+
"")
81+
# Default: GitHub-provided runner (AMD EPYC 7763)
82+
TEST_RUNNER="ubuntu-22.04"
83+
;;
84+
*)
85+
echo "::error::Invalid cpu_type: ${{ inputs.cpu_type }}"
86+
exit 1
87+
;;
88+
esac
89+
fi
90+
;;
91+
linux-aarch64)
92+
BUILD_OS="ubuntu-22.04-arm"
93+
BUILD_RUNNER="ubuntu-22.04-arm"
94+
ARCH="aarch64"
95+
TEST_RUNNER="ubuntu-22.04-arm"
96+
;;
97+
macos)
98+
BUILD_OS="macos-15"
99+
BUILD_RUNNER="macos-15"
100+
ARCH="arm64"
101+
TEST_RUNNER="macos-15"
102+
;;
103+
windows)
104+
BUILD_OS="windows-2025"
105+
BUILD_RUNNER="windows-2025"
106+
ARCH="x64"
107+
if [[ "${{ inputs.backend }}" == "cuda" ]]; then
108+
TEST_RUNNER="CUDA-Windows-x64"
109+
else
110+
TEST_RUNNER="windows-2025"
111+
fi
112+
;;
113+
*)
114+
echo "::error::Unsupported platform: ${{ inputs.platform }}"
115+
exit 1
116+
;;
117+
esac
118+
119+
# Create unique artifact name
120+
ARTIFACT="lib_${{ inputs.backend }}_${BUILD_OS}_${ARCH}"
121+
if [[ "${{ inputs.backend }}" == "cuda" ]]; then
122+
ARTIFACT="${ARTIFACT}_${{ inputs.cuda_version }}"
123+
fi
124+
# Add run ID to make artifacts unique across workflow runs
125+
ARTIFACT="${ARTIFACT}_${{ github.run_id }}_${{ github.run_attempt }}"
126+
127+
echo "build_runner=${BUILD_RUNNER}" >> $GITHUB_OUTPUT
128+
echo "test_runner=${TEST_RUNNER}" >> $GITHUB_OUTPUT
129+
echo "build_os=${BUILD_OS}" >> $GITHUB_OUTPUT
130+
echo "arch=${ARCH}" >> $GITHUB_OUTPUT
131+
echo "artifact_name=${ARTIFACT}" >> $GITHUB_OUTPUT
132+
133+
build:
134+
needs: setup
135+
runs-on: ${{ needs.setup.outputs.build_runner }}
136+
env:
137+
build_os: ${{ needs.setup.outputs.build_os }}
138+
build_arch: ${{ needs.setup.outputs.arch }}
139+
steps:
140+
- uses: actions/checkout@v4
141+
142+
# Windows + CUDA: Install CUDA Toolkit
143+
- name: Install CUDA Toolkit
144+
if: inputs.backend == 'cuda' && inputs.platform == 'windows'
145+
uses: Jimver/cuda-toolkit@c35baa1a18fd1fc9dcf47c5bd839bf30559c0bc3 # v0.2.24
146+
with:
147+
cuda: ${{ inputs.cuda_version }}
148+
method: "network"
149+
sub-packages: '["nvcc","cudart","cusparse","cublas","thrust","nvrtc_dev","cublas_dev","cusparse_dev"]'
150+
use-github-cache: false
151+
152+
# Windows: Setup MSVC (needed for both CPU and CUDA builds)
153+
- name: Setup MSVC
154+
if: inputs.platform == 'windows'
155+
uses: ilammy/[email protected]
156+
157+
# Build CPU backend
158+
- name: Build C++
159+
if: inputs.backend == 'cpu'
160+
run: bash .github/scripts/build-cpu.sh
161+
162+
# Build CUDA backend
163+
- name: Build C++ / CUDA
164+
if: inputs.backend == 'cuda'
165+
run: bash .github/scripts/build-cuda.sh
166+
env:
167+
cuda_version: ${{ inputs.cuda_version }}
168+
cuda_targets: "75;89"
169+
170+
- name: Upload build artifact
171+
uses: actions/upload-artifact@v4
172+
with:
173+
name: ${{ needs.setup.outputs.artifact_name }}
174+
path: output/${{ needs.setup.outputs.build_os }}/${{ needs.setup.outputs.arch }}/*
175+
retention-days: 7
176+
177+
test:
178+
needs: [setup, build]
179+
runs-on: ${{ needs.setup.outputs.test_runner }}
180+
env:
181+
BNB_TEST_DEVICE: ${{ inputs.backend }}
182+
steps:
183+
# CUDA: Show GPU information
184+
- name: Show GPU Information
185+
if: inputs.backend == 'cuda'
186+
run: nvidia-smi
187+
188+
- uses: actions/checkout@v4
189+
190+
- name: Download build artifact
191+
uses: actions/download-artifact@v4
192+
with:
193+
name: ${{ needs.setup.outputs.artifact_name }}
194+
path: bitsandbytes/
195+
merge-multiple: true
196+
197+
- name: Setup Python
198+
uses: actions/setup-python@v5
199+
with:
200+
python-version: '3.10'
201+
202+
# Windows: Setup MSVC for torch.compile
203+
- name: Setup MSVC
204+
if: inputs.platform == 'windows'
205+
uses: ilammy/[email protected]
206+
207+
- name: Install dependencies
208+
run: |
209+
pip install torch==${{ inputs.torch_version }} --index-url ${{ inputs.pypi_index }}
210+
pip install -e ".[test]" -v
211+
pip install pytest-cov
212+
213+
# Windows: Downgrade NumPy for torch<2.4.1 compatibility
214+
# See: https://github.com/pytorch/pytorch/issues/131668
215+
- name: Downgrade NumPy
216+
if: inputs.platform == 'windows' && startsWith(inputs.torch_version, '2.3.')
217+
run: pip install "numpy<2"
218+
219+
- name: Show installed packages
220+
run: pip list
221+
222+
- name: Show environment information
223+
run: python -m torch.utils.collect_env
224+
225+
- name: Run tests
226+
run: pytest --durations=100
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Nightly Tests
2+
3+
on:
4+
workflow_dispatch:
5+
schedule:
6+
# Every day at 02:15 AM UTC
7+
- cron: "15 2 * * *"
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
test-cpu:
15+
name: CPU
16+
if: github.repository == 'bitsandbytes-foundation/bitsandbytes'
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
platform: [linux-x64, linux-aarch64, macos, windows]
21+
# default runners don't have AVX-512 support, but icelake does
22+
cpu_type: ["", icelake]
23+
torch_version: ["2.3.1", "2.8.0", "2.9.1"]
24+
25+
exclude:
26+
# aarch64 minimum torch version is 2.5.1
27+
- platform: linux-aarch64
28+
torch_version: "2.3.1"
29+
# icelake only applies to linux-x64
30+
- platform: linux-aarch64
31+
cpu_type: icelake
32+
- platform: macos
33+
cpu_type: icelake
34+
- platform: windows
35+
cpu_type: icelake
36+
37+
include:
38+
# Add aarch64 with torch 2.5.1
39+
- platform: linux-aarch64
40+
cpu_type: ""
41+
torch_version: "2.5.1"
42+
43+
uses: ./.github/workflows/test-runner.yml
44+
with:
45+
platform: ${{ matrix.platform }}
46+
backend: cpu
47+
torch_version: ${{ matrix.torch_version }}
48+
pypi_index: "https://download.pytorch.org/whl/cpu"
49+
cpu_type: ${{ matrix.cpu_type }}
50+
51+
test-cuda:
52+
name: CUDA
53+
if: github.repository == 'bitsandbytes-foundation/bitsandbytes'
54+
strategy:
55+
fail-fast: false
56+
matrix:
57+
# Linux x64 cross-product
58+
platform: [linux-x64]
59+
gpu_type: [T4, L40S]
60+
cuda_version: ["11.8.0", "12.6.3", "12.8.1", "13.0.1"]
61+
62+
include:
63+
# Map CUDA version to torch version and PyPI index
64+
- cuda_version: "11.8.0"
65+
torch_version: "2.3.1"
66+
pypi_index: "https://download.pytorch.org/whl/cu118"
67+
- cuda_version: "12.6.3"
68+
torch_version: "2.7.1"
69+
pypi_index: "https://download.pytorch.org/whl/cu126"
70+
- cuda_version: "12.8.1"
71+
torch_version: "2.8.0"
72+
pypi_index: "https://download.pytorch.org/whl/cu128"
73+
- cuda_version: "13.0.1"
74+
torch_version: "2.9.1"
75+
pypi_index: "https://download.pytorch.org/whl/cu130"
76+
77+
# Windows CUDA Tests - T4 GPU (CUDA 11.8 only, multiple torch versions)
78+
- platform: windows
79+
gpu_type: T4
80+
cuda_version: "11.8.0"
81+
torch_version: "2.3.1"
82+
pypi_index: "https://download.pytorch.org/whl/cu118"
83+
- platform: windows
84+
gpu_type: T4
85+
cuda_version: "11.8.0"
86+
torch_version: "2.6.0"
87+
pypi_index: "https://download.pytorch.org/whl/cu118"
88+
- platform: windows
89+
gpu_type: T4
90+
cuda_version: "11.8.0"
91+
torch_version: "2.7.1" # Note: this is the last PyTorch release supporting CUDA 11.8.
92+
pypi_index: "https://download.pytorch.org/whl/cu118"
93+
94+
uses: ./.github/workflows/test-runner.yml
95+
with:
96+
platform: ${{ matrix.platform }}
97+
backend: cuda
98+
cuda_version: ${{ matrix.cuda_version }}
99+
gpu_type: ${{ matrix.gpu_type }}
100+
torch_version: ${{ matrix.torch_version }}
101+
pypi_index: ${{ matrix.pypi_index }}

0 commit comments

Comments
 (0)