Skip to content

Commit 69fa2ab

Browse files
committed
Update
[ghstack-poisoned]
2 parents 4bb8883 + 618f338 commit 69fa2ab

Some content is hidden

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

50 files changed

+487
-209
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ set -exu
1010
# shellcheck source=/dev/null
1111
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1212

13+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
14+
PYTHON_EXECUTABLE=python3
15+
fi
16+
which "${PYTHON_EXECUTABLE}"
17+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
18+
1319
install_executorch_and_backend_lib() {
1420
echo "Installing executorch and xnnpack backend"
1521
clean_executorch_install_folders
@@ -22,6 +28,7 @@ install_executorch_and_backend_lib() {
2228
-DANDROID_ABI="${ANDROID_ABI}" \
2329
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
2430
-DCMAKE_BUILD_TYPE=Release \
31+
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
2532
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
2633
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
2734
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
@@ -47,6 +54,7 @@ build_llama_runner() {
4754
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
4855
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
4956
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
57+
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
5058
-Bcmake-android-out/examples/models/llama examples/models/llama
5159

5260
cmake --build cmake-android-out/examples/models/llama -j4 --config Release

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ cmake_install_executorch_libraries() {
154154
rm -rf cmake-out
155155
retry cmake \
156156
-DCMAKE_INSTALL_PREFIX=cmake-out \
157+
-DCMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')" \
157158
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
158159
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
159160
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \

.ci/scripts/test_llava.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ fi
3030
NPROC=8
3131
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
3232

33+
python_lib=$($PYTHON_EXECUTABLE -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')
34+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
3335
EXECUTORCH_COMMON_CMAKE_ARGS=" \
3436
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
35-
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
37+
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
3638
-DEXECUTORCH_ENABLE_LOGGING=ON \
3739
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
3840
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
@@ -46,6 +48,7 @@ EXECUTORCH_COMMON_CMAKE_ARGS=" \
4648
cmake_install_executorch_libraries() {
4749
cmake \
4850
${EXECUTORCH_COMMON_CMAKE_ARGS} \
51+
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
4952
-B${BUILD_DIR} .
5053

5154
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -56,6 +59,7 @@ cmake_install_executorch_libraries_for_android() {
5659
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
5760
-DANDROID_ABI=arm64-v8a \
5861
${EXECUTORCH_COMMON_CMAKE_ARGS} \
62+
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
5963
-B${BUILD_DIR} .
6064

6165
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -76,7 +80,7 @@ cmake_build_llava_runner() {
7680

7781
cmake \
7882
${LLAVA_COMMON_CMAKE_ARGS} \
79-
-DCMAKE_PREFIX_PATH="$python_lib" \
83+
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
8084
-B${BUILD_DIR}/${dir} \
8185
${dir}
8286

@@ -92,7 +96,7 @@ cmake_build_llava_runner_for_android() {
9296
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
9397
-DANDROID_ABI=arm64-v8a \
9498
${LLAVA_COMMON_CMAKE_ARGS} \
95-
-DCMAKE_PREFIX_PATH="$python_lib" \
99+
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
96100
-DLLAVA_RUNNER_NO_TORCH_DUMMY_IMAGE=ON \
97101
-B${BUILD_DIR}/${dir} \
98102
${dir}

.ci/scripts/test_model.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ prepare_artifacts_upload() {
5050

5151
build_cmake_executor_runner() {
5252
echo "Building executor_runner"
53+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
5354
rm -rf ${CMAKE_OUTPUT_DIR}
5455
cmake -DCMAKE_BUILD_TYPE=Debug \
5556
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
5657
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
58+
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5759
-B${CMAKE_OUTPUT_DIR} .
5860

5961
cmake --build ${CMAKE_OUTPUT_DIR} -j4 --config Debug
@@ -98,8 +100,7 @@ test_model() {
98100

99101
build_cmake_xnn_executor_runner() {
100102
echo "Building xnn_executor_runner"
101-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
102-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
103+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
103104

104105
(rm -rf ${CMAKE_OUTPUT_DIR} \
105106
&& mkdir ${CMAKE_OUTPUT_DIR} \

.ci/scripts/test_phi_3_mini.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ NPROC=8
2222
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
2323

2424
cmake_install_executorch_libraries() {
25+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
2526
cmake -DPYTHON_EXECUTABLE=python \
2627
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
28+
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
2729
-DEXECUTORCH_ENABLE_LOGGING=1 \
2830
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
2931
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
@@ -39,8 +41,10 @@ cmake_install_executorch_libraries() {
3941
}
4042

4143
cmake_build_phi_3_mini() {
44+
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
4245
cmake -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
4346
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
47+
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
4448
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
4549
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
4650
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \

.ci/scripts/utils.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ cmake_install_executorch_lib() {
136136
clean_executorch_install_folders
137137
retry cmake -DBUCK2="$BUCK" \
138138
-DCMAKE_INSTALL_PREFIX=cmake-out \
139+
-DCMAKE_PREFIX_PATH="$($PYTHON_EXECUTABLE -c 'import torch as _; print(_.__path__[0])')" \
139140
-DCMAKE_BUILD_TYPE=Release \
140141
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
141142
-Bcmake-out .

.github/workflows/android-perf.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ jobs:
222222
--preq_mode 8da4w_output_8da8w \
223223
--preq_group_size 32 \
224224
--max_seq_length 2048 \
225+
--max_context_length 2048 \
225226
--output_name "${OUT_ET_MODEL_NAME}.pte" \
226227
-kv \
227228
-d fp32 \
@@ -253,6 +254,7 @@ jobs:
253254
--xnnpack-extended-ops \
254255
-d fp32 \
255256
--max_seq_length 2048 \
257+
--max_context_length 2048 \
256258
--output_name "${OUT_ET_MODEL_NAME}.pte" \
257259
--metadata '{"get_bos_id":128000, "get_eos_ids":[128009, 128001]}'
258260
ls -lh "${OUT_ET_MODEL_NAME}.pte"

.github/workflows/apple-perf.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ jobs:
233233
--preq_mode 8da4w_output_8da8w \
234234
--preq_group_size 32 \
235235
--max_seq_length 2048 \
236+
--max_context_length 2048 \
236237
--output_name "${OUT_ET_MODEL_NAME}.pte" \
237238
-kv \
238239
-d fp32 \
@@ -264,6 +265,7 @@ jobs:
264265
--xnnpack-extended-ops \
265266
-d fp32 \
266267
--max_seq_length 2048 \
268+
--max_context_length 2048 \
267269
--output_name "${OUT_ET_MODEL_NAME}.pte" \
268270
--metadata '{"get_bos_id":128000, "get_eos_ids":[128009, 128001]}'
269271
ls -lh "${OUT_ET_MODEL_NAME}.pte"

.github/workflows/pull.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ jobs:
147147
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
148148
conda activate "${CONDA_ENV}"
149149
150+
source .ci/scripts/utils.sh
151+
install_executorch "use-pt-pinned-commit"
150152
BUILD_TOOL="cmake"
151153
PYTHON_EXECUTABLE=python \
152154
bash .ci/scripts/build_llama_android.sh "${BUILD_TOOL}"

.github/workflows/trunk.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ jobs:
394394
rm -rf cmake-out
395395
cmake \
396396
-DCMAKE_INSTALL_PREFIX=cmake-out \
397+
-DCMAKE_PREFIX_PATH="$(python -c 'import torch as _; print(_.__path__[0])')" \
397398
-DCMAKE_BUILD_TYPE=Release \
398399
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
399400
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
@@ -411,6 +412,7 @@ jobs:
411412
cmake \
412413
-DCMAKE_INSTALL_PREFIX=cmake-out \
413414
-DCMAKE_BUILD_TYPE=Release \
415+
-DCMAKE_PREFIX_PATH="$(python -c 'import torch as _; print(_.__path__[0])')" \
414416
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
415417
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
416418
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ endif()
596596
# any backends.
597597
#
598598
add_library(executorch ${_executorch__srcs})
599-
target_link_libraries(executorch PRIVATE executorch_core)
599+
target_link_libraries(executorch PUBLIC executorch_core)
600600
target_include_directories(executorch PUBLIC ${_common_include_directories})
601601
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
602602
target_compile_options(executorch PUBLIC ${_common_compile_options})
@@ -614,6 +614,8 @@ if(BUILD_EXECUTORCH_PORTABLE_OPS)
614614
endif()
615615

616616
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
617+
# find pytorch lib here to make it available to all sub-directories
618+
find_package_torch_headers()
617619
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/optimized)
618620
endif()
619621

@@ -750,7 +752,9 @@ if(EXECUTORCH_BUILD_PYBIND)
750752
endif()
751753

752754
# find pytorch lib, to allow pybind to take at::Tensor as input/output
753-
find_package(Torch CONFIG REQUIRED)
755+
if(NOT TARGET torch)
756+
find_package(Torch CONFIG REQUIRED)
757+
endif()
754758
find_library(
755759
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
756760
)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates.
2+
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
import unittest
7+
8+
import pytest
9+
10+
from executorch.backends.arm.test import common, conftest
11+
12+
from executorch.backends.arm.test.tester.arm_tester import ArmTester
13+
from executorch.examples.models import deeplab_v3
14+
15+
16+
class TestDl3(unittest.TestCase):
17+
"""Tests DeepLabv3."""
18+
19+
dl3 = deeplab_v3.DeepLabV3ResNet50Model()
20+
model_inputs = dl3.get_example_inputs()
21+
dl3 = dl3.get_eager_model()
22+
23+
@unittest.expectedFailure
24+
def test_dl3_tosa_MI(self):
25+
(
26+
ArmTester(
27+
self.dl3,
28+
example_inputs=self.model_inputs,
29+
compile_spec=common.get_tosa_compile_spec("TOSA-0.80+MI"),
30+
)
31+
.export()
32+
.to_edge_transform_and_lower()
33+
.to_executorch()
34+
.run_method_and_compare_outputs(self.model_inputs)
35+
)
36+
37+
@unittest.expectedFailure
38+
def test_dl3_tosa_BI(self):
39+
(
40+
ArmTester(
41+
self.dl3,
42+
example_inputs=self.model_inputs,
43+
compile_spec=common.get_tosa_compile_spec("TOSA-0.80+BI"),
44+
)
45+
.quantize()
46+
.export()
47+
.to_edge_transform_and_lower()
48+
.to_executorch()
49+
.run_method_and_compare_outputs(atol=1.0, qtol=1, inputs=self.model_inputs)
50+
)
51+
52+
@pytest.mark.slow
53+
@pytest.mark.corstone_fvp
54+
@unittest.skip
55+
def test_dl3_u55_BI(self):
56+
tester = (
57+
ArmTester(
58+
self.dl3,
59+
example_inputs=self.model_inputs,
60+
compile_spec=common.get_u55_compile_spec(),
61+
)
62+
.quantize()
63+
.export()
64+
.to_edge_transform_and_lower()
65+
.to_executorch()
66+
.serialize()
67+
)
68+
if conftest.is_option_enabled("corstone_fvp"):
69+
tester.run_method_and_compare_outputs(
70+
atol=1.0, qtol=1, inputs=self.model_inputs
71+
)
72+
73+
@pytest.mark.slow
74+
@pytest.mark.corstone_fvp
75+
@unittest.skip
76+
def test_dl3_u85_BI(self):
77+
tester = (
78+
ArmTester(
79+
self.dl3,
80+
example_inputs=self.model_inputs,
81+
compile_spec=common.get_u85_compile_spec(),
82+
)
83+
.quantize()
84+
.export()
85+
.to_edge_transform_and_lower()
86+
.to_executorch()
87+
.serialize()
88+
)
89+
if conftest.is_option_enabled("corstone_fvp"):
90+
tester.run_method_and_compare_outputs(
91+
atol=1.0, qtol=1, inputs=self.model_inputs
92+
)

backends/cadence/aot/export_example.py

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
# Example script for exporting simple models to flatbuffer
88

9+
# pyre-unsafe
10+
911
import logging
1012
import tempfile
1113

12-
import torch
13-
1414
from executorch.backends.cadence.aot.ops_registrations import * # noqa
1515
from typing import Any, Tuple
1616

@@ -23,38 +23,15 @@
2323
from executorch.backends.cadence.aot.quantizer.quantizer import CadenceDefaultQuantizer
2424
from executorch.backends.cadence.runtime import runtime
2525
from executorch.backends.cadence.runtime.executor import BundledProgramManager
26-
from executorch.backends.xnnpack.quantizer.xnnpack_quantizer_utils import (
27-
QuantizationConfig,
28-
QuantizationSpec,
29-
)
3026
from executorch.exir import ExecutorchProgramManager
3127
from torch import nn
32-
from torch.ao.quantization.observer import HistogramObserver, MinMaxObserver
3328

3429
from .utils import save_bpte_program, save_pte_program
3530

3631

3732
FORMAT = "[%(levelname)s %(asctime)s %(filename)s:%(lineno)s] %(message)s"
3833
logging.basicConfig(level=logging.INFO, format=FORMAT)
3934

40-
act_qspec = QuantizationSpec(
41-
dtype=torch.int8,
42-
quant_min=-128,
43-
quant_max=127,
44-
qscheme=torch.per_tensor_affine,
45-
is_dynamic=False,
46-
observer_or_fake_quant_ctr=HistogramObserver.with_args(eps=2**-12),
47-
)
48-
49-
wgt_qspec = QuantizationSpec(
50-
dtype=torch.int8,
51-
quant_min=-128,
52-
quant_max=127,
53-
qscheme=torch.per_tensor_affine,
54-
is_dynamic=False,
55-
observer_or_fake_quant_ctr=MinMaxObserver,
56-
)
57-
5835

5936
def export_model(
6037
model: nn.Module,
@@ -66,15 +43,8 @@ def export_model(
6643
working_dir = tempfile.mkdtemp(dir="/tmp")
6744
logging.debug(f"Created work directory {working_dir}")
6845

69-
qconfig = QuantizationConfig(
70-
act_qspec,
71-
act_qspec,
72-
wgt_qspec,
73-
None,
74-
)
75-
7646
# Instantiate the quantizer
77-
quantizer = CadenceDefaultQuantizer(qconfig)
47+
quantizer = CadenceDefaultQuantizer()
7848

7949
# Convert the model
8050
converted_model = convert_pt2(model, example_inputs, quantizer)

backends/cadence/aot/ops_registrations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ def quantized_relu_per_tensor_meta(
576576
out_multiplier: int,
577577
out_shift: int,
578578
) -> torch.Tensor:
579-
return input.new_empty(input.size(), dtype=torch.uint8)
579+
return input.new_empty(input.size(), dtype=input.dtype)
580580

581581

582582
@register_fake("cadence::fully_connected")

0 commit comments

Comments
 (0)