Skip to content

Commit 7920d40

Browse files
committed
Set up CI
Copied from torchvision. ghstack-source-id: 8ed228d Pull Request resolved: #87
1 parent d2ea838 commit 7920d40

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

.github/scripts/setup-env.sh

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
# test dependency
110+
pip install numpy
111+
echo '::endgroup::'
112+
113+
echo '::group::Install TorchVision'
114+
python setup.py develop
115+
echo '::endgroup::'
116+
117+
echo '::group::Collect environment information'
118+
conda list
119+
python -m torch.utils.collect_env
120+
echo '::endgroup::'

.github/scripts/unittest.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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::'
14+
15+
pytest test/ --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v

.github/workflows/tests.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
workflow_dispatch:
9+
10+
jobs:
11+
unittests-linux:
12+
strategy:
13+
matrix:
14+
python-version:
15+
- "3.8"
16+
runner: ["linux.12xlarge"]
17+
gpu-arch-type: ["cpu"]
18+
include:
19+
- python-version: 3.11
20+
runner: linux.g5.4xlarge.nvidia.gpu
21+
gpu-arch-type: cuda
22+
gpu-arch-version: "11.8"
23+
fail-fast: false
24+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
25+
with:
26+
repository: pytorch/extension-cpp
27+
runner: ${{ matrix.runner }}
28+
gpu-arch-type: ${{ matrix.gpu-arch-type }}
29+
gpu-arch-version: ${{ matrix.gpu-arch-version }}
30+
timeout: 120
31+
script: |
32+
set -euo pipefail
33+
34+
export PYTHON_VERSION=${{ matrix.python-version }}
35+
export GPU_ARCH_TYPE=${{ matrix.gpu-arch-type }}
36+
export GPU_ARCH_VERSION=${{ matrix.gpu-arch-version }}
37+
38+
./.github/scripts/unittest.sh

0 commit comments

Comments
 (0)