Skip to content

Commit 90ae596

Browse files
committed
Update
[ghstack-poisoned]
2 parents 8305056 + 5205cb2 commit 90ae596

File tree

88 files changed

+1527
-665
lines changed

Some content is hidden

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

88 files changed

+1527
-665
lines changed

.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: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,22 @@ on:
1919
- extension/apple/**
2020
- extension/module/**
2121
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
2231

2332
concurrency:
2433
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}-${{ github.event_name == 'schedule' }}
2534
cancel-in-progress: true
2635

2736
jobs:
28-
test-demo-ios:
37+
build-demo-ios:
2938
name: test-demo-ios
3039
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
3140
secrets: inherit
@@ -58,6 +67,57 @@ jobs:
5867
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
5968
build/test_ios_ci.sh ${ARTIFACTS_DIR_NAME}
6069
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' }}
120+
61121
build-frameworks-ios:
62122
name: build-frameworks-ios
63123
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main

.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})

backends/arm/runtime/ArmBackendEthosU.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212

1313
#include <cstring>
14+
#include <memory>
1415

1516
#include <ethosu_driver.h>
1617
#include <pmu_ethosu.h>
@@ -164,8 +165,10 @@ class ArmBackend final : public PyTorchBackendInterface {
164165
}
165166

166167
// Allocate driver handle and synchronously invoke driver
167-
ethosu_driver* drv = ethosu_reserve_driver();
168-
if (drv == NULL) {
168+
auto driver =
169+
std::unique_ptr<ethosu_driver, decltype(&ethosu_release_driver)>(
170+
ethosu_reserve_driver(), ethosu_release_driver);
171+
if (driver == NULL) {
169172
ET_LOG(Error, "ArmBackend::execute: ethosu_reserve_driver failed");
170173
return Error::InvalidState;
171174
}
@@ -178,7 +181,7 @@ class ArmBackend final : public PyTorchBackendInterface {
178181
size_t bases_size[2] = {
179182
handles.weight_data_size, handles.scratch_data_size};
180183
int result = ethosu_invoke_v3(
181-
drv,
184+
driver.get(),
182185
(void*)handles.cmd_data,
183186
handles.cmd_data_size,
184187
bases,

backends/mediatek/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ add_library(neuron_backend SHARED)
2929
target_link_libraries(neuron_backend
3030
PRIVATE
3131
executorch_no_prim_ops
32+
portable_ops_lib
3233
android
3334
log
3435
${NEURON_BUFFER_ALLOCATOR_LIB}

0 commit comments

Comments
 (0)