From b0fedba0aaf94bbd3c53224c51f98af614de5134 Mon Sep 17 00:00:00 2001 From: Won-Kyu Park Date: Wed, 7 Feb 2024 20:20:05 +0900 Subject: [PATCH] CI: restore some accidentally removed stuff and fix miscs. * fix to support cmake -B build option * add cuda 11.8, 12.1 * use python-version==3.10 for builds. * fix wheel names for aarch64 * use conda+mamba method. disable cuda-toolkits * make wheel with all available cuda versions. * use docker-run-actions * update docker image version * drop artifact retention-days: it could be configured Settings->Actions->General. --- .github/workflows/python-package.yml | 236 ++++++++++++++++++++------- 1 file changed, 180 insertions(+), 56 deletions(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 265128637..b2a8be65c 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,9 +1,9 @@ name: Python package on: - push: {} - pull_request: + push: branches: [ main ] + pull_request: paths: - '.github/workflows/python-package.yml' - 'bitsandbytes/**' @@ -17,8 +17,13 @@ on: - 'pytest.ini' - '**/*.md' release: + branches: [ main ] types: [ published ] +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + jobs: ## @@ -26,9 +31,13 @@ jobs: ## build-shared-libs: strategy: + # 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. + fail-fast: false + matrix: os: [ubuntu-latest, macos-latest, windows-latest] arch: [x86_64, aarch64] + build_type: [Release] exclude: - os: windows-latest # This probably requires arm64 Windows agents arch: aarch64 @@ -36,14 +45,20 @@ jobs: steps: # Check out code - uses: actions/checkout@v4 - # On Linux we use CMake within Docker + - name: Allow cross-compile on aarch64 + if: ${{ startsWith(matrix.os, 'ubuntu') && matrix.arch == 'aarch64' }} + run: | + # Allow cross-compile on aarch64 + sudo apt-get install -y g++-aarch64-linux-gnu binutils-aarch64-linux-gnu + - name: Setup cmake uses: jwlawson/actions-setup-cmake@v1.14 with: cmake-version: '3.26.x' - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.1 - if: ${{ startsWith(matrix.os, 'windows') }} + - name: Setup MSVC + if: startsWith(matrix.os, 'windows') + #uses: microsoft/setup-msbuild@v1.1 # to use msbuild + uses: ilammy/msvc-dev-cmd@v1.13.0 # to use cl # Check out dependencies code - uses: actions/checkout@v4 name: Check out NVidia cub @@ -51,44 +66,58 @@ jobs: repository: nvidia/cub ref: 1.11.0 path: dependencies/cub - # Compile C++ code - - name: Build C++ - shell: bash + + - name: Prep Compilers + shell: bash -el {0} run: | - set -ex - build_os=${{ matrix.os }} - build_arch=${{ matrix.arch }} - if [ ${build_os:0:6} == ubuntu -a ${build_arch} == aarch64 ]; then - # Allow cross-compile om aarch64 - sudo apt-get install -y gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu - fi - if [ ${build_os:0:5} == macos -a ${build_arch} == aarch64 ]; then - cmake -DCMAKE_OSX_ARCHITECTURES=arm64 -DCOMPUTE_BACKEND=cpu . + python3 -m pip install cmake==3.27.9 ninja + if [[ "${{ matrix.os }}" = windows-* ]]; then + echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV" + elif [[ "${{ matrix.os }}" = ubuntu-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then + echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ >> "$GITHUB_ENV" else - cmake -DCOMPUTE_BACKEND=cpu . + echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV" fi - if [ ${build_os:0:7} == windows ]; then - pwsh -Command "msbuild bitsandbytes.vcxproj /property:Configuration=Release" - else - make + + if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then + echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV" fi + + - name: Build CPU + shell: bash -el {0} + run: | + cmake -B build \ + -G Ninja ${{ env.DCMAKE_OSX_ARCHITECTURES }} \ + ${{ env.CXX_COMPILER }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DCOMPUTE_BACKEND=cpu \ + -S . + + cmake --build build --config ${{ matrix.build_type }} + mkdir -p output/${{ matrix.os }}/${{ matrix.arch }} + ls -l bitsandbytes + echo " check lib files..." + file bitsandbytes/libbitsandbytes*.* ( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ ) - name: Upload build artifact uses: actions/upload-artifact@v4 with: name: shared_library_${{ matrix.os }}_${{ matrix.arch }} path: output/* - retention-days: 7 ## # This job matrix builds the CUDA versions of the libraries for platforms that support CUDA (Linux x64/aarch64 + Windows x64) ## build-shared-libs-cuda: strategy: + # 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. + fail-fast: false + matrix: os: [ubuntu-latest, windows-latest] arch: [x86_64, aarch64] - cuda_version: ['12.1.0'] + cuda-version: ['11.8.0', '12.1.1'] + build_type: [Release] exclude: - os: windows-latest # This probably requires arm64 Windows agents arch: aarch64 @@ -102,21 +131,28 @@ jobs: uses: docker/setup-qemu-action@v2 # On Linux we use CMake within Docker - name: Setup cmake - if: ${{ !startsWith(matrix.os, 'linux') }} + if: ${{ !startsWith(matrix.os, 'ubuntu') }} uses: jwlawson/actions-setup-cmake@v1.14 with: cmake-version: '3.26.x' # Windows: We install Cuda on the agent (slow) + # it is too slow and sometime break - uses: Jimver/cuda-toolkit@v0.2.14 - if: startsWith(matrix.os, 'windows') + if: startsWith(matrix.os, 'x') # disabled id: cuda-toolkit with: cuda: ${{ matrix.cuda_version }} method: 'local' # sub-packages: '["nvcc","cudart","nvrtc_dev","cublas_dev","cusparse_dev","visual_studio_integration"]' - - name: Add msbuild to PATH - uses: microsoft/setup-msbuild@v1.1 - if: ${{ startsWith(matrix.os, 'windows') }} + - name: Set up Python 3.10 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + + - name: Setup MSVC + if: startsWith(matrix.os, 'windows') + #uses: microsoft/setup-msbuild@v1.1 # to use msbuild + uses: ilammy/msvc-dev-cmd@v1.13.0 # to use cl # Check out dependencies code - uses: actions/checkout@v4 name: Check out NVidia cub @@ -124,35 +160,117 @@ jobs: repository: nvidia/cub ref: 1.11.0 path: dependencies/cub - # Compile C++ code - - name: Build C++ + - name: Setup Mambaforge + if: startsWith(matrix.os, 'windows') + uses: conda-incubator/setup-miniconda@v3.0.1 + with: + miniforge-variant: Mambaforge + miniforge-version: latest + activate-environment: bnb-env + use-mamba: true + + - uses: conda-incubator/setup-miniconda@v3.0.1 + if: startsWith(matrix.os, 'windows') + with: + auto-update-conda: true + activate-environment: bnb-env + environment-file: environment-bnb.yml + use-only-tar-bz2: false + auto-activate-base: true + python-version: "3.10" + mamba-version: "*" + + - name: Setup CUDA + if: startsWith(matrix.os, 'windows') + shell: bash -el {0} + run: | + addon="" + cuda_version=${{ matrix.cuda-version }} + [[ "$cuda_version" = 12.1.* ]] && [[ "${{ matrix.os }}" = ubuntu-* ]] && addon="cuda-cudart-static cuda-nvrtc" + [[ "$cuda_version" = 11.8.* ]] && [[ "${{ matrix.os }}" = windows-* ]] && addon="cuda-nvrtc" + [[ "$cuda_version" = 11.8.* ]] && cuda__version="11.8" + [[ "$cuda_version" = 12.1.* ]] && cuda__version="12.1" + + conda install pytorch-cuda=$cuda__version -c pytorch # it's dependency not correctly resolved sometime + conda install cuda-python=$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" + + CUDA_HOME="${{ env.CONDA }}/envs/bnb-env" + echo CUDA_HOME=$CUDA_HOME >> "$GITHUB_ENV" + echo CUDA_PATH=$CUDA_HOME >> "$GITHUB_ENV" + + if [[ "${{ matrix.os }}" = windows-* ]]; then + echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=cl >> "$GITHUB_ENV" + # without -DCMAKE_CUDA_COMPILER=nvcc, cmake config always fail for cuda-11.8 + echo DCMAKE_CUDA_COMPILER=-DCMAKE_CUDA_COMPILER=nvcc >> "$GITHUB_ENV" + else + echo CXX_COMPILER=-DCMAKE_CXX_COMPILER=g++ >> "$GITHUB_ENV" + fi + + if [[ "${{ matrix.os }}" = macos-* ]] && [[ "${{ matrix.arch }}" = "aarch64" ]]; then + echo DCMAKE_OSX_ARCHITECTURES=-DCMAKE_OSX_ARCHITECTURES=arm64 >> "$GITHUB_ENV" + fi + + nvcc --version + + - name: Update environment + if: startsWith(matrix.os, 'windows') + run: mamba env update -n bnb-env -f environment-bnb.yml + + - name: Prep build + if: startsWith(matrix.os, 'windows') + run: python -m pip install cmake==3.27.9 ninja + + - name: Build CUDA + if: startsWith(matrix.os, 'windows') + shell: bash -el {0} + run: | + cmake -B build \ + -G Ninja ${{ env.DCMAKE_CUDA_COMPILER }} \ + ${{ env.CXX_COMPILER }} \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \ + -DCOMPUTE_BACKEND=cuda \ + -S . + + cmake --build build --config ${{ matrix.build_type }} + + - name: Build CUDA (docker) + if: startsWith(matrix.os, 'ubuntu') + uses: addnab/docker-run-action@v3 + with: + image: ${{ format('nvidia/cuda:{0}-{1}', matrix.cuda-version, 'devel-ubuntu22.04') }} + options: --platform linux/${{ matrix.arch }} -w /src -v ${{ github.workspace }}:/src + run: | + apt-get update + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake python3 python3-pip + # install cmake, ninja to prepare cmake + python3 -m pip install cmake==3.27.9 ninja + + for NO_CUBLASLT in OFF ON; do + cmake -B build \ + -G Ninja \ + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \ + -DCOMPUTE_CAPABILITY="50;52;60;61;62;70;72;75;80;86;87;89;90" \ + -DCOMPUTE_BACKEND=cuda \ + -DNO_CUBLASLT=$NO_CUBLAST \ + -S . + + cmake --build build --config ${{ matrix.build_type }} + done + + - name: Copy libraries shell: bash run: | - set -ex - build_os=${{ matrix.os }} - build_arch=${{ matrix.arch }} - for NO_CUBLASLT in ON OFF; do - if [ ${build_os:0:6} == ubuntu ]; then - image=nvidia/cuda:${{ matrix.cuda_version }}-devel-ubuntu22.04 - echo "Using image $image" - docker run --platform linux/$build_arch -i -w /src -v $PWD:/src $image sh -c \ - "apt-get update \ - && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends cmake \ - && cmake -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} . \ - && make" - else - cmake -DCOMPUTE_BACKEND=cuda -DNO_CUBLASLT=${NO_CUBLASLT} . - pwsh -Command "msbuild bitsandbytes.vcxproj /property:Configuration=Release" - fi - done mkdir -p output/${{ matrix.os }}/${{ matrix.arch }} + echo " check lib files..." + file bitsandbytes/libbitsandbytes*.* ( shopt -s nullglob && cp bitsandbytes/*.{so,dylib,dll} output/${{ matrix.os }}/${{ matrix.arch }}/ ) - name: Upload build artifact uses: actions/upload-artifact@v4 with: - name: shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda_version }} + name: shared_library_cuda_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.cuda-version }} path: output/* - retention-days: 7 + build-wheels: needs: - build-shared-libs @@ -160,7 +278,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, macos-latest, windows-latest] - python-version: ["3.9", "3.10", "3.11", "3.12"] + python-version: ["3.10"] arch: [x86_64, aarch64] exclude: - os: windows-latest # This probably requires arm64 Windows agents @@ -200,13 +318,19 @@ jobs: # PYTHONPATH=. pytest --log-cli-level=DEBUG tests - name: Build wheel shell: bash - run: python -m build . + run: | + python -m build . --wheel + # fix wheel name + if [ "${{ matrix.arch }}" = "aarch64" ]; then + o=$(ls dist/*.whl) + n=$(echo $o | sed 's@_x86_64@_aarch64@') + [ "$n" != "$o" ] && mv $o $n + fi - name: Upload build artifact uses: actions/upload-artifact@v4 with: - name: bdist_wheel_${{ matrix.os }}_${{ matrix.arch }}_${{ matrix.python-version }} - path: dist/bitsandbytes-*.whl - retention-days: 7 + name: bdist_wheel_${{ matrix.os }}-${{ matrix.arch }} + path: ${{ github.workspace }}/dist/bitsandbytes-*.whl publish: needs: build-wheels runs-on: ubuntu-latest