Skip to content

Commit 6912560

Browse files
authored
Merge branch 'main' into jz/update-bug-report-yml
2 parents dc3cc3f + 4f90ce4 commit 6912560

File tree

172 files changed

+5096
-1418
lines changed

Some content is hidden

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

172 files changed

+5096
-1418
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1414
PYTHON_EXECUTABLE=python3
1515
fi
1616
which "${PYTHON_EXECUTABLE}"
17-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
1817

1918
install_executorch_and_backend_lib() {
2019
echo "Installing executorch and xnnpack backend"
@@ -28,7 +27,6 @@ install_executorch_and_backend_lib() {
2827
-DANDROID_ABI="${ANDROID_ABI}" \
2928
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
3029
-DCMAKE_BUILD_TYPE=Release \
31-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
3230
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
3331
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
3432
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
@@ -54,7 +52,6 @@ build_llama_runner() {
5452
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
5553
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
5654
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
57-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
5855
-Bcmake-android-out/examples/models/llama examples/models/llama
5956

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

.ci/scripts/test_llama.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ 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])')" \
158157
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
159158
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
160159
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \

.ci/scripts/test_llava.sh

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ NPROC=8
3131
if hash nproc &> /dev/null; then NPROC=$(nproc); fi
3232

3333
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])')"
3534
EXECUTORCH_COMMON_CMAKE_ARGS=" \
3635
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
3736
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} \
@@ -48,7 +47,6 @@ EXECUTORCH_COMMON_CMAKE_ARGS=" \
4847
cmake_install_executorch_libraries() {
4948
cmake \
5049
${EXECUTORCH_COMMON_CMAKE_ARGS} \
51-
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
5250
-B${BUILD_DIR} .
5351

5452
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -59,7 +57,6 @@ cmake_install_executorch_libraries_for_android() {
5957
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
6058
-DANDROID_ABI=arm64-v8a \
6159
${EXECUTORCH_COMMON_CMAKE_ARGS} \
62-
"-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" \
6360
-B${BUILD_DIR} .
6461

6562
cmake --build ${BUILD_DIR} -j${NPROC} --target install --config ${CMAKE_BUILD_TYPE}
@@ -80,7 +77,7 @@ cmake_build_llava_runner() {
8077

8178
cmake \
8279
${LLAVA_COMMON_CMAKE_ARGS} \
83-
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
80+
-DCMAKE_PREFIX_PATH="$python_lib" \
8481
-B${BUILD_DIR}/${dir} \
8582
${dir}
8683

@@ -96,7 +93,7 @@ cmake_build_llava_runner_for_android() {
9693
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
9794
-DANDROID_ABI=arm64-v8a \
9895
${LLAVA_COMMON_CMAKE_ARGS} \
99-
-DCMAKE_PREFIX_PATH="$python_lib;${CMAKE_PREFIX_PATH}" \
96+
-DCMAKE_PREFIX_PATH="$python_lib" \
10097
-DLLAVA_RUNNER_NO_TORCH_DUMMY_IMAGE=ON \
10198
-B${BUILD_DIR}/${dir} \
10299
${dir}

.ci/scripts/test_model.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,10 @@ 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])')"
5453
rm -rf ${CMAKE_OUTPUT_DIR}
5554
cmake -DCMAKE_BUILD_TYPE=Debug \
5655
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
5756
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
58-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
5957
-B${CMAKE_OUTPUT_DIR} .
6058

6159
cmake --build ${CMAKE_OUTPUT_DIR} -j4 --config Debug
@@ -100,14 +98,12 @@ test_model() {
10098

10199
build_cmake_xnn_executor_runner() {
102100
echo "Building xnn_executor_runner"
103-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
104101

105102
(rm -rf ${CMAKE_OUTPUT_DIR} \
106103
&& mkdir ${CMAKE_OUTPUT_DIR} \
107104
&& cd ${CMAKE_OUTPUT_DIR} \
108105
&& retry cmake -DCMAKE_BUILD_TYPE=Release \
109106
-DEXECUTORCH_BUILD_XNNPACK=ON \
110-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
111107
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
112108

113109
cmake --build ${CMAKE_OUTPUT_DIR} -j4

.ci/scripts/test_phi_3_mini.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ 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])')"
2625
cmake -DPYTHON_EXECUTABLE=python \
2726
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
28-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
2927
-DEXECUTORCH_ENABLE_LOGGING=1 \
3028
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
3129
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
@@ -41,10 +39,8 @@ cmake_install_executorch_libraries() {
4139
}
4240

4341
cmake_build_phi_3_mini() {
44-
CMAKE_PREFIX_PATH="$(python3 -c 'import torch as _; print(_.__path__[0])')"
4542
cmake -DPYTHON_EXECUTABLE=$PYTHON_EXECUTABLE \
4643
-DCMAKE_INSTALL_PREFIX=${BUILD_DIR} \
47-
-DCMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}" \
4844
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
4945
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
5046
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \

.ci/scripts/test_qnn_static_llama.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ $PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o to
3434

3535
set +e
3636
# Compile only as weight sharing is not applicable on x86
37-
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_stories_single_llama --model SM8650 --build_folder build-android/ --executorch_root . --artifact_dir . --compile_only
37+
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --model SM8650 --build_folder build-android/ --executorch_root . --artifact_dir . --llama_artifacts . --compile_only
3838
exit_code1=$?
3939

4040
# Checks accuracy with weight sharing disabled since x86 does not support weight sharing.
41-
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleScript.test_stories_single_llama --model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir . --enable_x86_64
41+
$PYTHON_EXECUTABLE backends/qualcomm/tests/test_qnn_delegate.py -k TestExampleLLMScript.test_llama_stories_110m --model SM8650 --build_folder build-x86/ --executorch_root . --artifact_dir . --llama_artifacts . --enable_x86_64
4242
exit_code2=$?
4343

4444
# Check the exit codes and print messages

.ci/scripts/test_quantized_aot_lib.sh

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,10 @@ CMAKE_OUTPUT_DIR=cmake-out
1616

1717
build_cmake_quantized_aot_lib() {
1818
echo "Building quantized aot lib"
19-
SITE_PACKAGES="$(${PYTHON_EXECUTABLE} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')"
20-
CMAKE_PREFIX_PATH="${SITE_PACKAGES}/torch"
2119
(rm -rf ${CMAKE_OUTPUT_DIR} \
2220
&& mkdir ${CMAKE_OUTPUT_DIR} \
2321
&& cd ${CMAKE_OUTPUT_DIR} \
2422
&& retry cmake -DCMAKE_BUILD_TYPE=Release \
25-
-DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
2623
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED_AOT=ON \
2724
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" ..)
2825

.ci/scripts/utils.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ 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])')" \
140139
-DCMAKE_BUILD_TYPE=Release \
141140
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
142141
-Bcmake-out .

.github/workflows/trunk.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ jobs:
159159
sudo sysctl fs.inotify.max_user_watches=1048576 # 1024 * 1024
160160
161161
# Test ethos-u delegate examples with run.sh
162-
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
162+
backends/arm/test/test_arm_baremetal.sh test_full_ethosu_fvp
163163
164164
165165
test-arm-reference-delegation:
@@ -394,7 +394,6 @@ 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])')" \
398397
-DCMAKE_BUILD_TYPE=Release \
399398
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
400399
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
@@ -412,7 +411,6 @@ jobs:
412411
cmake \
413412
-DCMAKE_INSTALL_PREFIX=cmake-out \
414413
-DCMAKE_BUILD_TYPE=Release \
415-
-DCMAKE_PREFIX_PATH="$(python -c 'import torch as _; print(_.__path__[0])')" \
416414
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
417415
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
418416
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \

CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR "Build the Flat Tensor extension"
186186
OFF
187187
)
188188

189+
option(EXECUTORCH_BUILD_EXTENSION_LLM "Build the LLM extension"
190+
OFF
191+
)
192+
189193
option(EXECUTORCH_BUILD_EXTENSION_MODULE "Build the Module extension" OFF)
190194

191195
option(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL "Build the Runner Util extension"
@@ -718,6 +722,10 @@ if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
718722
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor/serialize)
719723
endif()
720724

725+
if(EXECUTORCH_BUILD_EXTENSION_LLM)
726+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizer)
727+
endif()
728+
721729
if(EXECUTORCH_BUILD_EXTENSION_MODULE)
722730
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/module)
723731
endif()
@@ -753,9 +761,7 @@ if(EXECUTORCH_BUILD_PYBIND)
753761
endif()
754762

755763
# find pytorch lib, to allow pybind to take at::Tensor as input/output
756-
if(NOT TARGET torch)
757-
find_package(Torch CONFIG REQUIRED)
758-
endif()
764+
find_package_torch()
759765
find_library(
760766
TORCH_PYTHON_LIBRARY torch_python PATHS "${TORCH_INSTALL_PREFIX}/lib"
761767
)

backends/apple/coreml/partition/coreml_partitioner.py

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

55
import logging
6-
from typing import List, Optional
6+
from typing import Callable, List, Optional, Tuple
77

88
import coremltools as ct
99

@@ -104,3 +104,17 @@ def partition(self, exported_program: ExportedProgram) -> PartitionResult:
104104
return PartitionResult(
105105
tagged_exported_program=exported_program, partition_tags=partition_tags
106106
)
107+
108+
def ops_to_not_decompose(
109+
self, ep: ExportedProgram
110+
) -> Tuple[List[torch._ops.OpOverload], Optional[Callable[[torch.fx.Node], bool]]]:
111+
do_not_decompose = []
112+
op_support = OperatorsSupportedForCoreMLBackend()
113+
for node in ep.graph.nodes:
114+
if (
115+
node.op == "call_function"
116+
and isinstance(node.target, torch._ops.OpOverload)
117+
and op_support.is_node_supported(None, node)
118+
):
119+
do_not_decompose.append(node.target)
120+
return do_not_decompose, None

backends/apple/coreml/test/test_coreml_partitioner.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from executorch.backends.apple.coreml.compiler import CoreMLBackend
1515
from executorch.backends.apple.coreml.partition import CoreMLPartitioner
16+
from executorch.exir.backend.utils import format_delegated_graph
1617

1718

1819
class TestCoreMLPartitioner(unittest.TestCase):
@@ -79,6 +80,50 @@ def test_vit_skip_conv(self):
7980
"getitem",
8081
]
8182

83+
def test_ops_to_not_decompose(self):
84+
class Model(torch.nn.Module):
85+
def forward(self, q, k, v, mask):
86+
return torch.ops.aten.scaled_dot_product_attention.default(
87+
q, k, v, attn_mask=mask
88+
)
89+
90+
model = Model()
91+
model.eval()
92+
93+
batch_size = 1
94+
n_heads = 12
95+
seq_len = 1
96+
max_seq_length = 32
97+
embedding_dim = 16
98+
q = torch.randn(batch_size, n_heads, seq_len, embedding_dim)
99+
k = torch.randn(batch_size, n_heads, max_seq_length, embedding_dim)
100+
v = torch.randn(batch_size, n_heads, max_seq_length, embedding_dim)
101+
mask = torch.randn(seq_len, max_seq_length)
102+
example_inputs = (q, k, v, mask)
103+
ep = torch.export.export(model, example_inputs)
104+
coreml_partitioner = CoreMLPartitioner()
105+
106+
# Using to_edge_transform_and_lower, we expect SDPA will be preserved and show up in delegated graph
107+
edge_program_manager = executorch.exir.to_edge_transform_and_lower(
108+
ep, partitioner=[coreml_partitioner]
109+
)
110+
self.assertTrue(
111+
"executorch.exir.dialects.edge._ops.aten.scaled_dot_product_attention.default"
112+
in format_delegated_graph(
113+
edge_program_manager.exported_program().graph_module
114+
)
115+
)
116+
117+
# Using to_edge flow, we expect SDPA will be decomposed and not show up in delegated graph
118+
edge_program_manager2 = executorch.exir.to_edge(ep)
119+
edge_program_manager2.to_backend(coreml_partitioner)
120+
self.assertTrue(
121+
"executorch.exir.dialects.edge._ops.aten.scaled_dot_product_attention.default"
122+
not in format_delegated_graph(
123+
edge_program_manager2.exported_program().graph_module
124+
)
125+
)
126+
82127
def test_buffer(self):
83128
embedding_dim = 3
84129
max_seq_len = 2
@@ -129,4 +174,5 @@ def forward(self, q, k_val, input_pos):
129174
test_runner = TestCoreMLPartitioner()
130175
test_runner.test_add_sub_skip_mm()
131176
test_runner.test_vit_skip_conv()
177+
test_runner.test_ops_to_not_decompose()
132178
test_runner.test_buffer()

backends/arm/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ To run the unit test suite with Corstone3x0 FVP simulator support use
5555
backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp
5656
```
5757

58-
You can test to run some models with the run.sh flow
58+
You can test to run some models with the full fvp test flow
5959

6060
```
61-
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
61+
backends/arm/test/test_arm_baremetal.sh test_full_ethosu_fvp
6262
```
6363

6464
## Unit tests

backends/arm/TARGETS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
44
python_library(
55
name = "arm_partitioner",
66
srcs = [
7-
"arm_partitioner.py",
7+
"ethosu_backend.py",
8+
"ethosu_partitioner.py",
9+
"tosa_backend.py",
10+
"tosa_partitioner.py",
811
],
912
typing = True,
1013
deps = [

0 commit comments

Comments
 (0)