Skip to content

Commit 07435d3

Browse files
authored
Merge branch 'main' into export-D78762534
2 parents 2794831 + 92fb0cc commit 07435d3

File tree

104 files changed

+3158
-708
lines changed

Some content is hidden

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

104 files changed

+3158
-708
lines changed

.ci/scripts/setup-qnn-deps.sh

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,7 @@
77

88
set -ex
99

10-
verify_pkg_installed() {
11-
echo $(dpkg-query -W --showformat='${Status}\n' $1|grep "install ok installed")
12-
}
10+
source "$(dirname "${BASH_SOURCE[0]}")/../../backends/qualcomm/scripts/install_qnn_sdk.sh"
1311

14-
install_qnn() {
15-
echo "Start installing qnn."
16-
QNN_INSTALLATION_DIR=/tmp/qnn
17-
mkdir -p "${QNN_INSTALLATION_DIR}"
18-
19-
curl -Lo /tmp/v2.28.0.24.10.29.zip "https://softwarecenter.qualcomm.com/api/download/software/qualcomm_neural_processing_sdk/v2.28.0.241029.zip"
20-
echo "Finishing downloading qnn sdk."
21-
unzip -qo /tmp/v2.28.0.24.10.29.zip -d /tmp
22-
echo "Finishing unzip qnn sdk."
23-
24-
25-
# Print the content for manual verification
26-
ls -lah "/tmp/qairt"
27-
mv "/tmp/qairt"/* "${QNN_INSTALLATION_DIR}"
28-
echo "Finishing installing qnn '${QNN_INSTALLATION_DIR}' ."
29-
30-
ls -lah "${QNN_INSTALLATION_DIR}"
31-
}
32-
33-
setup_libc++() {
34-
clang_version=$1
35-
sudo apt-get update
36-
pkgs_to_check=("libc++-${clang_version}-dev")
37-
j=0
38-
while [ $j -lt ${#pkgs_to_check[*]} ]; do
39-
install_status=$(verify_pkg_installed ${pkgs_to_check[$j]})
40-
if [ "$install_status" == "" ]; then
41-
sudo apt-get install -y ${pkgs_to_check[$j]}
42-
if [[ $? -ne 0 ]]; then
43-
echo "ERROR: Failed to install required packages for libc++"
44-
exit 1
45-
fi
46-
fi
47-
j=$(( $j +1));
48-
done
49-
}
50-
51-
# This needs to match with the clang version from the Docker image
52-
setup_libc++ 12
12+
setup_libcpp 12
5313
install_qnn

.ci/scripts/unittest-linux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if [[ "$BUILD_TOOL" == "cmake" ]]; then
2222

2323
# We need the runner to test the built library.
2424
PYTHON_EXECUTABLE=python \
25-
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
25+
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
2626
.ci/scripts/setup-linux.sh "$@"
2727

2828
.ci/scripts/unittest-linux-cmake.sh

.ci/scripts/unittest-macos.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ trap 'rm -rfv ${TMP_DIR}' EXIT
2222
# Setup MacOS dependencies as there is no Docker support on MacOS atm
2323
# We need the runner to test the built library.
2424
PYTHON_EXECUTABLE=python \
25-
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
25+
CMAKE_ARGS="-DEXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL=ON -DEXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL=ON -DEXECUTORCH_BUILD_EXECUTOR_RUNNER=ON -DEXECUTORCH_BUILD_TESTS=ON" \
2626
${CONDA_RUN} --no-capture-output \
2727
.ci/scripts/setup-macos.sh "$@"
2828

.github/workflows/trunk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ jobs:
387387
eval "$(conda shell.bash hook)"
388388
389389
# Install requirements
390-
${CONDA_RUN} python install_executorch.py
390+
${CONDA_RUN} EXECUTORCH_BUILD_TORCHAO=1 python install_executorch.py
391391
${CONDA_RUN} sh examples/models/llama/install_requirements.sh
392392
393393
# Run test

CMakeLists.txt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ target_link_libraries(executorch PRIVATE executorch_core)
416416
target_include_directories(executorch PUBLIC ${_common_include_directories})
417417
target_compile_definitions(executorch PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
418418
target_compile_options(executorch PUBLIC ${_common_compile_options})
419-
target_link_options_shared_lib(executorch)
419+
executorch_target_link_options_shared_lib(executorch)
420420

421421
#
422422
# portable_ops_lib: A library to register core ATen ops using portable kernels,
@@ -548,6 +548,16 @@ if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
548548
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader)
549549
endif()
550550

551+
if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL)
552+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util)
553+
install(
554+
DIRECTORY extension/evalue_util/
555+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/evalue_util
556+
FILES_MATCHING
557+
PATTERN "*.h"
558+
)
559+
endif()
560+
551561
if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
552562
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor)
553563
endif()
@@ -576,6 +586,12 @@ endif()
576586

577587
if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
578588
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
589+
install(
590+
DIRECTORY extension/runner_util/
591+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/executorch/extension/runner_util
592+
FILES_MATCHING
593+
PATTERN "*.h"
594+
)
579595
endif()
580596

581597
if(EXECUTORCH_BUILD_EXTENSION_TENSOR)
@@ -651,8 +667,7 @@ if(EXECUTORCH_BUILD_PYBIND)
651667

652668
# util lib
653669
add_library(
654-
util ${CMAKE_CURRENT_SOURCE_DIR}/extension/evalue_util/print_evalue.cpp
655-
${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
670+
util ${CMAKE_CURRENT_SOURCE_DIR}/extension/aten_util/aten_bridge.cpp
656671
)
657672
target_include_directories(
658673
util PUBLIC ${_common_include_directories} ${TORCH_INCLUDE_DIRS}
@@ -690,12 +705,14 @@ endif()
690705

691706
if(EXECUTORCH_BUILD_KERNELS_QUANTIZED)
692707
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized)
693-
target_link_options_shared_lib(quantized_ops_lib)
708+
executorch_target_link_options_shared_lib(quantized_ops_lib)
694709
endif()
695710

696711
if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
697712
# Baseline libraries that executor_runner will link against.
698-
set(_executor_runner_libs executorch gflags)
713+
set(_executor_runner_libs executorch extension_evalue_util
714+
extension_runner_util gflags
715+
)
699716

700717
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
701718
list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib)

backends/apple/coreml/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ if(APPLE)
199199
${CMAKE_CURRENT_SOURCE_DIR}/third-party/coremltools/deps/protobuf/cmake
200200
)
201201

202-
target_link_options_shared_lib(libprotobuf-lite)
202+
executorch_target_link_options_shared_lib(libprotobuf-lite)
203203
target_link_libraries(coremldelegate PRIVATE libprotobuf-lite)
204204
endif()
205205

@@ -210,7 +210,7 @@ if(APPLE)
210210
${FOUNDATION_FRAMEWORK} ${SQLITE_LIBRARY}
211211
)
212212

213-
target_link_options_shared_lib(coremldelegate)
213+
executorch_target_link_options_shared_lib(coremldelegate)
214214

215215
if(EXECUTORCH_COREML_BUILD_EXECUTOR_RUNNER)
216216
target_link_libraries(

backends/apple/coreml/test/tester.py

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,73 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
from typing import Any, List, Optional, Tuple
7+
import functools
8+
from typing import Any, List, Optional, Sequence, Tuple
89

10+
import coremltools as ct
911
import executorch
1012
import executorch.backends.test.harness.stages as BaseStages
11-
1213
import torch
14+
15+
from executorch.backends.apple.coreml.compiler import CoreMLBackend
1316
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
17+
from executorch.backends.apple.coreml.quantizer import CoreMLQuantizer
1418
from executorch.backends.test.harness import Tester as TesterBase
1519
from executorch.backends.test.harness.stages import StageType
1620
from executorch.exir import EdgeCompileConfig
1721
from executorch.exir.backend.partitioner import Partitioner
1822

1923

24+
def _create_default_partitioner(
25+
minimum_deployment_target: Any = ct.target.iOS15,
26+
) -> CoreMLPartitioner:
27+
return CoreMLPartitioner(
28+
compile_specs=CoreMLBackend.generate_compile_specs(
29+
minimum_deployment_target=minimum_deployment_target
30+
)
31+
)
32+
33+
34+
def _get_static_int8_linear_qconfig():
35+
return ct.optimize.torch.quantization.LinearQuantizerConfig(
36+
global_config=ct.optimize.torch.quantization.ModuleLinearQuantizerConfig(
37+
quantization_scheme="symmetric",
38+
activation_dtype=torch.quint8,
39+
weight_dtype=torch.qint8,
40+
weight_per_channel=True,
41+
)
42+
)
43+
44+
45+
class Quantize(BaseStages.Quantize):
46+
def __init__(
47+
self,
48+
quantizer: Optional[CoreMLQuantizer] = None,
49+
quantization_config: Optional[Any] = None,
50+
calibrate: bool = True,
51+
calibration_samples: Optional[Sequence[Any]] = None,
52+
is_qat: Optional[bool] = False,
53+
):
54+
super().__init__(
55+
quantizer=quantizer
56+
or CoreMLQuantizer(
57+
quantization_config or _get_static_int8_linear_qconfig()
58+
),
59+
calibrate=calibrate,
60+
calibration_samples=calibration_samples,
61+
is_qat=is_qat,
62+
)
63+
64+
2065
class Partition(BaseStages.Partition):
21-
def __init__(self, partitioner: Optional[Partitioner] = None):
66+
def __init__(
67+
self,
68+
partitioner: Optional[Partitioner] = None,
69+
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
70+
):
2271
super().__init__(
23-
partitioner=partitioner or CoreMLPartitioner,
72+
partitioner=partitioner
73+
or _create_default_partitioner(minimum_deployment_target),
2474
)
2575

2676

@@ -29,9 +79,12 @@ def __init__(
2979
self,
3080
partitioners: Optional[List[Partitioner]] = None,
3181
edge_compile_config: Optional[EdgeCompileConfig] = None,
82+
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
3283
):
3384
super().__init__(
34-
default_partitioner_cls=CoreMLPartitioner,
85+
default_partitioner_cls=lambda: _create_default_partitioner(
86+
minimum_deployment_target
87+
),
3588
partitioners=partitioners,
3689
edge_compile_config=edge_compile_config,
3790
)
@@ -43,13 +96,20 @@ def __init__(
4396
module: torch.nn.Module,
4497
example_inputs: Tuple[torch.Tensor],
4598
dynamic_shapes: Optional[Tuple[Any]] = None,
99+
minimum_deployment_target: Optional[Any] = ct.target.iOS15,
46100
):
47101
# Specialize for XNNPACK
48102
stage_classes = (
49103
executorch.backends.test.harness.Tester.default_stage_classes()
50104
| {
51-
StageType.PARTITION: Partition,
52-
StageType.TO_EDGE_TRANSFORM_AND_LOWER: ToEdgeTransformAndLower,
105+
StageType.QUANTIZE: Quantize,
106+
StageType.PARTITION: functools.partial(
107+
Partition, minimum_deployment_target=minimum_deployment_target
108+
),
109+
StageType.TO_EDGE_TRANSFORM_AND_LOWER: functools.partial(
110+
ToEdgeTransformAndLower,
111+
minimum_deployment_target=minimum_deployment_target,
112+
),
53113
}
54114
)
55115

backends/apple/mps/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ target_link_libraries(
7070
${MPS_FRAMEWORK} ${MPS_GRAPH_FRAMEWORK}
7171
)
7272

73-
target_link_options_shared_lib(mpsdelegate)
73+
executorch_target_link_options_shared_lib(mpsdelegate)
7474
target_compile_options(mpsdelegate PUBLIC ${_common_compile_options})
7575
target_compile_options(mpsdelegate PRIVATE "-fno-objc-arc")
7676

backends/cadence/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ if(EXECUTORCH_CADENCE_CPU_RUNNER)
3535
# Find prebuilt libraries. executorch package should contain portable_ops_lib,
3636
# etdump, bundled_program.
3737
find_package(executorch CONFIG REQUIRED)
38-
target_link_options_shared_lib(executorch)
39-
target_link_options_shared_lib(portable_ops_lib)
38+
executorch_target_link_options_shared_lib(executorch)
39+
executorch_target_link_options_shared_lib(portable_ops_lib)
4040

4141
target_include_directories(executorch INTERFACE ${_common_include_directories})
4242

backends/cadence/aot/export_example.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ def export_model(
5252
# Prepare the model
5353
prepared_gm = prepare_pt2(model, example_inputs, quantizer)
5454

55+
# Calibrate the model
56+
for samples in [example_inputs]:
57+
prepared_gm(*samples)
58+
59+
# Prepare the model
60+
prepared_gm = prepare_pt2(ep, quantizer)
61+
5562
# Calibrate the model
5663
for samples in [example_inputs]:
5764
prepared_gm(*samples)

0 commit comments

Comments
 (0)