Skip to content

Commit 94c81c2

Browse files
atalmanmalfetNicolasHug
authored
M1 fixes cherry (#6167)
* Add M1 wheels binary builds (#5948) * [M1] Set build version and delocate wheels (#6110) This would package libpng and libjpeg.dylib into wheel files Add a very simple test step, copied from https://github.com/pytorch/pytorch.github.io/blob/1eaa33a3d3f1b83b64c5031c6dd04dbb238d6105/scripts/test_install.py#L78 Cherry-picked from https://github.com/pytorch/builder/blob/d0bc74cc363a9da5a8b6a40e883d40d25d050036/build_m1_domains.sh#L22 * [BE] Unify version computation (#6117) * [BE] Unify version computation Instead of hardcoding dev version in various script, use one from `version.txt` if `setup_build_version` is called without arguments Also, pass `--pre` option to M1 build/test pip install commands to build TorchVision against nightly pytorch * Pin torchvision dependency to a specific pytorch version * [M1] Install "jpeg<=9b" rather than OpenJpeg (#6122) Explicitly set PATH to point to `conda` binary, otherwise libjpeg detection logic does not work Pin libjpeg to the same version on x86 and m1 Add simple tests that jpeg can be decoded by a generated wheel * Add unit-tests for M1 (#6132) * Add M1 testing job * libjpeg -> jpeg<=9b in test-m1.yml * Added export PATH=~/miniconda3/bin... from 6122 * Tests were OK, let's see if we can remove the pinning * GH: Add M1 conda build workflows (#6135) Clean up Conda build folder before every run Enable artifact upload to GitHub for every workflow run, but upload to Conda/S3 only on nightly pushes Test plan: `conda install -c pytorch-nightly torchvision; python -c "import torchvision;print(torchvision.io.read_image('hummingbird.jpg').shape)"` * Fix `Test M1` workflow By passing `--pre` option to `pip install`, otherwise torchvision were always tested against last PyTorch release * Adding tagged builds for M1 (#6140) * Adding tagged builds * Testing * Testing * Testing * Testing * Adding conda builds * Fix `if` condition for s3/conda uploads (#6146) Replace `steps.extract_branch.outputs.branch` (which were probably taken from https://stackoverflow.com/questions/58033366/how-to-get-the-current-branch-within-github-actions ) with straightforward `github.event.ref` Tested in https://github.com/malfet/deleteme/runs/6822647720?check_suite_focus=true and https://github.com/malfet/deleteme/runs/6822691158?check_suite_focus=true * Fix typo in GHA nightly build condition (#6158) s#ref/heads/#refs/heads/# I should have noticed it while copy-n-pasting the condition. Unfortunately there are no way to test is other than in prod, but nightly builds are still not getting pushed, see https://github.com/pytorch/vision/runs/6860407007?check_suite_focus=true for example * Making sure we are building against release * Testing Testing Testing Testing testing Testing Testing Testing Testing Testing Testing Testing * Testing * Testing * Cleanup * Refactoring logic Co-authored-by: Nikita Shulga <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent 9dd7cfd commit 94c81c2

File tree

6 files changed

+243
-6
lines changed

6 files changed

+243
-6
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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

.github/workflows/test-m1.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Unit-tests on M1
2+
on:
3+
pull_request:
4+
paths:
5+
- .github/workflows/test-m1.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+
tests:
20+
name: "Unit-tests on M1"
21+
runs-on: macos-m1
22+
strategy:
23+
matrix:
24+
py_vers: [ "3.8"]
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v2
29+
- name: Set CHANNEL (only for tagged pushes)
30+
if: ${{ github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') }}
31+
run: |
32+
# reference ends with an RC suffix
33+
if [[ ${GITHUB_REF_NAME} = *-rc[0-9]* ]]; then
34+
echo "CHANNEL=test" >> "$GITHUB_ENV"
35+
fi
36+
- name: Set Release CHANNEL (for release)
37+
if: ${{ github.event_name == 'pull_request' && startsWith(github.base_ref, 'release') }}
38+
run: |
39+
echo "CHANNEL=test" >> "$GITHUB_ENV"
40+
- name: Install TorchVision
41+
shell: arch -arch arm64 bash {0}
42+
env:
43+
ENV_NAME: conda-env-${{ github.run_id }}
44+
PY_VERS: ${{ matrix.py_vers }}
45+
run: |
46+
. ~/miniconda3/etc/profile.d/conda.sh
47+
# Needed for JPEG library detection as setup.py detects conda presence by running `shlex.which('conda')`
48+
export PATH=~/miniconda3/bin:$PATH
49+
set -ex
50+
conda create -yp ${ENV_NAME} python=${PY_VERS} numpy libpng jpeg scipy
51+
conda run -p ${ENV_NAME} python3 -mpip install --pre torch --extra-index-url=https://download.pytorch.org/whl/${CHANNEL}
52+
conda run -p ${ENV_NAME} python3 setup.py develop
53+
conda run -p ${ENV_NAME} python3 -mpip install pytest pytest-mock av
54+
- name: Run tests
55+
shell: arch -arch arm64 bash {0}
56+
env:
57+
ENV_NAME: conda-env-${{ github.run_id }}
58+
PY_VERS: ${{ matrix.py_vers }}
59+
run: |
60+
. ~/miniconda3/etc/profile.d/conda.sh
61+
set -ex
62+
conda run -p ${ENV_NAME} --no-capture-output python3 -u -mpytest -v --tb=long --durations 20
63+
conda env remove -p ${ENV_NAME}

packaging/build_cmake.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1515
. "$script_dir/pkg_helpers.bash"
1616

1717
export BUILD_TYPE=conda
18-
setup_env 0.13.0
18+
setup_env
1919
export SOURCE_ROOT_DIR="$PWD"
2020
setup_conda_pytorch_constraint
2121
setup_conda_cudatoolkit_plain_constraint

packaging/build_conda.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55
. "$script_dir/pkg_helpers.bash"
66

77
export BUILD_TYPE=conda
8-
setup_env 0.13.0
8+
setup_env
99
export SOURCE_ROOT_DIR="$PWD"
1010
setup_conda_pytorch_constraint
1111
setup_conda_cudatoolkit_constraint

packaging/build_wheel.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55
. "$script_dir/pkg_helpers.bash"
66

77
export BUILD_TYPE=wheel
8-
setup_env 0.13.0
8+
setup_env
99
setup_wheel_python
1010
pip_install numpy pyyaml future ninja
1111
pip_install --upgrade setuptools

packaging/pkg_helpers.bash

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,31 @@ setup_cuda() {
100100
# Usage: setup_build_version 0.2.0
101101
setup_build_version() {
102102
if [[ -z "$BUILD_VERSION" ]]; then
103-
export BUILD_VERSION="$1.dev$(date "+%Y%m%d")$VERSION_SUFFIX"
103+
if [[ -z "$1" ]]; then
104+
setup_base_build_version
105+
else
106+
BUILD_VERSION="$1"
107+
fi
108+
BUILD_VERSION="$BUILD_VERSION.dev$(date "+%Y%m%d")$VERSION_SUFFIX"
104109
else
105-
export BUILD_VERSION="$BUILD_VERSION$VERSION_SUFFIX"
110+
BUILD_VERSION="$BUILD_VERSION$VERSION_SUFFIX"
106111
fi
107112

108113
# Set build version based on tag if on tag
109114
if [[ -n "${CIRCLE_TAG}" ]]; then
110115
# Strip tag
111-
export BUILD_VERSION="$(echo "${CIRCLE_TAG}" | sed -e 's/^v//' -e 's/-.*$//')${VERSION_SUFFIX}"
116+
BUILD_VERSION="$(echo "${CIRCLE_TAG}" | sed -e 's/^v//' -e 's/-.*$//')${VERSION_SUFFIX}"
112117
fi
118+
119+
export BUILD_VERSION
120+
}
121+
122+
setup_base_build_version() {
123+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
124+
# version.txt for some reason has `a` character after major.minor.rev
125+
# command below yields 0.10.0 from version.txt containing 0.10.0a0
126+
BUILD_VERSION=$( cut -f 1 -d a "$SCRIPT_DIR/../version.txt" )
127+
export BUILD_VERSION
113128
}
114129

115130
# Set some useful variables for OS X, if applicable

0 commit comments

Comments
 (0)