|
| 1 | +name: Build on M1 |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + paths: |
| 5 | + - .github/workflows/build-m1-binaries.yml |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - nightly |
| 9 | + - main |
| 10 | + - release/* |
| 11 | + tags: |
| 12 | + # NOTE: Binary build pipelines should only get triggered on release candidate builds |
| 13 | + # Release candidate tags look like: v1.11.0-rc1 |
| 14 | + - v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+ |
| 15 | + workflow_dispatch: |
| 16 | +env: |
| 17 | + CHANNEL: "nightly" |
| 18 | +jobs: |
| 19 | + build_wheels: |
| 20 | + name: "Build TorchVision M1 wheels" |
| 21 | + runs-on: macos-m1 |
| 22 | + strategy: |
| 23 | + matrix: |
| 24 | + py_vers: [ "3.8", "3.9", "3.10" ] |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v2 |
| 28 | + - name: Set CHANNEL (only for tagged pushes) |
| 29 | + if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') }} |
| 30 | + run: | |
| 31 | + # reference ends with an RC suffix |
| 32 | + if [[ ${GITHUB_REF_NAME} = *-rc[0-9]* ]]; then |
| 33 | + echo "CHANNEL=test" >> "$GITHUB_ENV" |
| 34 | + fi |
| 35 | + - name: Set Release CHANNEL (for release) |
| 36 | + if: ${{ (github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')) || startsWith(github.ref, 'release') }} |
| 37 | + run: | |
| 38 | + echo "CHANNEL=test" >> "$GITHUB_ENV" |
| 39 | + - name: Build TorchVision M1 wheel |
| 40 | + shell: arch -arch arm64 bash {0} |
| 41 | + env: |
| 42 | + ENV_NAME: conda-env-${{ github.run_id }} |
| 43 | + PY_VERS: ${{ matrix.py_vers }} |
| 44 | + run: | |
| 45 | + . ~/miniconda3/etc/profile.d/conda.sh |
| 46 | + # Needed for JPEG library detection as setup.py detects conda presence by running `shlex.which('conda')` |
| 47 | + export PATH=~/miniconda3/bin:$PATH |
| 48 | + set -ex |
| 49 | + . packaging/pkg_helpers.bash |
| 50 | + # if we are uploading to test channell, our version consist only of the base: 0.x.x - no date string or suffix added |
| 51 | + if [[ $CHANNEL == "test" ]]; then |
| 52 | + setup_base_build_version |
| 53 | + else |
| 54 | + setup_build_version |
| 55 | + fi |
| 56 | +
|
| 57 | + WHL_NAME=torchvision-${BUILD_VERSION}-cp${PY_VERS/.}-cp${PY_VERS/.}-macosx_11_0_arm64.whl |
| 58 | + conda create -yp ${ENV_NAME} python=${PY_VERS} numpy libpng jpeg wheel pkg-config |
| 59 | + conda run -p ${ENV_NAME} python3 -mpip install torch --pre --extra-index-url=https://download.pytorch.org/whl/${CHANNEL} |
| 60 | + conda run -p ${ENV_NAME} python3 -mpip install delocate |
| 61 | + conda run -p ${ENV_NAME} python3 setup.py bdist_wheel |
| 62 | + export PYTORCH_VERSION="$(conda run -p ${ENV_NAME} python3 -mpip show torch | grep ^Version: | sed 's/Version: *//')" |
| 63 | + conda run -p ${ENV_NAME} DYLD_FALLBACK_LIBRARY_PATH="${ENV_NAME}/lib" delocate-wheel -v --ignore-missing-dependencies dist/${WHL_NAME} |
| 64 | + conda env remove -p ${ENV_NAME} |
| 65 | + - name: Test wheel |
| 66 | + shell: arch -arch arm64 bash {0} |
| 67 | + env: |
| 68 | + ENV_NAME: conda-test-env-${{ github.run_id }} |
| 69 | + PY_VERS: ${{ matrix.py_vers }} |
| 70 | + run: | |
| 71 | + . ~/miniconda3/etc/profile.d/conda.sh |
| 72 | + set -ex |
| 73 | + conda create -yp ${ENV_NAME} python=${PY_VERS} numpy |
| 74 | + conda run -p ${ENV_NAME} python3 -mpip install torch --pre --extra-index-url=https://download.pytorch.org/whl/${CHANNEL} |
| 75 | + conda run -p ${ENV_NAME} python3 -mpip install dist/*.whl |
| 76 | + # Test torch is importable, by changing cwd and running import commands |
| 77 | + conda run --cwd /tmp -p ${ENV_NAME} python3 -c "import torchvision;print('torchvision version is ', torchvision.__version__)" |
| 78 | + conda run --cwd /tmp -p ${ENV_NAME} python3 -c "import torch;import torchvision;print('Is torchvision useable?', all(x is not None for x in [torch.ops.image.decode_png, torch.ops.torchvision.roi_align]))" |
| 79 | + conda run --cwd /tmp -p ${ENV_NAME} python3 -c "import torchvision;print(torchvision.io.read_image('${PWD}/gallery/assets/dog1.jpg').shape)" |
| 80 | + conda env remove -p ${ENV_NAME} |
| 81 | + - name: Upload wheel to GitHub |
| 82 | + uses: actions/upload-artifact@v3 |
| 83 | + with: |
| 84 | + name: torchvision-py${{ matrix.py_vers }}-macos11-m1 |
| 85 | + path: dist/ |
| 86 | + - name: Upload wheel to S3 |
| 87 | + if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/nightly' || startsWith(github.event.ref, 'refs/tags/')) }} |
| 88 | + shell: arch -arch arm64 bash {0} |
| 89 | + env: |
| 90 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PYTORCH_UPLOADER_ACCESS_KEY_ID }} |
| 91 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_PYTORCH_UPLOADER_SECRET_ACCESS_KEY }} |
| 92 | + run: | |
| 93 | + for pkg in dist/*; do |
| 94 | + aws s3 cp "$pkg" "s3://pytorch/whl/${CHANNEL}/cpu/" --acl public-read |
| 95 | + done |
| 96 | + build_conda: |
| 97 | + name: "Build TorchVision M1 conda packages" |
| 98 | + runs-on: macos-m1 |
| 99 | + strategy: |
| 100 | + matrix: |
| 101 | + py_vers: [ "3.8", "3.9", "3.10" ] |
| 102 | + steps: |
| 103 | + - name: Checkout repository |
| 104 | + uses: actions/checkout@v2 |
| 105 | + - name: Set CHANNEL (only for tagged pushes) |
| 106 | + if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') }} |
| 107 | + run: | |
| 108 | + # reference ends with an RC suffix |
| 109 | + if [[ ${GITHUB_REF_NAME} = *-rc[0-9]* ]]; then |
| 110 | + echo "CHANNEL=test" >> "$GITHUB_ENV" |
| 111 | + fi |
| 112 | + - name: Set CHANNEL Release (for release) |
| 113 | + if: ${{ (github.event_name == 'pull_request' && startsWith(github.base_ref, 'release')) || startsWith(github.ref, 'release') }} |
| 114 | + run: | |
| 115 | + echo "CHANNEL=test" >> "$GITHUB_ENV" |
| 116 | + - name: Install conda-build and purge previous artifacts |
| 117 | + shell: arch -arch arm64 bash {0} |
| 118 | + run: | |
| 119 | + . ~/miniconda3/etc/profile.d/conda.sh |
| 120 | + conda install -yq conda-build |
| 121 | + conda build purge-all |
| 122 | +
|
| 123 | + - name: Build TorchVision M1 conda package |
| 124 | + shell: arch -arch arm64 bash {0} |
| 125 | + env: |
| 126 | + ENV_NAME: conda-env-${{ github.run_id }} |
| 127 | + PYTHON_VERSION: ${{ matrix.py_vers }} |
| 128 | + CU_VERSION: cpu |
| 129 | + run: | |
| 130 | + . ~/miniconda3/etc/profile.d/conda.sh |
| 131 | + set -ex |
| 132 | + . packaging/pkg_helpers.bash |
| 133 | +
|
| 134 | + if [[ $CHANNEL == "test" ]]; then |
| 135 | + setup_base_build_version |
| 136 | + else |
| 137 | + setup_build_version |
| 138 | + fi |
| 139 | +
|
| 140 | + setup_conda_pytorch_constraint |
| 141 | + export SOURCE_ROOT_DIR=$(pwd) |
| 142 | + conda build -c defaults $CONDA_CHANNEL_FLAGS --no-anaconda-upload --python "$PYTHON_VERSION" packaging/torchvision |
| 143 | + mkdir -p dist |
| 144 | + cp ~/miniconda3/conda-bld/osx-arm64/*.tar.bz2 dist/ |
| 145 | + - name: Upload package to GitHub |
| 146 | + uses: actions/upload-artifact@v3 |
| 147 | + with: |
| 148 | + name: torchvision-py${{ matrix.py_vers }}-macos11-m1-conda |
| 149 | + path: dist/ |
| 150 | + - name: Upload package to conda |
| 151 | + if: ${{ github.event_name == 'push' && (github.event.ref == 'refs/heads/nightly' || startsWith(github.event.ref, 'refs/tags/')) }} |
| 152 | + shell: arch -arch arm64 bash {0} |
| 153 | + env: |
| 154 | + CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }} |
| 155 | + run: | |
| 156 | + . ~/miniconda3/etc/profile.d/conda.sh |
| 157 | + conda install -yq anaconda-client |
| 158 | + set -x |
| 159 | + anaconda -t "${CONDA_PYTORCHBOT_TOKEN}" upload ~/miniconda3/conda-bld/osx-arm64/*.tar.bz2 -u "pytorch-${CHANNEL}" --label main --no-progress --force |
0 commit comments