Skip to content

Commit b5a49ae

Browse files
CI: Run tests on PRs, refactor nightly test workflow (#1811)
* CI: Run tests on PRs, refactor nightly test workflow * Ensure artifact names are unique * Simplify * Fix for Windows * Fix for Windows * Temp rename * Temp * Update
1 parent 221b4b4 commit b5a49ae

File tree

4 files changed

+423
-1
lines changed

4 files changed

+423
-1
lines changed

.github/workflows/test-runner.yml

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
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+
build:
41+
runs-on: >-
42+
${{
43+
inputs.platform == 'linux-x64' && 'ubuntu-22.04' ||
44+
inputs.platform == 'linux-aarch64' && 'ubuntu-22.04-arm' ||
45+
inputs.platform == 'macos' && 'macos-15' ||
46+
'windows-2025'
47+
}}
48+
outputs:
49+
test_runner: ${{ steps.config.outputs.test_runner }}
50+
artifact_name: ${{ steps.config.outputs.artifact_name }}
51+
build_os: ${{ steps.config.outputs.build_os }}
52+
arch: ${{ steps.config.outputs.arch }}
53+
steps:
54+
- name: Configure test runner and paths
55+
id: config
56+
shell: bash
57+
run: |
58+
# Map platform to OS identifiers, architecture, and test runner
59+
case "${{ inputs.platform }}" in
60+
linux-x64)
61+
BUILD_OS="ubuntu-22.04"
62+
ARCH="x64"
63+
if [[ "${{ inputs.backend }}" == "cuda" ]]; then
64+
case "${{ inputs.gpu_type }}" in
65+
T4)
66+
TEST_RUNNER="bandb-aws-g4dn-4xlarge-plus-use1-public-80"
67+
;;
68+
L40S)
69+
TEST_RUNNER="bandb-aws-g6e-4xlarge-plus-use1-public-80"
70+
;;
71+
*)
72+
echo "::error::Must specify gpu_type (T4 or L40S) for linux-x64 cuda backend"
73+
exit 1
74+
;;
75+
esac
76+
else
77+
case "${{ inputs.cpu_type }}" in
78+
icelake)
79+
TEST_RUNNER="banb-aws-general-8-plus-use1-public-80"
80+
;;
81+
cascadelake)
82+
TEST_RUNNER="bandb-aws-g4dn-4xlarge-plus-use1-public-80"
83+
;;
84+
"")
85+
TEST_RUNNER="ubuntu-22.04"
86+
;;
87+
*)
88+
echo "::error::Invalid cpu_type: ${{ inputs.cpu_type }}"
89+
exit 1
90+
;;
91+
esac
92+
fi
93+
;;
94+
linux-aarch64)
95+
BUILD_OS="ubuntu-22.04-arm"
96+
ARCH="aarch64"
97+
TEST_RUNNER="ubuntu-22.04-arm"
98+
;;
99+
macos)
100+
BUILD_OS="macos-15"
101+
ARCH="arm64"
102+
TEST_RUNNER="macos-15"
103+
;;
104+
windows)
105+
BUILD_OS="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 per configuration
120+
ARTIFACT="lib_${{ inputs.backend }}_${BUILD_OS}_${ARCH}"
121+
if [[ "${{ inputs.backend }}" == "cuda" ]]; then
122+
ARTIFACT="${ARTIFACT}_${{ inputs.cuda_version }}_${{ inputs.gpu_type }}"
123+
else
124+
ARTIFACT="${ARTIFACT}_${{ inputs.cpu_type }}"
125+
fi
126+
ARTIFACT="${ARTIFACT}_torch${{ inputs.torch_version }}_${{ github.run_id }}_${{ github.run_attempt }}"
127+
128+
echo "test_runner=${TEST_RUNNER}" >> $GITHUB_OUTPUT
129+
echo "artifact_name=${ARTIFACT}" >> $GITHUB_OUTPUT
130+
echo "build_os=${BUILD_OS}" >> $GITHUB_OUTPUT
131+
echo "arch=${ARCH}" >> $GITHUB_OUTPUT
132+
133+
- uses: actions/checkout@v4
134+
135+
- name: Set build environment variables
136+
shell: bash
137+
run: |
138+
echo "build_os=${{ steps.config.outputs.build_os }}" >> $GITHUB_ENV
139+
echo "build_arch=${{ steps.config.outputs.arch }}" >> $GITHUB_ENV
140+
141+
# Windows + CUDA: Install CUDA Toolkit
142+
- name: Install CUDA Toolkit
143+
if: inputs.backend == 'cuda' && inputs.platform == 'windows'
144+
uses: Jimver/cuda-toolkit@c35baa1a18fd1fc9dcf47c5bd839bf30559c0bc3 # v0.2.24
145+
with:
146+
cuda: ${{ inputs.cuda_version }}
147+
method: "network"
148+
sub-packages: '["nvcc","cudart","cusparse","cublas","thrust","nvrtc_dev","cublas_dev","cusparse_dev"]'
149+
use-github-cache: false
150+
151+
# Windows: Setup MSVC (needed for both CPU and CUDA builds)
152+
- name: Setup MSVC
153+
if: inputs.platform == 'windows'
154+
uses: ilammy/[email protected]
155+
156+
# Build CPU backend
157+
- name: Build C++
158+
if: inputs.backend == 'cpu'
159+
run: bash .github/scripts/build-cpu.sh
160+
161+
# Build CUDA backend
162+
- name: Build C++ / CUDA
163+
if: inputs.backend == 'cuda'
164+
run: bash .github/scripts/build-cuda.sh
165+
env:
166+
cuda_version: ${{ inputs.cuda_version }}
167+
cuda_targets: "75;89"
168+
169+
- name: Upload build artifact
170+
uses: actions/upload-artifact@v4
171+
with:
172+
name: ${{ steps.config.outputs.artifact_name }}
173+
path: output/${{ steps.config.outputs.build_os }}/${{ steps.config.outputs.arch }}/*
174+
retention-days: 7
175+
176+
test:
177+
needs: build
178+
runs-on: ${{ needs.build.outputs.test_runner }}
179+
env:
180+
BNB_TEST_DEVICE: ${{ inputs.backend }}
181+
steps:
182+
# CUDA: Show GPU information
183+
- name: Show GPU Information
184+
if: inputs.backend == 'cuda'
185+
run: nvidia-smi
186+
187+
- uses: actions/checkout@v4
188+
189+
- name: Download build artifact
190+
uses: actions/download-artifact@v4
191+
with:
192+
name: ${{ needs.build.outputs.artifact_name }}
193+
path: bitsandbytes/
194+
merge-multiple: true
195+
196+
- name: Setup Python
197+
uses: actions/setup-python@v5
198+
with:
199+
python-version: '3.10'
200+
201+
# Windows: Setup MSVC for torch.compile
202+
- name: Setup MSVC
203+
if: inputs.platform == 'windows'
204+
uses: ilammy/[email protected]
205+
206+
- name: Install dependencies
207+
run: |
208+
pip install torch==${{ inputs.torch_version }} --index-url ${{ inputs.pypi_index }}
209+
pip install -e ".[test]" -v
210+
pip install pytest-cov
211+
212+
# Windows: Downgrade NumPy for torch<2.4.1 compatibility
213+
# See: https://github.com/pytorch/pytorch/issues/131668
214+
- name: Downgrade NumPy
215+
if: inputs.platform == 'windows' && startsWith(inputs.torch_version, '2.3.')
216+
run: pip install "numpy<2"
217+
218+
- name: Show installed packages
219+
run: pip list
220+
221+
- name: Show environment information
222+
run: python -m torch.utils.collect_env
223+
224+
- name: Run tests
225+
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)