Skip to content

Commit 961c7a3

Browse files
huydhnfacebook-github-bot
authored andcommitted
Add more sample models to OSS CI (#76)
Summary: This updates the CI to build and test all models under `examples/models`. * A simple script `.ci/scripts/gather_test_models.py` gathers all the models there and makes them available to the CI. All models are then run in parallel. * Install vision and audio as they are needed by `mobilenet` and others We have 8 current models x 2 os (linux and mac) x 2 builds system (buck2 and cmake) = 32 combinations. I will check with the team on the status of quantized models testing and add them in a later PR. Pull Request resolved: #76 Reviewed By: larryliu0820, guangy10 Differential Revision: D48485199 Pulled By: huydhn fbshipit-source-id: d78ee063b89e5be0d0d6ea5757e3c3e72d83feb1
1 parent b26db1d commit 961c7a3

File tree

13 files changed

+163
-36
lines changed

13 files changed

+163
-36
lines changed

.ci/docker/build.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,23 @@ OS_VERSION=22.04
1717
CLANG_VERSION=12
1818
PYTHON_VERSION=3.10
1919
MINICONDA_VERSION=23.5.1-0
20-
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
2120
BUCK2_VERSION=$(cat ci_commit_pins/buck2.txt)
2221

22+
NIGHTLY=$(cat ci_commit_pins/nightly.txt)
23+
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
24+
TORCHAUDIO_VERSION=$(cat ci_commit_pins/audio.txt)
25+
TORCHVISION_VERSION=$(cat ci_commit_pins/vision.txt)
26+
2327
docker build \
2428
--no-cache \
2529
--progress=plain \
2630
--build-arg "OS_VERSION=${OS_VERSION}" \
2731
--build-arg "CLANG_VERSION=${CLANG_VERSION}" \
2832
--build-arg "PYTHON_VERSION=${PYTHON_VERSION}" \
2933
--build-arg "MINICONDA_VERSION=${MINICONDA_VERSION}" \
30-
--build-arg "TORCH_VERSION=${TORCH_VERSION}" \
34+
--build-arg "TORCH_VERSION=${TORCH_VERSION}.${NIGHTLY}" \
35+
--build-arg "TORCHAUDIO_VERSION=${TORCHAUDIO_VERSION}.${NIGHTLY}" \
36+
--build-arg "TORCHVISION_VERSION=${TORCHVISION_VERSION}.${NIGHTLY}" \
3137
--build-arg "BUCK2_VERSION=${BUCK2_VERSION}" \
3238
-f "${OS}"/Dockerfile \
3339
"$@" \

.ci/docker/ci_commit_pins/audio.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.0

.ci/docker/ci_commit_pins/nightly.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dev20230813

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.0.dev20230813
1+
2.1.0

.ci/docker/ci_commit_pins/vision.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.16.0

.ci/docker/common/install_conda.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ install_pip_dependencies() {
4040
pushd /opt/conda
4141
# Install all Python dependencies, including PyTorch
4242
pip_install -r /opt/conda/requirements-ci.txt
43-
pip_install --pre torch=="${TORCH_VERSION}" --index-url https://download.pytorch.org/whl/nightly/cpu
43+
pip_install --pre \
44+
torch=="${TORCH_VERSION}" \
45+
torchaudio=="${TORCHAUDIO_VERSION}" \
46+
torchvision=="${TORCHVISION_VERSION}" \
47+
--index-url https://download.pytorch.org/whl/nightly/cpu
4448
popd
4549
}
4650

.ci/docker/ubuntu/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ RUN bash ./install_user.sh && rm install_user.sh
2828
ARG MINICONDA_VERSION
2929
ARG PYTHON_VERSION
3030
ARG TORCH_VERSION
31+
ARG TORCHAUDIO_VERSION
32+
ARG TORCHVISION_VERSION
3133
ENV PYTHON_VERSION=$PYTHON_VERSION
3234
ENV PATH /opt/conda/envs/py_$PYTHON_VERSION/bin:/opt/conda/bin:$PATH
3335
COPY requirements-ci.txt /opt/conda/

.ci/scripts/gather_test_models.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
import json
9+
import os
10+
from typing import Any
11+
12+
from examples.models import MODEL_NAME_TO_MODEL
13+
14+
15+
def set_output(name: str, val: Any) -> None:
16+
"""
17+
Set the GitHb output so that it can be accessed by other jobs
18+
"""
19+
print(f"Setting {val} to GitHub output")
20+
21+
if os.getenv("GITHUB_OUTPUT"):
22+
with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env:
23+
print(f"{name}={val}", file=env)
24+
else:
25+
print(f"::set-output name={name}::{val}")
26+
27+
28+
def export_models_for_ci() -> None:
29+
"""
30+
This gathers all the example models that we want to test on GitHub OSS CI
31+
"""
32+
# This is the JSON syntax for configuration matrix used by GitHub
33+
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
34+
models = {"include": [{"model": name} for name in MODEL_NAME_TO_MODEL.keys()]}
35+
set_output("models", json.dumps(models))
36+
37+
38+
if __name__ == "__main__":
39+
export_models_for_ci()

.ci/scripts/setup-macos.sh

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
set -exu
99

10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
1013
install_buck() {
1114
if ! command -v zstd &> /dev/null; then
1215
brew install zstd
@@ -33,23 +36,6 @@ install_buck() {
3336
fi
3437
}
3538

36-
install_conda() {
37-
pushd .ci/docker
38-
# Install conda dependencies like flatbuffer
39-
conda install --file conda-env-ci.txt
40-
popd
41-
}
42-
43-
install_pip_dependencies() {
44-
pushd .ci/docker
45-
# Install all Python dependencies, including PyTorch
46-
pip install --progress-bar off -r requirements-ci.txt
47-
48-
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
49-
pip install --progress-bar off --pre torch=="${TORCH_VERSION}" --index-url https://download.pytorch.org/whl/nightly/cpu
50-
popd
51-
}
52-
5339
install_buck
5440
install_conda
5541
install_pip_dependencies

.ci/scripts/test-cmake.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ set -exu
1010
# shellcheck source=/dev/null
1111
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

13+
MODEL_NAME=$1
14+
if [[ -z "${MODEL_NAME:-}" ]]; then
15+
echo "Missing model name, exiting..."
16+
exit 1
17+
else
18+
echo "Testing ${MODEL_NAME} ..."
19+
fi
20+
1321
test_model() {
14-
MODEL_NAME=$1
1522
python -m examples.export.export_example --model_name="${MODEL_NAME}"
1623

1724
# Run test model
@@ -24,7 +31,7 @@ build_and_test_executorch() {
2431
rm -rf "${CMAKE_OUTPUT_DIR}" && mkdir "${CMAKE_OUTPUT_DIR}"
2532

2633
pushd "${CMAKE_OUTPUT_DIR}"
27-
cmake -DBUCK2=buck2 ..
34+
cmake -DBUCK2=buck2 -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" ..
2835
popd
2936

3037
if [ "$(uname)" == "Darwin" ]; then
@@ -35,9 +42,13 @@ build_and_test_executorch() {
3542
cmake --build "${CMAKE_OUTPUT_DIR}" -j "${CMAKE_JOBS}"
3643

3744
which python
38-
# Test the example linear model
39-
test_model "linear"
45+
# Test the select model
46+
test_model
4047
}
4148

49+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
50+
PYTHON_EXECUTABLE=python3
51+
fi
52+
4253
install_executorch
4354
build_and_test_executorch

.ci/scripts/test.sh

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,15 @@ set -exu
1010
# shellcheck source=/dev/null
1111
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

13+
MODEL_NAME=$1
14+
if [[ -z "${MODEL_NAME:-}" ]]; then
15+
echo "Missing model name, exiting..."
16+
exit 1
17+
else
18+
echo "Testing ${MODEL_NAME} ..."
19+
fi
20+
1321
test_model() {
14-
MODEL_NAME=$1
1522
python -m examples.export.export_example --model_name="${MODEL_NAME}"
1623

1724
# Run test model
@@ -23,8 +30,8 @@ build_and_test_executorch() {
2330
buck2 build //examples/executor_runner:executor_runner
2431

2532
which python
26-
# Test the example linear model
27-
test_model "linear"
33+
# Test the select model
34+
test_model
2835
}
2936

3037
install_executorch

.ci/scripts/utils.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,28 @@ install_executorch() {
1313
# Just print out the list of packages for debugging
1414
pip list
1515
}
16+
17+
install_conda() {
18+
pushd .ci/docker || return
19+
# Install conda dependencies like flatbuffer
20+
conda install --file conda-env-ci.txt
21+
popd || return
22+
}
23+
24+
install_pip_dependencies() {
25+
pushd .ci/docker || return
26+
# Install all Python dependencies, including PyTorch
27+
pip install --progress-bar off -r requirements-ci.txt
28+
29+
NIGHTLY=$(cat ci_commit_pins/nightly.txt)
30+
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
31+
TORCHAUDIO_VERSION=$(cat ci_commit_pins/audio.txt)
32+
TORCHVISION_VERSION=$(cat ci_commit_pins/vision.txt)
33+
34+
pip install --progress-bar off --pre \
35+
torch=="${TORCH_VERSION}.${NIGHTLY}" \
36+
torchaudio=="${TORCHAUDIO_VERSION}.${NIGHTLY}" \
37+
torchvision=="${TORCHVISION_VERSION}.${NIGHTLY}" \
38+
--index-url https://download.pytorch.org/whl/nightly/cpu
39+
popd || return
40+
}

.github/workflows/pull.yml

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,39 @@ concurrency:
1212
cancel-in-progress: true
1313

1414
jobs:
15+
gather-models:
16+
runs-on: ubuntu-22.04
17+
outputs:
18+
models: ${{ steps.gather-models.outputs.models }}
19+
steps:
20+
- uses: actions/checkout@v3
21+
- uses: actions/setup-python@v4
22+
with:
23+
python-version: '3.10'
24+
cache: pip
25+
- name: Extract the list of models to test
26+
id: gather-models
27+
run: |
28+
set -eux
29+
30+
source .ci/scripts/utils.sh
31+
# This is a simple Python script but as it tries to import executorch.examples.models,
32+
# it requires a whole bunch of Executorch dependencies on the Docker image
33+
install_pip_dependencies
34+
install_executorch
35+
36+
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py
37+
1538
buck-build-test-linux:
1639
name: buck-build-test-linux
1740
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
41+
needs: gather-models
42+
strategy:
43+
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }}
44+
fail-fast: false
1845
with:
1946
runner: linux.2xlarge
2047
docker-image: executorch-ubuntu-22.04-clang12
21-
fetch-depth: 0
2248
submodules: 'true'
2349
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
2450
script: |
@@ -27,15 +53,20 @@ jobs:
2753
# here, as it's there in the container
2854
export PATH="/opt/conda/envs/py_${PYTHON_VERSION}/bin:${PATH}"
2955
56+
# The name of model we are going to test
57+
MODEL_NAME=${{ matrix.model }}
3058
# Build and test Executorch
31-
bash .ci/scripts/test.sh
32-
59+
bash .ci/scripts/test.sh "${MODEL_NAME}"
3360
# Test custom ops
3461
bash examples/custom_ops/test_custom_ops.sh buck2
3562
3663
buck-build-test-macos:
3764
name: buck-build-test-macos
3865
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
66+
needs: gather-models
67+
strategy:
68+
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }}
69+
fail-fast: false
3970
with:
4071
runner: macos-m1-12
4172
submodules: 'true'
@@ -47,20 +78,24 @@ jobs:
4778
# Setup MacOS dependencies as there is no Docker support on MacOS atm
4879
bash .ci/scripts/setup-macos.sh
4980
81+
# The name of model we are going to test
82+
MODEL_NAME=${{ matrix.model }}
5083
# Build and test Executorch
51-
bash .ci/scripts/test.sh
52-
84+
PYTHON_EXECUTABLE=python bash .ci/scripts/test.sh "${MODEL_NAME}"
5385
# Test custom ops
5486
PYTHON_EXECUTABLE=python bash examples/custom_ops/test_custom_ops.sh buck2
5587
popd
5688
5789
cmake-build-test-linux:
5890
name: cmake-build-test-linux
5991
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
92+
needs: gather-models
93+
strategy:
94+
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }}
95+
fail-fast: false
6096
with:
6197
runner: linux.2xlarge
6298
docker-image: executorch-ubuntu-22.04-clang12
63-
fetch-depth: 0
6499
submodules: 'true'
65100
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
66101
script: |
@@ -69,15 +104,20 @@ jobs:
69104
# here, as it's there in the container
70105
export PATH="/opt/conda/envs/py_${PYTHON_VERSION}/bin:${PATH}"
71106
107+
# The name of model we are going to test
108+
MODEL_NAME=${{ matrix.model }}
72109
# Build and test Executorch
73-
bash .ci/scripts/test-cmake.sh
74-
110+
bash .ci/scripts/test-cmake.sh "${MODEL_NAME}"
75111
# Build and test custom ops
76112
bash examples/custom_ops/test_custom_ops.sh cmake
77113
78114
cmake-build-test-macos:
79115
name: cmake-build-test-macos
80116
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
117+
needs: gather-models
118+
strategy:
119+
matrix: ${{ fromJSON(needs.gather-models.outputs.models) }}
120+
fail-fast: false
81121
with:
82122
runner: macos-m1-12
83123
submodules: 'true'
@@ -89,6 +129,10 @@ jobs:
89129
# Setup MacOS dependencies as there is no Docker support on MacOS atm
90130
bash .ci/scripts/setup-macos.sh
91131
132+
# The name of model we are going to test
133+
MODEL_NAME=${{ matrix.model }}
134+
# Build and test Executorch
135+
PYTHON_EXECUTABLE=python bash .ci/scripts/test-cmake.sh "${MODEL_NAME}"
92136
# Build and test custom ops
93137
PYTHON_EXECUTABLE=python bash examples/custom_ops/test_custom_ops.sh cmake
94138
popd

0 commit comments

Comments
 (0)