Skip to content

Commit 6a44e7a

Browse files
authored
Merge branch 'main' into add_mv3_testcase
2 parents 68ae67e + 6fb42ef commit 6a44e7a

File tree

150 files changed

+2465
-3733
lines changed

Some content is hidden

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

150 files changed

+2465
-3733
lines changed

.ci/docker/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ case "${IMAGE_NAME}" in
4848
executorch-ubuntu-22.04-mediatek-sdk)
4949
MEDIATEK_SDK=yes
5050
CLANG_VERSION=12
51+
ANDROID_NDK_VERSION=r27b
5152
;;
5253
executorch-ubuntu-22.04-clang12-android)
5354
LINTRUNNER=""

.ci/scripts/build_llama_android.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,5 @@ build_llama_runner() {
6060

6161
cmake --build cmake-android-out/examples/models/llama -j4 --config Release
6262
}
63-
install_flatc_from_source
6463
install_executorch_and_backend_lib
6564
build_llama_runner
File renamed without changes.

.ci/scripts/test_model.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,14 @@ test_model_with_qnn() {
209209
EXPORTED_MODEL=$(find "./${EXPORT_SCRIPT}" -type f -name "${MODEL_NAME}*.pte" -print -quit)
210210
}
211211

212+
# Run CoreML tests.
213+
#
214+
# @param should_test If true, build and test the model using the coreml_executor_runner.
212215
test_model_with_coreml() {
213-
if [[ "${BUILD_TOOL}" == "buck2" ]]; then
214-
echo "coreml doesn't support buck2."
216+
local should_test="$1"
217+
218+
if [[ "${BUILD_TOOL}" != "cmake" ]]; then
219+
echo "coreml only supports cmake."
215220
exit 1
216221
fi
217222

@@ -229,6 +234,14 @@ test_model_with_coreml() {
229234
echo "No .pte file found"
230235
exit 1
231236
fi
237+
238+
# Run the model
239+
if [ "${should_test}" = true ]; then
240+
echo "Testing exported model with coreml_executor_runner..."
241+
local out_dir=$(mktemp -d)
242+
COREML_EXECUTOR_RUNNER_OUT_DIR="${out_dir}" examples/apple/coreml/scripts/build_executor_runner.sh
243+
"${out_dir}/coreml_executor_runner" --model_path "${EXPORTED_MODEL}"
244+
fi
232245
}
233246

234247
test_model_with_mps() {
@@ -247,7 +260,11 @@ elif [[ "${BACKEND}" == *"qnn"* ]]; then
247260
fi
248261
elif [[ "${BACKEND}" == *"coreml"* ]]; then
249262
echo "Testing ${MODEL_NAME} with coreml..."
250-
test_model_with_coreml
263+
should_test_coreml=false
264+
if [[ "${BACKEND}" == *"test"* ]]; then
265+
should_test_coreml=true
266+
fi
267+
test_model_with_coreml "${should_test_coreml}"
251268
if [[ $? -eq 0 ]]; then
252269
prepare_artifacts_upload
253270
fi

.ci/scripts/utils.sh

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,6 @@ install_pytorch_and_domains() {
8080
sccache --show-stats || true
8181
}
8282

83-
install_flatc_from_source() {
84-
# NB: This function could be used to install flatbuffer from source
85-
pushd third-party/flatbuffers || return
86-
87-
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
88-
if [ "$(uname)" == "Darwin" ]; then
89-
CMAKE_JOBS=$(( $(sysctl -n hw.ncpu) - 1 ))
90-
else
91-
CMAKE_JOBS=$(( $(nproc) - 1 ))
92-
fi
93-
cmake --build . -j "${CMAKE_JOBS}"
94-
95-
# Copy the flatc binary to conda path
96-
EXEC_PATH=$(dirname "$(which python)")
97-
cp flatc "${EXEC_PATH}"
98-
99-
popd || return
100-
}
101-
10283
build_executorch_runner_buck2() {
10384
# Build executorch runtime with retry as this step is flaky on macos CI
10485
retry buck2 build //examples/portable/executor_runner:executor_runner
@@ -111,9 +92,14 @@ build_executorch_runner_cmake() {
11192
mkdir "${CMAKE_OUTPUT_DIR}"
11293

11394
pushd "${CMAKE_OUTPUT_DIR}" || return
95+
if [[ $1 == "Debug" ]]; then
96+
CXXFLAGS="-fsanitize=address,undefined"
97+
else
98+
CXXFLAGS=""
99+
fi
114100
# This command uses buck2 to gather source files and buck2 could crash flakily
115101
# on MacOS
116-
retry cmake -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" -DCMAKE_BUILD_TYPE="${1:-Release}" ..
102+
CXXFLAGS="$CXXFLAGS" retry cmake -DPYTHON_EXECUTABLE="${PYTHON_EXECUTABLE}" -DCMAKE_BUILD_TYPE="${1:-Release}" ..
117103
popd || return
118104

119105
if [ "$(uname)" == "Darwin" ]; then

.ci/scripts/wheel/__init__.py

Whitespace-only changes.

.ci/scripts/wheel/envvar_linux.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# This file is sourced into the environment before building a pip wheel. It
8+
# should typically only contain shell variable assignments. Be sure to export
9+
# any variables so that subprocesses will see them.
10+
11+
source "${GITHUB_WORKSPACE}/${REPOSITORY}/.ci/scripts/wheel/envvar_base.sh"

build/packaging/env_var_script_macos.sh renamed to .ci/scripts/wheel/envvar_macos.sh

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@
88
# should typically only contain shell variable assignments. Be sure to export
99
# any variables so that subprocesses will see them.
1010

11-
# Enable pybindings so that users can execute ExecuTorch programs from python.
12-
export EXECUTORCH_BUILD_PYBIND=1
13-
14-
# Ensure that CMAKE_ARGS is defined before referencing it. Defaults to empty
15-
# if not defined.
16-
export CMAKE_ARGS="${CMAKE_ARGS:-}"
17-
18-
# Link the XNNPACK backend into the pybindings runtime so that users can execute
19-
# ExecuTorch programs that delegate to it.
20-
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_XNNPACK=ON"
11+
source "${GITHUB_WORKSPACE}/${REPOSITORY}/.ci/scripts/wheel/envvar_base.sh"
2112

2213
# When building for macOS, link additional backends into the pybindings runtime.
2314
CMAKE_ARGS="${CMAKE_ARGS} -DEXECUTORCH_BUILD_COREML=ON"

build/packaging/pre_build_script.sh renamed to .ci/scripts/wheel/pre_build_script.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ set -euxo pipefail
1414
# which does install them. Though we'd need to disable build isolation to be
1515
# able to see the installed torch package.
1616

17-
pip install --progress-bar off -r requirements-dev.txt
17+
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh"

.ci/scripts/wheel/test_base.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
import os
8+
import subprocess
9+
import sys
10+
from dataclasses import dataclass
11+
from functools import cache
12+
from typing import List
13+
14+
15+
@cache
16+
def _unsafe_get_env(key: str) -> str:
17+
value = os.getenv(key)
18+
if value is None:
19+
raise RuntimeError(f"environment variable '{key}' is not set")
20+
return value
21+
22+
23+
@cache
24+
def _repository_root_dir() -> str:
25+
return os.path.join(
26+
_unsafe_get_env("GITHUB_WORKSPACE"),
27+
_unsafe_get_env("REPOSITORY"),
28+
)
29+
30+
31+
# For some reason, we are unable to see the entire repo in the python path.
32+
# So manually add it.
33+
sys.path.append(_repository_root_dir())
34+
from examples.models import Backend, Model
35+
36+
37+
@dataclass
38+
class ModelTest:
39+
model: Model
40+
backend: Backend
41+
42+
43+
def run_tests(model_tests: List[ModelTest]) -> None:
44+
# Why are we doing this envvar shenanigans? Since we build the testers, which
45+
# uses buck, we cannot run as root. This is a sneaky of getting around that
46+
# test.
47+
#
48+
# This can be reverted if either:
49+
# - We remove usage of buck in our builds
50+
# - We stop running the Docker image as root: https://github.com/pytorch/test-infra/issues/5091
51+
envvars = os.environ.copy()
52+
envvars.pop("HOME")
53+
54+
for model_test in model_tests:
55+
subprocess.run(
56+
[
57+
os.path.join(_repository_root_dir(), ".ci/scripts/test_model.sh"),
58+
str(model_test.model),
59+
# What to build `executor_runner` with for testing.
60+
"cmake",
61+
str(model_test.backend),
62+
],
63+
env=envvars,
64+
check=True,
65+
cwd=_repository_root_dir(),
66+
)

.ci/scripts/wheel/test_linux.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 test_base
9+
from examples.models import Backend, Model
10+
11+
if __name__ == "__main__":
12+
test_base.run_tests(
13+
model_tests=[
14+
test_base.ModelTest(
15+
model=Model.Mv3,
16+
backend=Backend.XnnpackQuantizationDelegation,
17+
)
18+
]
19+
)

.ci/scripts/wheel/test_macos.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 test_base
9+
from examples.models import Backend, Model
10+
11+
if __name__ == "__main__":
12+
test_base.run_tests(
13+
model_tests=[
14+
test_base.ModelTest(
15+
model=Model.Mv3,
16+
backend=Backend.XnnpackQuantizationDelegation,
17+
),
18+
# Enable this once CoreML is suppported out-of-the-box
19+
# https://github.com/pytorch/executorch/issues/9019
20+
# test_base.ModelTest(
21+
# model=Model.Mv3,
22+
# backend=Backend.CoreMlTest,
23+
# )
24+
]
25+
)

.github/workflows/_android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
# Build LLM Demo for Android
3232
export BUILD_AAR_DIR=aar-out
3333
bash build/build_android_library.sh ${ARTIFACTS_DIR_NAME}
34-
bash build/build_android_instrumentation.sh ${ARTIFACTS_DIR_NAME}
34+
bash .ci/scripts/build_android_instrumentation.sh ${ARTIFACTS_DIR_NAME}
3535
3636
mkdir -p ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
3737
bash ".ci/scripts/test_llama.sh" -model stories110M -build_tool cmake -dtype fp16 -mode portable -upload ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom

.github/workflows/apple.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
- build/build_apple_frameworks.sh
1515
- build/build_apple_llm_demo.sh
1616
- build/create_frameworks.sh
17-
- build/test_ios_ci.sh
17+
- .ci/scripts/test_ios_ci.sh
1818
- examples/demo-apps/apple_ios/**
1919
- extension/apple/**
2020
- extension/benchmark/apple/**
@@ -75,7 +75,7 @@ jobs:
7575
7676
# Build and test iOS Demo App
7777
PYTHON_EXECUTABLE=python ${CONDA_RUN} --no-capture-output \
78-
build/test_ios_ci.sh "${ARTIFACTS_DIR_NAME}"
78+
.ci/scripts/test_ios_ci.sh "${ARTIFACTS_DIR_NAME}"
7979
8080
# Upload the test demo app to S3
8181
upload-demo-ios:

.github/workflows/build-wheels-linux.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Build Linux Wheels
44
on:
55
pull_request:
66
paths:
7-
- build/packaging/**
7+
- .ci/**/*
88
- .github/workflows/build-wheels-linux.yml
99
push:
1010
branches:
@@ -39,9 +39,9 @@ jobs:
3939
matrix:
4040
include:
4141
- repository: pytorch/executorch
42-
pre-script: build/packaging/pre_build_script.sh
43-
post-script: build/packaging/post_build_script.sh
44-
smoke-test-script: build/packaging/smoke_test.py
42+
pre-script: .ci/scripts/wheel/pre_build_script.sh
43+
post-script: .ci/scripts/wheel/post_build_script.sh
44+
smoke-test-script: .ci/scripts/wheel/test_linux.py
4545
package-name: executorch
4646
name: ${{ matrix.repository }}
4747
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
@@ -51,11 +51,8 @@ jobs:
5151
test-infra-repository: pytorch/test-infra
5252
test-infra-ref: main
5353
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
54-
# ExecuTorch only needs the first layer of submodules; override the
55-
# "recursive" default to do less work, and to give the buck daemon fewer
56-
# files to look at.
57-
submodules: true
58-
env-var-script: build/packaging/env_var_script_linux.sh
54+
submodules: recursive
55+
env-var-script: .ci/scripts/wheel/envvar_linux.sh
5956
pre-script: ${{ matrix.pre-script }}
6057
post-script: ${{ matrix.post-script }}
6158
package-name: ${{ matrix.package-name }}

.github/workflows/build-wheels-macos.yml

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name: Build macOS Wheels
44
on:
55
pull_request:
66
paths:
7-
- build/packaging/**
7+
- .ci/**/*
88
- .github/workflows/build-wheels-macos.yml
99
push:
1010
branches:
@@ -39,9 +39,9 @@ jobs:
3939
matrix:
4040
include:
4141
- repository: pytorch/executorch
42-
pre-script: build/packaging/pre_build_script.sh
43-
post-script: build/packaging/post_build_script.sh
44-
smoke-test-script: build/packaging/smoke_test.py
42+
pre-script: .ci/scripts/wheel/pre_build_script.sh
43+
post-script: .ci/scripts/wheel/post_build_script.sh
44+
smoke-test-script: .ci/scripts/wheel/test_macos.py
4545
package-name: executorch
4646
name: ${{ matrix.repository }}
4747
uses: pytorch/test-infra/.github/workflows/build_wheels_macos.yml@main
@@ -51,12 +51,9 @@ jobs:
5151
test-infra-repository: pytorch/test-infra
5252
test-infra-ref: main
5353
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
54-
# ExecuTorch only needs the first layer of submodules; override the
55-
# "recursive" default to do less work, and to give the buck daemon fewer
56-
# files to look at.
57-
submodules: true
54+
submodules: recursive
5855
delocate-wheel: false
59-
env-var-script: build/packaging/env_var_script_macos.sh
56+
env-var-script: .ci/scripts/wheel/envvar_macos.sh
6057
pre-script: ${{ matrix.pre-script }}
6158
post-script: ${{ matrix.post-script }}
6259
package-name: ${{ matrix.package-name }}

.github/workflows/trunk.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ jobs:
176176
id-token: write
177177
contents: read
178178
with:
179-
runner: linux.2xlarge
179+
runner: linux.2xlarge.memory
180180
docker-image: executorch-ubuntu-22.04-arm-sdk
181181
submodules: 'true'
182182
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -206,7 +206,7 @@ jobs:
206206
id-token: write
207207
contents: read
208208
with:
209-
runner: linux.2xlarge
209+
runner: linux.2xlarge.memory
210210
docker-image: executorch-ubuntu-22.04-arm-sdk
211211
submodules: 'true'
212212
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.lintrunner.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,29 @@ init_command = [
343343
'--dry-run={{DRYRUN}}',
344344
'--requirement=requirements-lintrunner.txt',
345345
]
346+
347+
[[linter]]
348+
code = 'LICENSELINT'
349+
include_patterns = [
350+
'**/*',
351+
]
352+
exclude_patterns = [
353+
'**/fb/**',
354+
'.lintrunner.toml',
355+
]
356+
command = [
357+
'python',
358+
'-m',
359+
'lintrunner_adapters',
360+
'run',
361+
'grep_linter',
362+
'--pattern=Confidential and proprietary',
363+
'--linter-name=LICENSELINT',
364+
'--error-name=Wrong license',
365+
"""--error-description=\
366+
Code contributed to ExecuTorch open source repo should have \
367+
BSD-license header \
368+
""",
369+
'--',
370+
'@{{PATHSFILE}}',
371+
]

0 commit comments

Comments
 (0)