Skip to content

Commit 7587ad7

Browse files
Merge branch 'pytorch:main' into oss_model_execution
2 parents 59f837d + f65c28e commit 7587ad7

File tree

398 files changed

+7573
-3175
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

398 files changed

+7573
-3175
lines changed

.ci/docker/ci_commit_pins/pytorch.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b556d31586845fb1e296a975d2b85d9d325205c9
1+
c42ac54d9e817bf0a0366eb78e6c8beba4d5eff5

.ci/docker/common/install_linter.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1313
# NB: Install all linter dependencies, the caching of lintrunner init could be
1414
# done after Executorch becomes public
1515
pip_install -r requirements-lintrunner.txt
16+
17+
# Install google-java-format
18+
curl -L --retry 3 https://github.com/google/google-java-format/releases/download/v1.23.0/google-java-format_linux-x86-64 > /opt/google-java-format
19+
chmod +x /opt/google-java-format

.ci/scripts/setup-ios.sh

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
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+
set -exu
9+
10+
# This script follows the instructions from GitHub to install an Apple certificate
11+
# https://docs.github.com/en/actions/use-cases-and-examples/deploying/installing-an-apple-certificate-on-macos-runners-for-xcode-development
12+
13+
CERTIFICATE_PATH="${RUNNER_TEMP}"/build_certificate.p12
14+
PP_PATH="${RUNNER_TEMP}"/build_pp.mobileprovision
15+
KEYCHAIN_PATH="${RUNNER_TEMP}"/app-signing.keychain-db
16+
17+
# Import certificate and provisioning profile from secrets
18+
echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH
19+
echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH
20+
21+
# Create a temporary keychain
22+
security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
23+
security set-keychain-settings -lut 21600 $KEYCHAIN_PATH
24+
security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
25+
26+
# Import certificate to the keychain
27+
security import $CERTIFICATE_PATH -P "" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH
28+
security set-key-partition-list -S apple-tool:,apple: -k "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH
29+
security list-keychain -d user -s $KEYCHAIN_PATH
30+
31+
# Apply provisioning profile
32+
mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles
33+
cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles

.ci/scripts/setup-linux.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,5 @@ fi
2020

2121
# As Linux job is running inside a Docker container, all of its dependencies
2222
# have already been installed
23-
install_flatc_from_source
2423
install_executorch
2524
build_executorch_runner "${BUILD_TOOL}"

.ci/scripts/setup-macos.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,5 @@ if [[ -z "${GITHUB_RUNNER:-}" ]]; then
128128
fi
129129

130130
print_cmake_info
131-
install_pytorch_and_domains
132-
install_flatc_from_source
133131
install_executorch
134132
build_executorch_runner "${BUILD_TOOL}"

.ci/scripts/test_llava.sh

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@
88
set -exu
99
# shellcheck source=/dev/null
1010

11+
BUILD_TYPE=${1:-Debug}
12+
13+
echo "Building with BUILD_TYPE: $BUILD_TYPE"
14+
1115
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1216
PYTHON_EXECUTABLE=python3
1317
fi
1418

1519
cmake_install_executorch_libraries() {
1620
cmake \
1721
-DCMAKE_INSTALL_PREFIX=cmake-out \
18-
-DCMAKE_BUILD_TYPE=Debug \
22+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
1923
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
2024
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
2125
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
@@ -27,7 +31,7 @@ cmake_install_executorch_libraries() {
2731
-Bcmake-out .
2832

2933

30-
cmake --build cmake-out -j9 --target install --config Debug
34+
cmake --build cmake-out -j9 --target install --config ${BUILD_TYPE}
3135
}
3236

3337
cmake_build_llava_runner() {
@@ -36,7 +40,7 @@ cmake_build_llava_runner() {
3640

3741
cmake \
3842
-DCMAKE_INSTALL_PREFIX=cmake-out \
39-
-DCMAKE_BUILD_TYPE=Debug \
43+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
4044
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
4145
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
4246
-DEXECUTORCH_BUILD_XNNPACK=ON \
@@ -45,7 +49,7 @@ cmake_build_llava_runner() {
4549
${dir}
4650

4751

48-
cmake --build cmake-out/${dir} -j9 --config Debug
52+
cmake --build cmake-out/${dir} -j9 --config ${BUILD_TYPE}
4953
}
5054

5155
# only export the one without custom op for now since it's
@@ -54,6 +58,13 @@ export_llava() {
5458
$PYTHON_EXECUTABLE -m executorch.examples.models.llava.export_llava --pte-name llava.pte --with-artifacts
5559
}
5660

61+
# Download a new image with different size, to test if the model can handle different image sizes
62+
prepare_image_tensor() {
63+
echo "Downloading image"
64+
curl -o basketball.jpg https://upload.wikimedia.org/wikipedia/commons/7/73/Chicago_Bulls_and_New_Jersey_Nets%2C_March_28%2C_1991.jpg
65+
$PYTHON_EXECUTABLE -m executorch.examples.models.llava.image_util --image-path basketball.jpg --output-path image.pt
66+
}
67+
5768
run_and_verify() {
5869
NOW=$(date +"%H:%M:%S")
5970
echo "Starting to run llava runner at ${NOW}"
@@ -79,7 +90,12 @@ run_and_verify() {
7990
# verify result.txt
8091
RESULT=$(cat result.txt)
8192
# set the expected prefix to be the same as prompt because there's a bug in sdpa_with_kv_cache that causes <unk> tokens.
82-
EXPECTED_PREFIX="ASSISTANT:"
93+
if [[ "$(uname)" == "Darwin" ]]; then
94+
EXPECTED_PREFIX="ASSISTANT: image captures a basketball game in progress on a basketball court. There are several players on the court, with one player in the foreground holding a basketball, and"
95+
else
96+
# set the expected prefix to be the same as prompt because there's a bug in sdpa_with_kv_cache that causes <unk> tokens.
97+
EXPECTED_PREFIX="ASSISTANT:"
98+
fi
8399
if [[ "${RESULT}" == *"${EXPECTED_PREFIX}"* ]]; then
84100
echo "Expected result prefix: ${EXPECTED_PREFIX}"
85101
echo "Actual result: ${RESULT}"
@@ -96,4 +112,5 @@ run_and_verify() {
96112
cmake_install_executorch_libraries
97113
cmake_build_llava_runner
98114
export_llava
115+
prepare_image_tensor
99116
run_and_verify

.ci/scripts/utils.sh

Lines changed: 3 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ retry () {
1919
install_executorch() {
2020
which pip
2121
# Install executorch, this assumes that Executorch is checked out in the
22-
# current directory. The --extra-index-url options tell pip to look on the
23-
# pytorch servers for nightly and pre-release versions of torch packages.
24-
pip install . --no-build-isolation -v \
25-
--extra-index-url https://download.pytorch.org/whl/test/cpu \
26-
--extra-index-url https://download.pytorch.org/whl/nightly/cpu
22+
# current directory.
23+
# TODO(T199538337): clean up install scripts to use install_requirements.sh
24+
./install_requirements.sh --pybind xnnpack
2725
# Just print out the list of packages for debugging
2826
pip list
2927
}
@@ -35,42 +33,6 @@ install_pip_dependencies() {
3533
popd || return
3634
}
3735

38-
install_domains() {
39-
echo "Install torchvision and torchaudio"
40-
pip install --no-use-pep517 --user "git+https://github.com/pytorch/audio.git@${TORCHAUDIO_VERSION}"
41-
pip install --no-use-pep517 --user "git+https://github.com/pytorch/vision.git@${TORCHVISION_VERSION}"
42-
}
43-
44-
install_pytorch_and_domains() {
45-
pushd .ci/docker || return
46-
TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
47-
popd || return
48-
49-
git clone https://github.com/pytorch/pytorch.git
50-
51-
# Fetch the target commit
52-
pushd pytorch || return
53-
git checkout "${TORCH_VERSION}"
54-
git submodule update --init --recursive
55-
56-
export _GLIBCXX_USE_CXX11_ABI=0
57-
# Then build and install PyTorch
58-
python setup.py bdist_wheel
59-
pip install "$(echo dist/*.whl)"
60-
61-
# Grab the pinned audio and vision commits from PyTorch
62-
TORCHAUDIO_VERSION=$(cat .github/ci_commit_pins/audio.txt)
63-
export TORCHAUDIO_VERSION
64-
TORCHVISION_VERSION=$(cat .github/ci_commit_pins/vision.txt)
65-
export TORCHVISION_VERSION
66-
67-
install_domains
68-
69-
popd || return
70-
# Print sccache stats for debugging
71-
sccache --show-stats || true
72-
}
73-
7436
install_flatc_from_source() {
7537
# NB: This function could be used to install flatbuffer from source
7638
pushd third-party/flatbuffers || return

.github/workflows/android-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ jobs:
156156
BUILD_MODE="cmake"
157157
DTYPE="fp32"
158158
159-
if [[ ${{ matrix.model }} == "stories*"" ]]; then
159+
if [[ ${{ matrix.model }} =~ ^stories* ]]; then
160160
# Install requirements for export_llama
161161
PYTHON_EXECUTABLE=python bash examples/models/llama2/install_requirements.sh
162162
# Test llama2

.github/workflows/apple.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88
pull_request:
99
paths:
1010
- .ci/docker/**
11+
- .ci/scripts/setup-ios.sh
1112
- .github/workflows/apple.yml
1213
- install_requirements.sh
1314
- backends/apple/**
@@ -27,24 +28,35 @@ jobs:
2728
test-demo-ios:
2829
name: test-demo-ios
2930
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
31+
secrets: inherit
3032
with:
3133
runner: macos-latest-xlarge
3234
python-version: '3.11'
3335
submodules: 'true'
3436
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
3537
timeout: 90
38+
secrets-env: BUILD_CERTIFICATE_BASE64 EXECUTORCH_DEMO_BUILD_PROVISION_PROFILE_BASE64 KEYCHAIN_PASSWORD
39+
upload-artifact: ios-apps
3640
script: |
3741
BUILD_TOOL=cmake
3842
3943
.ci/scripts/setup-conda.sh
4044
45+
# Setup Apple certificate for iOS development
46+
BUILD_PROVISION_PROFILE_BASE64="${SECRET_EXECUTORCH_DEMO_BUILD_PROVISION_PROFILE_BASE64}" \
47+
BUILD_CERTIFICATE_BASE64="${SECRET_BUILD_CERTIFICATE_BASE64}" \
48+
KEYCHAIN_PASSWORD="${SECRET_KEYCHAIN_PASSWORD}" \
49+
.ci/scripts/setup-ios.sh
50+
4151
# Setup MacOS dependencies as there is no Docker support on MacOS atm
4252
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
4353
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
4454
55+
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
56+
4557
# Build and test iOS Demo App
4658
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
47-
build/test_ios_ci.sh
59+
build/test_ios_ci.sh ${ARTIFACTS_DIR_NAME}
4860
4961
build-frameworks-ios:
5062
name: build-frameworks-ios

.github/workflows/lint.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,20 @@ jobs:
5454
lint.json || true
5555
5656
exit $RC
57+
58+
android-java-format:
59+
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main
60+
with:
61+
runner: linux.2xlarge
62+
docker-image: executorch-ubuntu-22.04-linter
63+
fetch-depth: 0
64+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
65+
script: |
66+
FILES_NEEDS_FORMAT=$(/opt/google-java-format -n extension/android/src/main/java/org/pytorch/executorch/*.java \
67+
examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/*.java \
68+
examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/*.java)
69+
if [ -n "$FILES_NEEDS_FORMAT" ]; then
70+
echo "Warning: The following files need formatting. Please use google-java-format."
71+
echo "$FILES_NEEDS_FORMAT"
72+
exit 1
73+
fi

.github/workflows/trunk.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
- ciflow/trunk/*
1010
pull_request:
1111
paths:
12+
- .ci/docker/ci_commit_pins/pytorch.txt
1213
- .ci/scripts/**
1314
workflow_dispatch:
1415

@@ -142,7 +143,6 @@ jobs:
142143
conda activate "${CONDA_ENV}"
143144
144145
source .ci/scripts/utils.sh
145-
install_flatc_from_source
146146
install_executorch
147147
148148
install_arm
@@ -168,7 +168,6 @@ jobs:
168168
conda activate "${CONDA_ENV}"
169169
170170
source .ci/scripts/utils.sh
171-
install_flatc_from_source
172171
install_executorch
173172
174173
install_arm
@@ -271,6 +270,34 @@ jobs:
271270
# Test llama2
272271
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
273272
273+
test-llava-runner-macos:
274+
name: test-llava-runner-macos
275+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
276+
strategy:
277+
fail-fast: false
278+
with:
279+
runner: macos-m1-stable
280+
python-version: '3.11'
281+
submodules: 'true'
282+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
283+
timeout: 900
284+
script: |
285+
# The generic Linux job chooses to use base env, not the one setup by the image
286+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
287+
conda activate "${CONDA_ENV}"
288+
289+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "cmake"
290+
291+
# install Llava requirements
292+
bash examples/models/llama2/install_requirements.sh
293+
bash examples/models/llava/install_requirements.sh
294+
295+
# run python unittest
296+
python -m unittest examples.models.llava.test.test_llava
297+
298+
# run e2e (export, tokenizer and runner)
299+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llava.sh Release
300+
274301
test-qnn-model:
275302
name: test-qnn-model
276303
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main

0 commit comments

Comments
 (0)