|
| 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 | + |
| 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 | + |
| 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 |
0 commit comments