Build wheels for torch 2.13 (#252) #618
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Torch Wheels | |
| on: | |
| push: | |
| branches: [main] | |
| tags: ["*"] | |
| pull_request: | |
| # Check all PR | |
| concurrency: | |
| group: torch-wheels-${{ github.ref }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | |
| jobs: | |
| build-torch-sdist: | |
| runs-on: ubuntu-22.04 | |
| name: sdist | |
| env: | |
| SPHERICART_NO_LOCAL_DEPS: 1 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies | |
| run: python -m pip install build | |
| - name: Build torch sdist | |
| run: python -m build --sdist ./sphericart-torch --outdir ./dist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: "sphericart-torch-sdist" | |
| path: ./dist/*.tar.gz | |
| - name: upload to GitHub release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| ./dist/*.tar.gz | |
| prerelease: ${{ contains(github.ref, '-rc') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| build-torch-wheels: | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| pytorch-version: ["2.6", "2.7", "2.8", "2.9", "2.10", "2.11", "2.12", "2.13"] | |
| os: [ubuntu-22.04, macos-14, ubuntu-22.04-arm, windows-2022] | |
| include: | |
| - os: ubuntu-22.04 | |
| arch: x86_64 | |
| name: x86_64 Linux | |
| - os: macos-14 | |
| arch: arm64 | |
| name: arm64 macOS | |
| - os: ubuntu-22.04-arm | |
| arch: aarch64 | |
| name: aarch64 Linux | |
| - os: windows-2022 | |
| arch: AMD64 | |
| name: x86_64 Windows | |
| name: "Torch ${{matrix.pytorch-version}} ${{matrix.os}} ${{matrix.arch}}" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Free disk space (Ubuntu) | |
| if: startsWith(matrix.os, 'ubuntu-') | |
| run: | | |
| sudo rm -rf /usr/local/.ghcup | |
| sudo rm -rf /opt/hostedtoolcache/CodeQL | |
| sudo rm -rf /usr/local/lib/android/sdk/ndk | |
| sudo rm -rf /usr/share/dotnet | |
| sudo rm -rf /opt/ghc | |
| sudo rm -rf /usr/local/share/boost | |
| - name: Build custom manylinux Docker Image with CUDA | |
| if: startsWith(matrix.os, 'ubuntu-') | |
| run: | | |
| docker build --no-cache \ | |
| -t sphericart_manylinux_2_28_"${{ matrix.arch }}" \ | |
| scripts/manylinux_2_28_"${{ matrix.arch }}" | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install CUDA toolkit (Windows) | |
| if: matrix.os == 'windows-2022' | |
| uses: Jimver/cuda-toolkit@v0.2.29 | |
| with: | |
| cuda: '12.6.3' | |
| method: 'local' | |
| log-file-suffix: 'torch-${{ matrix.pytorch-version }}-${{ matrix.os }}.txt' | |
| - name: Install cibuildwheel | |
| run: python -m pip install cibuildwheel | |
| - name: Build torch wheels | |
| run: python -m cibuildwheel ./sphericart-torch | |
| env: | |
| CIBW_BUILD_VERBOSITY: 1 | |
| CIBW_BUILD: "cp312-*" | |
| CIBW_SKIP: "*-musllinux*" | |
| CIBW_ARCHS: "${{ matrix.arch }}" | |
| CIBW_MANYLINUX_X86_64_IMAGE: sphericart_manylinux_2_28_x86_64 | |
| CIBW_MANYLINUX_AARCH64_IMAGE: sphericart_manylinux_2_28_aarch64 | |
| CIBW_REPAIR_WHEEL_COMMAND_LINUX: | | |
| auditwheel repair \ | |
| --exclude libc10.so \ | |
| --exclude libtorch.so \ | |
| --exclude libtorch_cpu.so \ | |
| --exclude libtorch_cuda.so \ | |
| --exclude libc10_cuda.so \ | |
| --exclude libnvrtc.so.* \ | |
| -w {dest_dir} {wheel} | |
| CIBW_REPAIR_WHEEL_COMMAND_MACOS: | | |
| delocate-wheel --ignore-missing-dependencies \ | |
| --require-archs {delocate_archs} \ | |
| -w {dest_dir} -v {wheel} | |
| CIBW_BEFORE_BUILD_WINDOWS: pip install delvewheel | |
| CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: > | |
| delvewheel repair | |
| --no-dll c10.dll | |
| --no-dll torch.dll | |
| --no-dll torch_cpu.dll | |
| --no-dll torch_cuda.dll | |
| --no-dll c10_cuda.dll | |
| -w {dest_dir} {wheel} | |
| CIBW_ENVIRONMENT: > | |
| SPHERICART_ARCH_NATIVE=OFF | |
| SPHERICART_NO_LOCAL_DEPS=1 | |
| TORCH_CUDA_ARCH_LIST="8.0 8.6 8.9 9.0" | |
| SPHERICART_TORCH_BUILD_WITH_TORCH_VERSION=${{ matrix.pytorch-version }}.* | |
| CIBW_ENVIRONMENT_WINDOWS: > | |
| SPHERICART_ARCH_NATIVE=OFF | |
| SPHERICART_NO_LOCAL_DEPS=1 | |
| TORCH_CUDA_ARCH_LIST="8.0 8.6 8.9 9.0" | |
| SPHERICART_TORCH_BUILD_WITH_TORCH_VERSION=${{ matrix.pytorch-version }}.* | |
| PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu126 | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: torch-single-version-wheel-${{ matrix.os }}-${{ matrix.arch }}-torch-${{ matrix.pytorch-version }} | |
| path: ./wheelhouse/*.whl | |
| merge-torch-wheels: | |
| needs: build-torch-wheels | |
| runs-on: ubuntu-22.04 | |
| name: merge wheels for ${{ matrix.name }} | |
| strategy: | |
| matrix: | |
| include: | |
| - name: x86_64 Linux | |
| os: ubuntu-22.04 | |
| arch: x86_64 | |
| - name: arm64 macOS | |
| os: macos-14 | |
| arch: arm64 | |
| - name: aarch64 Linux | |
| os: ubuntu-22.04-arm | |
| arch: aarch64 | |
| - name: x86_64 Windows | |
| os: windows-2022 | |
| arch: AMD64 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download wheels | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: torch-single-version-wheel-${{ matrix.os }}-${{ matrix.arch }}-* | |
| merge-multiple: false | |
| path: dist | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: install dependencies | |
| run: python -m pip install twine wheel | |
| - name: merge wheels | |
| run: | | |
| # collect all torch versions used for the build | |
| REQUIRES_TORCH=$(find dist -name "*.whl" -exec unzip -p {} "sphericart_torch-*.dist-info/METADATA" \; | grep "Requires-Dist: torch") | |
| MERGED_TORCH_REQUIRE=$(python scripts/create-torch-versions-range.py "$REQUIRES_TORCH") | |
| echo MERGED_TORCH_REQUIRE=$MERGED_TORCH_REQUIRE | |
| # unpack all single torch versions wheels in the same directory | |
| mkdir dist/unpacked | |
| find dist -name "*.whl" -print -exec python -m wheel unpack --dest dist/unpacked/ {} ';' | |
| sed -i "s/Requires-Dist: torch.*/$MERGED_TORCH_REQUIRE/" dist/unpacked/sphericart_torch-*/sphericart_torch-*.dist-info/METADATA | |
| echo "\n\n METADATA = \n\n" | |
| cat dist/unpacked/sphericart_torch-*/sphericart_torch-*.dist-info/METADATA | |
| # check the right metadata was added to the file. grep will exit with | |
| # code `1` if the line is not found, which will stop CI | |
| grep "$MERGED_TORCH_REQUIRE" dist/unpacked/sphericart_torch-*/sphericart_torch-*.dist-info/METADATA | |
| # repack the directory as a new wheel | |
| mkdir wheelhouse | |
| python -m wheel pack --dest wheelhouse/ dist/unpacked/* | |
| - name: check wheels with twine | |
| run: twine check wheelhouse/* | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: sphericart-torch-wheel-${{ matrix.os }}-${{ matrix.arch }} | |
| path: ./wheelhouse/*.whl | |
| - name: upload to GitHub release | |
| if: startsWith(github.ref, 'refs/tags/') | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| ./wheelhouse/*.whl | |
| prerelease: ${{ contains(github.ref, '-rc') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |