Skip to content

Commit ddb1fcd

Browse files
committed
Update base for Update on "[executorch] Ignore leading 1 dimensions when checking optimized path for op_mul"
A 1 x 1 x ... x m x n tensor can be element-wise multiplied with a m x n tensor just fine. Differential Revision: [D61504544](https://our.internmc.facebook.com/intern/diff/D61504544/) [ghstack-poisoned]
2 parents 35c25c0 + 35e2302 commit ddb1fcd

File tree

129 files changed

+2477
-1628
lines changed

Some content is hidden

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

129 files changed

+2477
-1628
lines changed

.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/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

.github/workflows/apple.yml

Lines changed: 74 additions & 2 deletions
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/**
@@ -18,33 +19,104 @@ on:
1819
- extension/apple/**
1920
- extension/module/**
2021
workflow_dispatch:
22+
# TODO (huydhn): This is used to validate the test spec. Eventually, we need a proper
23+
# perf benchmark workflow like android-perf. This can be cleaned up once that workflow
24+
# is ready
25+
workflow_call:
26+
inputs:
27+
test_spec:
28+
description: The test spec to drive the test on AWS devices
29+
required: false
30+
type: string
2131

2232
concurrency:
2333
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
2434
cancel-in-progress: true
2535

2636
jobs:
27-
test-demo-ios:
37+
build-demo-ios:
2838
name: test-demo-ios
2939
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
40+
secrets: inherit
3041
with:
3142
runner: macos-latest-xlarge
3243
python-version: '3.11'
3344
submodules: 'true'
3445
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
3546
timeout: 90
47+
secrets-env: BUILD_CERTIFICATE_BASE64 EXECUTORCH_DEMO_BUILD_PROVISION_PROFILE_BASE64 KEYCHAIN_PASSWORD
48+
upload-artifact: ios-apps
3649
script: |
3750
BUILD_TOOL=cmake
3851
3952
.ci/scripts/setup-conda.sh
4053
54+
# Setup Apple certificate for iOS development
55+
BUILD_PROVISION_PROFILE_BASE64="${SECRET_EXECUTORCH_DEMO_BUILD_PROVISION_PROFILE_BASE64}" \
56+
BUILD_CERTIFICATE_BASE64="${SECRET_BUILD_CERTIFICATE_BASE64}" \
57+
KEYCHAIN_PASSWORD="${SECRET_KEYCHAIN_PASSWORD}" \
58+
.ci/scripts/setup-ios.sh
59+
4160
# Setup MacOS dependencies as there is no Docker support on MacOS atm
4261
GITHUB_RUNNER=1 PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
4362
.ci/scripts/setup-macos.sh "${BUILD_TOOL}"
4463
64+
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
65+
4566
# Build and test iOS Demo App
4667
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
47-
build/test_ios_ci.sh
68+
build/test_ios_ci.sh ${ARTIFACTS_DIR_NAME}
69+
70+
# Upload the test demo app to S3
71+
upload-demo-ios:
72+
needs: build-demo-ios
73+
runs-on: linux.2xlarge
74+
steps:
75+
- name: Download the artifacts from GitHub
76+
uses: actions/download-artifact@v3
77+
with:
78+
# The name here needs to match the name of the upload-artifact parameter
79+
name: ios-apps
80+
path: ${{ runner.temp }}/artifacts/
81+
82+
- name: Verify the artifacts
83+
shell: bash
84+
working-directory: ${{ runner.temp }}/artifacts/
85+
run: |
86+
ls -lah ./
87+
88+
- name: Upload the artifacts to S3
89+
uses: seemethere/upload-artifact-s3@v5
90+
with:
91+
s3-bucket: gha-artifacts
92+
s3-prefix: |
93+
${{ github.repository }}/${{ github.run_id }}/artifact
94+
retention-days: 14
95+
if-no-files-found: ignore
96+
path: ${{ runner.temp }}/artifacts/
97+
98+
test-demo-ios:
99+
# Only PR from ExecuTorch itself has permission to access AWS, forked PRs will fail to
100+
# authenticate with the cloud service. So, this job will be skipped on the latter
101+
if: ${{ !github.event.pull_request.head.repo.fork }}
102+
needs: upload-demo-ios
103+
permissions:
104+
id-token: write
105+
contents: read
106+
uses: pytorch/test-infra/.github/workflows/mobile_job.yml@main
107+
with:
108+
device-type: ios
109+
# For iOS testing, the runner just needs to call AWS Device Farm, so there is no need to run this on macOS
110+
runner: linux.2xlarge
111+
test-infra-ref: ''
112+
# This is the ARN of ExecuTorch project on AWS
113+
project-arn: arn:aws:devicefarm:us-west-2:308535385114:project:02a2cf0f-6d9b-45ee-ba1a-a086587469e6
114+
# This is the custom device pool that only includes iOS devices
115+
device-pool-arn: arn:aws:devicefarm:us-west-2:308535385114:devicepool:02a2cf0f-6d9b-45ee-ba1a-a086587469e6/3b5acd2e-92e2-4778-b651-7726bafe129d
116+
# Uploaded to S3 from the previous job
117+
ios-ipa-archive: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/ExecuTorchDemo.ipa
118+
ios-xctestrun-zip: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/ExecuTorchDemo.xctestrun.zip
119+
test-spec: ${{ inputs.test_spec || 'https://ossci-ios.s3.amazonaws.com/executorch/default-ios-device-farm-appium-test-spec.yml' }}
48120

49121
build-frameworks-ios:
50122
name: build-frameworks-ios

.github/workflows/trunk.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,34 @@ jobs:
270270
# Test llama2
271271
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash .ci/scripts/test_llama.sh stories110M "${BUILD_TOOL}" "${DTYPE}" "${MODE}"
272272
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+
273301
test-qnn-model:
274302
name: test-qnn-model
275303
uses: pytorch/test-infra/.github/workflows/linux_job.yml@main

.github/workflows/upload-test-specs.yml renamed to .github/workflows/upload-android-test-specs.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: Upload AWS Device Farm test specs
1+
name: Upload AWS Device Farm Android test specs
22

33
on:
44
pull_request:
55
paths:
6-
- .github/workflows/upload-test-specs.yml
6+
- .github/workflows/upload-android-test-specs.yml
77
- examples/demo-apps/android/LlamaDemo/android-llm-device-farm-test-spec.yml
88
push:
99
branches:
1010
- main
1111
paths:
12-
- .github/workflows/upload-test-specs.yml
12+
- .github/workflows/upload-android-test-specs.yml
1313
- examples/demo-apps/android/LlamaDemo/android-llm-device-farm-test-spec.yml
1414

1515
concurrency:
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Upload AWS Device Farm Apple iOS test specs
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- .github/workflows/upload-apple-test-specs.yml
7+
- examples/demo-apps/apple_ios/default-ios-device-farm-appium-test-spec.yml
8+
push:
9+
branches:
10+
- main
11+
paths:
12+
- .github/workflows/upload-apple-test-specs.yml
13+
- examples/demo-apps/apple_ios/default-ios-device-farm-appium-test-spec.yml
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
upload-apple-test-spec-for-validation:
21+
runs-on: linux.2xlarge
22+
steps:
23+
- uses: actions/checkout@v3
24+
25+
- name: Upload the spec as a GitHub artifact for validation
26+
uses: seemethere/upload-artifact-s3@v5
27+
with:
28+
s3-bucket: gha-artifacts
29+
s3-prefix: |
30+
${{ github.repository }}/${{ github.run_id }}/artifact
31+
retention-days: 1
32+
if-no-files-found: error
33+
path: examples/demo-apps/apple_ios/default-ios-device-farm-appium-test-spec.yml
34+
35+
# TODO (huydhn): An example on how to validate the test spec using the iOS demo app, but we need a proper
36+
# perf benchmark workflow like android-perf
37+
validate-apple-test-spec:
38+
needs: upload-apple-test-spec-for-validation
39+
uses: ./.github/workflows/apple.yml
40+
secrets: inherit
41+
permissions:
42+
id-token: write
43+
contents: read
44+
with:
45+
test_spec: https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifact/default-ios-device-farm-appium-test-spec.yml
46+
47+
upload-apple-test-spec:
48+
needs: validate-apple-test-spec
49+
runs-on: ubuntu-22.04
50+
timeout-minutes: 15
51+
permissions:
52+
id-token: write
53+
contents: read
54+
steps:
55+
- uses: actions/checkout@v3
56+
57+
- uses: actions/setup-python@v4
58+
with:
59+
python-version: '3.11'
60+
cache: pip
61+
62+
- name: configure aws credentials
63+
uses: aws-actions/[email protected]
64+
with:
65+
role-to-assume: arn:aws:iam::308535385114:role/gha_executorch_upload-frameworks-ios
66+
aws-region: us-east-1
67+
68+
- name: Only push to S3 when running the workflow manually from main branch
69+
if: ${{ github.ref == 'refs/heads/main' }}
70+
shell: bash
71+
run: |
72+
set -eux
73+
echo "UPLOAD_ON_MAIN=1" >> "${GITHUB_ENV}"
74+
75+
- name: Upload the spec to S3 ossci-ios bucket
76+
shell: bash
77+
working-directory: examples/demo-apps/apple_ios
78+
env:
79+
SPEC_FILE: default-ios-device-farm-appium-test-spec.yml
80+
run: |
81+
set -eux
82+
83+
pip install awscli==1.32.18
84+
85+
AWS_CMD="aws s3 cp --dryrun"
86+
if [[ "${UPLOAD_ON_MAIN:-0}" == "1" ]]; then
87+
AWS_CMD="aws s3 cp"
88+
fi
89+
90+
shasum -a 256 "${SPEC_FILE}"
91+
${AWS_CMD} "${SPEC_FILE}" s3://ossci-ios/executorch/ --acl public-read

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,6 @@ if(EXECUTORCH_BUILD_PYBIND)
693693
util
694694
${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util/print_evalue.cpp
695695
${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
696-
${CMAKE_CURRENT_SOURCE_DIR}/util/read_file.cpp
697696
)
698697
target_include_directories(
699698
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
@@ -786,8 +785,12 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
786785
endif()
787786

788787
add_executable(executor_runner ${_executor_runner__srcs})
789-
if(CMAKE_BUILD_TYPE STREQUAL "Release" AND NOT APPLE)
790-
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
788+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
789+
if(APPLE)
790+
target_link_options(executor_runner PRIVATE "LINKER:-dead_strip")
791+
else()
792+
target_link_options(executor_runner PRIVATE "LINKER:--gc-sections")
793+
endif()
791794
endif()
792795
target_link_libraries(executor_runner ${_executor_runner_libs})
793796
target_compile_options(executor_runner PUBLIC ${_common_compile_options})

0 commit comments

Comments
 (0)