Skip to content

Commit 25822ee

Browse files
Update on "[Executorch][target recipes] Add target based recipes for lowering models to a target device"
This diff introduces multi backend/ target based recipes to lower a model with very less code. Target recipes provide pre-configured backend recipes to use them and retarget if needed. See RFC: #13732 ## Usage ``` from executorch.export import export, ExportRecipe, IOSTargetRecipeType # CoreML + XNNPACK coreml_xnnpack_recipe = ExportRecipe.get_recipe(IOSTargetRecipeType.IOS_ARM64_COREML_FP32) session = export(model, coreml_xnnpack_recipe, example_inputs) session.save_pte_file("model.pte") ``` ## Advanced usage one can directly use `ExportRecipe.combine_recipes()` to combine specific backend recipes. ``` recipe1 = ExportRecipe.get_recipe(AndroidRecipeType.XYZ) recipe2 = ExportRecipe.get_recipe(XNNPackRecipeType.FP32) combined_recipe = ExportRecipe.combine( [recipe1, recipe2], recipe_name="multi_backend_coreml_xnnpack_fp32" ) session = export(model, combined_recipe, example_inputs) ``` Fixes: #13732 Differential Revision: [D81297451](https://our.internmc.facebook.com/intern/diff/D81297451/) [ghstack-poisoned]
2 parents c3b1e9c + 702c2af commit 25822ee

File tree

191 files changed

+9312
-1964
lines changed

Some content is hidden

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

191 files changed

+9312
-1964
lines changed

.ci/scripts/setup-vulkan-linux-deps.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ install_vulkan_sdk() {
4343
export PATH="${PATH}:${_vulkan_sdk_dir}/${VULKAN_SDK_VERSION}/x86_64/bin/"
4444
}
4545

46-
VULKAN_SDK_VERSION="1.3.296.0"
46+
VULKAN_SDK_VERSION="1.4.321.1"
4747

4848
install_swiftshader
4949
install_vulkan_sdk "${VULKAN_SDK_VERSION}"

.github/workflows/android-release-artifacts.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ on:
1616
options:
1717
- "xnnpack"
1818
- "vulkan+xnnpack"
19+
- "qnn"
1920
schedule:
2021
- cron: 0 10 * * *
2122

@@ -83,17 +84,29 @@ jobs:
8384
8485
echo -n "$SECRET_EXECUTORCH_MAVEN_SIGNING_GPG_KEY_CONTENTS" | base64 -d > /tmp/secring.gpg
8586
87+
GRADLE_ARGS=""
88+
8689
# Update the version name in build.gradle in case of maven publish
8790
VERSION="${{ inputs.version }}"
8891
if [ ! -z "$VERSION" ]; then
89-
sed -i "s/\(coordinates(\"org.pytorch\", \"executorch-android\", \"\)\([0-9]\+.[0-9]\+.[0-9]\+\)\(\")\)/\1$VERSION\3/" extension/android/executorch_android/build.gradle
92+
GRADLE_ARGS+=" -DexecuTorchVersion=${VERSION}"
9093
fi
9194
9295
FLAVOR="${{ inputs.flavor }}"
9396
if [[ "$FLAVOR" == "vulkan+xnnpack" || -z "$FLAVOR" ]]; then
9497
export EXECUTORCH_BUILD_VULKAN=ON
9598
fi
9699
100+
if [[ "$FLAVOR" == "qnn" ]]; then
101+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
102+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
103+
export EXECUTORCH_BUILD_QNN=ON
104+
source backends/qualcomm/scripts/qnn_config.sh
105+
export QNN_SDK_ROOT="/tmp/qnn/${QNN_VERSION}"
106+
export ANDROID_ABIS=arm64-v8a
107+
GRADLE_ARGS+=" -DqnnVersion=2.28.0"
108+
fi
109+
97110
# Build AAR Package
98111
mkdir aar-out
99112
export BUILD_AAR_DIR=aar-out
@@ -106,7 +119,7 @@ jobs:
106119
# Publish to maven staging
107120
UPLOAD_TO_MAVEN="${{ inputs.upload_to_maven }}"
108121
if [[ "$UPLOAD_TO_MAVEN" == "true" ]]; then
109-
(cd extension/android; ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:publishToMavenCentral)
122+
(cd extension/android; ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew ${GRADLE_ARGS} :executorch_android:publishToMavenCentral)
110123
fi
111124
112125
upload-release-aar:

.github/workflows/apple-perf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ jobs:
416416
- set-parameters
417417
secrets: inherit
418418
with:
419-
runner: macos-latest-xlarge
419+
runner: macos-14-xlarge
420420
python-version: '3.11'
421421
submodules: 'recursive'
422422
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.github/workflows/apple.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
5050
secrets: inherit
5151
with:
52-
runner: macos-latest-xlarge
52+
runner: macos-14-xlarge
5353
python-version: '3.11'
5454
submodules: 'recursive'
5555
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -136,7 +136,7 @@ jobs:
136136
needs: set-version
137137
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
138138
with:
139-
runner: macos-latest-xlarge
139+
runner: macos-14-xlarge
140140
python-version: '3.11'
141141
submodules: 'recursive'
142142
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -276,7 +276,7 @@ jobs:
276276
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
277277
secrets: inherit
278278
with:
279-
runner: macos-latest-xlarge
279+
runner: macos-14-xlarge
280280
python-version: '3.11'
281281
submodules: 'recursive'
282282
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}

.github/workflows/build-presets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
job-name: build
2424
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
25-
runner: macos-latest-xlarge
25+
runner: macos-14-xlarge
2626
python-version: 3.12
2727
submodules: recursive
2828
timeout: 90

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
post-script: ${{ matrix.post-script }}
6464
package-name: ${{ matrix.package-name }}
6565
# Meta's macOS runners do not have Xcode, so use GitHub's runners.
66-
runner-type: macos-latest-xlarge
66+
runner-type: macos-14-xlarge
6767
setup-miniconda: true
6868
smoke-test-script: ${{ matrix.smoke-test-script }}
6969
trigger-event: ${{ github.event_name }}

.github/workflows/pull.yml

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,14 @@ jobs:
855855
.ci/scripts/setup-linux.sh --build-tool "cmake"
856856
857857
# Install test requirements
858-
pip install -r backends/nxp/requirements-tests.txt
858+
pip install -r backends/nxp/requirements-tests-pypi.txt
859+
pip install -r backends/nxp/requirements-tests-eiq.txt
859860
860861
# Run pytest
861862
PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh
862863
863864
# Run aot examples:
864-
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10
865+
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10
865866
PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh mobilenetv2
866867
867868
@@ -901,6 +902,34 @@ jobs:
901902
done
902903
903904
905+
test-vulkan-operators-linux:
906+
name: test-vulkan-operators-linux
907+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
908+
permissions:
909+
id-token: write
910+
contents: read
911+
with:
912+
runner: linux.2xlarge
913+
docker-image: ci-image:executorch-ubuntu-22.04-clang12
914+
submodules: 'recursive'
915+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
916+
timeout: 90
917+
script: |
918+
set -eux
919+
920+
# The generic Linux job chooses to use base env, not the one setup by the image
921+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
922+
conda activate "${CONDA_ENV}"
923+
924+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
925+
source .ci/scripts/setup-vulkan-linux-deps.sh
926+
927+
# Setup python
928+
PYTHON_EXECUTABLE=python \
929+
CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \
930+
.ci/scripts/setup-linux.sh --build-tool "cmake"
931+
932+
PYTHON_EXECUTABLE=python bash backends/vulkan/test/custom_ops/build_and_run.sh add
904933
905934
nxp-build-test:
906935
name: nxp-build-test

.github/workflows/trunk.yml

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ jobs:
435435
name: test-coreml-delegate
436436
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
437437
with:
438-
runner: macos-latest-xlarge
438+
runner: macos-14-xlarge
439439
python-version: '3.11'
440440
submodules: 'recursive'
441441
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -940,3 +940,42 @@ jobs:
940940
build-mode: Release
941941
build-tool: cmake
942942
docker-image: ci-image:executorch-ubuntu-22.04-clang12
943+
944+
test-mcu-models:
945+
name: test-mcu-models
946+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
947+
strategy:
948+
matrix:
949+
include:
950+
- build-tool: cmake
951+
fail-fast: false
952+
permissions:
953+
id-token: write
954+
contents: read
955+
with:
956+
runner: linux.2xlarge
957+
docker-image: ci-image:executorch-ubuntu-22.04-arm-sdk
958+
submodules: 'recursive'
959+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
960+
timeout: 90
961+
script: |
962+
BUILD_TOOL=${{ matrix.build-tool }}
963+
964+
# The generic Linux job chooses to use base env, not the one setup by the image
965+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
966+
conda activate "${CONDA_ENV}"
967+
968+
# Try to mirror these as closely as possible
969+
source .ci/scripts/utils.sh
970+
install_executorch "--use-pt-pinned-commit"
971+
972+
.ci/scripts/setup-arm-baremetal-tools.sh
973+
source examples/arm/ethos-u-scratch/setup_path.sh
974+
975+
# Run selective Build
976+
chmod +x examples/selective_build/test_selective_build.sh
977+
examples/selective_build/test_selective_build.sh "${BUILD_TOOL}"
978+
979+
# Run MCU models
980+
chmod +x examples/arm/run_mcu_models_fvp.sh
981+
examples/arm/run_mcu_models_fvp.sh --target=cortex-m55

CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ endif()
582582

583583
if(EXECUTORCH_BUILD_EXTENSION_APPLE)
584584
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple)
585-
list(APPEND _executorch_extensions apple_extension)
586585
endif()
587586

588587
if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
@@ -649,7 +648,6 @@ endif()
649648

650649
if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE)
651650
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple)
652-
list(APPEND _executorch_extensions extension_llm_apple)
653651
endif()
654652

655653
if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
@@ -968,6 +966,10 @@ else()
968966
endif()
969967
target_link_libraries(executorch_kernels INTERFACE ${_executorch_kernels})
970968

969+
install(TARGETS executorch_backends executorch_extensions executorch_kernels
970+
EXPORT ExecuTorchTargets
971+
)
972+
971973
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
972974
# Baseline libraries that executor_runner will link against.
973975
set(_executor_runner_libs executorch extension_evalue_util

backends/apple/coreml/recipes/coreml_recipe_provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Please refer to the license found in the LICENSE file in the root directory of the source tree.
44

55

6+
import logging
67
from typing import Any, Optional, Sequence
78

89
import coremltools as ct
@@ -111,8 +112,9 @@ def _validate_recipe_kwargs(self, recipe_type: RecipeType, **kwargs: Any) -> Non
111112

112113
unexpected = set(kwargs.keys()) - expected_keys
113114
if unexpected:
114-
raise ValueError(
115-
f"Recipe '{recipe_type.value}' received unexpected parameters: {list(unexpected)}"
115+
logging.warning(
116+
f"CoreML recipe '{recipe_type.value}' ignoring unexpected parameters: {list(unexpected)}. "
117+
f"Expected parameters: {list(expected_keys)}"
116118
)
117119

118120
self._validate_base_parameters(kwargs)

0 commit comments

Comments
 (0)