Skip to content

Commit ae7e24e

Browse files
committed
Set up CI
Copied from torchvision. ghstack-source-id: 49241f2 Pull Request resolved: #87
1 parent d209fd4 commit ae7e24e

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

.github/scripts/setup-env.sh

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
# Prepare conda
6+
set +x && eval "$($(which conda) shell.bash hook)" && set -x
7+
8+
# Setup the OS_TYPE environment variable that should be used for conditions involving the OS below.
9+
case $(uname) in
10+
Linux)
11+
OS_TYPE=linux
12+
;;
13+
Darwin)
14+
OS_TYPE=macos
15+
;;
16+
MSYS*)
17+
OS_TYPE=windows
18+
;;
19+
*)
20+
echo "Unknown OS type:" $(uname)
21+
exit 1
22+
;;
23+
esac
24+
25+
if [[ "${OS_TYPE}" == "macos" && $(uname -m) == x86_64 ]]; then
26+
echo '::group::Uninstall system JPEG libraries on macOS'
27+
# The x86 macOS runners, e.g. the GitHub Actions native "macos-12" runner, has some JPEG and PNG libraries
28+
# installed by default that interfere with our build. We uninstall them here and use the one from conda below.
29+
IMAGE_LIBS=$(brew list | grep -E "jpeg|png")
30+
for lib in $IMAGE_LIBS; do
31+
brew uninstall --ignore-dependencies --force "${lib}"
32+
done
33+
echo '::endgroup::'
34+
fi
35+
36+
echo '::group::Create build environment'
37+
# See https://github.com/pytorch/vision/issues/7296 for ffmpeg
38+
conda create \
39+
--name ci \
40+
--quiet --yes \
41+
python="${PYTHON_VERSION}" pip \
42+
ninja cmake \
43+
libpng \
44+
'ffmpeg<4.3'
45+
conda activate ci
46+
conda install --quiet --yes libjpeg-turbo -c pytorch
47+
pip install --progress-bar=off --upgrade setuptools
48+
49+
# See https://github.com/pytorch/vision/issues/6790
50+
if [[ "${PYTHON_VERSION}" != "3.11" ]]; then
51+
pip install --progress-bar=off av!=10.0.0
52+
fi
53+
54+
echo '::endgroup::'
55+
56+
if [[ "${OS_TYPE}" == windows && "${GPU_ARCH_TYPE}" == cuda ]]; then
57+
echo '::group::Install VisualStudio CUDA extensions on Windows'
58+
if [[ "${VC_YEAR:-}" == "2022" ]]; then
59+
TARGET_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2022/BuildTools/MSBuild/Microsoft/VC/v170/BuildCustomizations"
60+
else
61+
TARGET_DIR="/c/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/MSBuild/Microsoft/VC/v160/BuildCustomizations"
62+
fi
63+
mkdir -p "${TARGET_DIR}"
64+
cp -r "${CUDA_HOME}/MSBuildExtensions/"* "${TARGET_DIR}"
65+
echo '::endgroup::'
66+
fi
67+
68+
echo '::group::Install PyTorch'
69+
# TODO: Can we maybe have this as environment variable in the job template? For example, `IS_RELEASE`.
70+
if [[ (${GITHUB_EVENT_NAME} = 'pull_request' && (${GITHUB_BASE_REF} = 'release'*)) || (${GITHUB_REF} = 'refs/heads/release'*) ]]; then
71+
CHANNEL=test
72+
else
73+
CHANNEL=nightly
74+
fi
75+
76+
case $GPU_ARCH_TYPE in
77+
cpu)
78+
GPU_ARCH_ID="cpu"
79+
;;
80+
cuda)
81+
VERSION_WITHOUT_DOT=$(echo "${GPU_ARCH_VERSION}" | sed 's/\.//')
82+
GPU_ARCH_ID="cu${VERSION_WITHOUT_DOT}"
83+
;;
84+
*)
85+
echo "Unknown GPU_ARCH_TYPE=${GPU_ARCH_TYPE}"
86+
exit 1
87+
;;
88+
esac
89+
PYTORCH_WHEEL_INDEX="https://download.pytorch.org/whl/${CHANNEL}/${GPU_ARCH_ID}"
90+
pip install --progress-bar=off --pre torch --index-url="${PYTORCH_WHEEL_INDEX}"
91+
92+
if [[ $GPU_ARCH_TYPE == 'cuda' ]]; then
93+
python -c "import torch; exit(not torch.cuda.is_available())"
94+
fi
95+
echo '::endgroup::'
96+
97+
echo '::group::Install third party dependencies prior to TorchVision install'
98+
# Installing with `easy_install`, e.g. `python setup.py install` or `python setup.py develop`, has some quirks when
99+
# when pulling in third-party dependencies. For example:
100+
# - On Windows, we often hit an SSL error although `pip` can install just fine.
101+
# - It happily pulls in pre-releases, which can lead to more problems down the line.
102+
# `pip` does not unless explicitly told to do so.
103+
# Thus, we use `easy_install` to extract the third-party dependencies here and install them upfront with `pip`.
104+
python setup.py egg_info
105+
# The requires.txt cannot be used with `pip install -r` directly. The requirements are listed at the top and the
106+
# optional dependencies come in non-standard syntax after a blank line. Thus, we just extract the header.
107+
sed -e '/^$/,$d' *.egg-info/requires.txt | tee requirements.txt
108+
pip install --progress-bar=off -r requirements.txt
109+
echo '::endgroup::'
110+
111+
echo '::group::Install TorchVision'
112+
python setup.py develop
113+
echo '::endgroup::'
114+
115+
echo '::group::Collect environment information'
116+
conda list
117+
python -m torch.utils.collect_env
118+
echo '::endgroup::'

.github/scripts/unittest.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
./.github/scripts/setup-env.sh
6+
7+
# Activate conda environment
8+
eval "$($(which conda) shell.bash hook)" && conda deactivate && conda activate ci
9+
10+
echo '::group::Install testing utilities'
11+
# TODO: remove the <8 constraint on pytest when https://github.com/pytorch/vision/issues/8238 is closed
12+
pip install --progress-bar=off "pytest<8" pytest-mock pytest-cov expecttest!=0.2.0
13+
echo '::endgroup::'

0 commit comments

Comments
 (0)