Skip to content

Commit 277fd57

Browse files
committed
Update
1 parent 5ccd817 commit 277fd57

File tree

8 files changed

+53
-45
lines changed

8 files changed

+53
-45
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ install(
473473
INCLUDES
474474
DESTINATION ${_common_include_directories}
475475
)
476-
install(FILES tools/cmake/executorch-config.cmake
476+
install(FILES tools/cmake/executorch-config.cmake tools/cmake/Utils.cmake
477477
DESTINATION lib/cmake/ExecuTorch
478478
)
479479

examples/models/llama/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ find_package(gflags REQUIRED)
8080
# find `executorch` libraries Same as for gflags
8181
set(executorch_DIR ${CMAKE_CURRENT_BINARY_DIR}/../../../lib/cmake/ExecuTorch)
8282
find_package(executorch CONFIG REQUIRED)
83-
target_link_options_shared_lib(executorch)
8483

8584
# llama_runner library
8685
add_subdirectory(runner)
8786

8887
set(link_libraries executorch gflags)
88+
target_link_options_shared_lib(executorch)
89+
8990
set(_srcs main.cpp)
9091

9192
if(TARGET optimized_native_cpu_ops_lib)

examples/models/llama/runner/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if(NOT TARGET extension_llm_runner)
6060
)
6161
endif()
6262

63-
set(llama_runner_deps executorch_core extension_data_loader extension_module
63+
set(llama_runner_deps executorch_core extension_data_loader extension_module_static
6464
extension_tensor extension_flat_tensor extension_llm_runner
6565
)
6666

examples/models/phi-3-mini/CMakeLists.txt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,12 @@ set(CMAKE_CXX_STANDARD 17)
2020
set(CMAKE_CXX_STANDARD_REQUIRED True)
2121
set(CMAKE_BUILD_TYPE Release)
2222

23-
# Set options for executorch build.
24-
option(EXECUTORCH_BUILD_EXECUTOR_RUNNER "" OFF)
25-
option(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER "" ON)
26-
option(EXECUTORCH_BUILD_EXTENSION_MODULE "" ON)
27-
option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER "" ON)
28-
option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR "" ON)
29-
option(EXECUTORCH_BUILD_EXTENSION_TENSOR "" ON)
30-
option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED "" ON)
31-
option(EXECUTORCH_BUILD_XNNPACK "" ON)
32-
33-
add_subdirectory(
34-
${CMAKE_CURRENT_SOURCE_DIR}/../../.. ${CMAKE_BINARY_DIR}/../../..
35-
)
23+
set(EXECUTORCH_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../..")
24+
find_package(executorch CONFIG REQUIRED)
25+
26+
set(BUILD_TESTING OFF)
27+
add_subdirectory(${EXECUTORCH_ROOT}/extension/llm/runner ${CMAKE_BINARY_DIR}/../../../extension/llm/runner)
28+
3629
if(NOT TARGET gflags)
3730
add_subdirectory(
3831
${CMAKE_CURRENT_SOURCE_DIR}/../../../third-party/gflags
@@ -44,11 +37,7 @@ add_executable(
4437
phi_3_mini_runner
4538
main.cpp
4639
)
47-
# target_include_directories(
48-
# phi_3_mini_runner
49-
# PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../../../third-party/gflags/src
50-
# ${CMAKE_CURRENT_SOURCE_DIR}/../../../extension/llm/tokenizers/include
51-
# )
40+
5241
target_link_libraries(
53-
phi_3_mini_runner PUBLIC optimized_native_cpu_ops_lib xnnpack_backend gflags extension_llm_runner
42+
phi_3_mini_runner PUBLIC executorch optimized_native_cpu_ops_lib xnnpack_backend gflags extension_llm_runner
5443
)

examples/models/phi-3-mini/README.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,17 @@ python -m examples.models.phi-3-mini.export_phi-3-mini -c "4k" -s 128 -o phi-3-m
2121
```
2222
3. Build and run the model.
2323
- Build executorch with optimized CPU performance as follows. Build options available [here](https://github.com/pytorch/executorch/blob/main/CMakeLists.txt#L59).
24-
```
25-
cmake --preset llm -DCMAKE_INSTALL_PREFIX=cmake-out
24+
```
25+
cmake --preset llm -DCMAKE_INSTALL_PREFIX=cmake-out
2626
27-
cmake --build cmake-out -j16 --target install --config Release
28-
```
27+
cmake --build cmake-out -j16 --target install --config Release
28+
```
2929
- Build Phi-3-mini runner.
3030
```
31-
cmake -DPYTHON_EXECUTABLE=python \
32-
-DCMAKE_INSTALL_PREFIX=cmake-out \
33-
-DCMAKE_BUILD_TYPE=Release \
34-
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
35-
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
36-
-DEXECUTORCH_BUILD_XNNPACK=ON \
37-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
38-
-Bcmake-out/examples/models/phi-3-mini \
39-
examples/models/phi-3-mini
31+
cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
32+
-DCMAKE_BUILD_TYPE=Release \
33+
-Bcmake-out/examples/models/phi-3-mini \
34+
examples/models/phi-3-mini
4035
4136
cmake --build cmake-out/examples/models/phi-3-mini -j16 --config Release
4237
```

extension/llm/runner/CMakeLists.txt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ include(${EXECUTORCH_SRCS_FILE})
3737
# build llm runner library
3838
list(TRANSFORM _extension_llm_runner__srcs PREPEND "${EXECUTORCH_ROOT}/")
3939

40-
target_include_directories(
41-
extension_module INTERFACE ${_common_include_directories}
42-
)
40+
if(NOT _common_include_directories)
41+
set(_common_include_directories
42+
${EXECUTORCH_ROOT}/..
43+
${EXECUTORCH_ROOT}/runtime/core/portable_type/c10
44+
)
45+
endif()
4346

4447
add_library(extension_llm_runner STATIC ${_extension_llm_runner__srcs})
4548

@@ -52,15 +55,14 @@ add_subdirectory(
5255
${EXECUTORCH_ROOT}/extension/llm/tokenizers
5356
${CMAKE_CURRENT_BINARY_DIR}/../../../extension/llm/tokenizers
5457
)
55-
add_dependencies(extension_llm_runner tokenizers_external_project)
56-
find_package(tokenizers CONFIG HINTS ${CMAKE_INSTALL_PREFIX} ${CMAKE_CURRENT_BINARY_DIR}/../tokenizers)
57-
set(runner_deps executorch extension_module extension_tensor ${TOKENIZERS_LIBRARIES})
5858

59-
target_link_libraries(extension_llm_runner PUBLIC ${runner_deps})
59+
set(runner_deps executorch_core extension_module extension_tensor tokenizers)
6060

61+
target_link_libraries(extension_llm_runner PUBLIC ${runner_deps})
62+
target_compile_definitions(extension_llm_runner PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
6163
target_include_directories(
6264
extension_llm_runner
63-
INTERFACE ${_common_include_directories}
65+
PUBLIC ${_common_include_directories}
6466
${EXECUTORCH_ROOT}/extension/llm/tokenizers/include
6567
)
6668

extension/llm/runner/text_llm_runner.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,14 @@ std::unordered_map<std::string, int64_t> get_llm_metadata(
318318
}
319319
// Check if we are using cache positions instead of input pos.
320320
auto second_input_info = method_meta.input_tensor_meta(1).get();
321-
// For input_pos, size is [1], for cache_positions, size is [1, max_seq_len]
322-
metadata[llm::kUseCachePositions] = second_input_info.sizes().size() == 2;
321+
// For input_pos, numel is 1, for cache_positions, numel is max_seq_len
322+
auto sizes = second_input_info.sizes();
323+
int64_t total_size = 1;
324+
for (const auto& size : sizes) {
325+
total_size *= size;
326+
}
327+
metadata[llm::kUseCachePositions] = total_size > 1;
328+
return metadata;
323329
}
324330

325331
std::unordered_set<uint64_t> get_eos_ids(
@@ -386,6 +392,7 @@ std::unique_ptr<TextLLMRunner> create_text_llm_runner(
386392
auto text_prefiller = std::make_unique<TextPrefiller>(
387393
text_decoder_runner.get(),
388394
metadata.at(kUseKVCache),
395+
metadata.at(kUseCachePositions),
389396
metadata.at(kEnableDynamicShape),
390397
metadata.at(kMaxSeqLen));
391398

tools/cmake/executorch-config.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
cmake_minimum_required(VERSION 3.19)
2727

28+
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)
29+
2830
set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..")
2931
set(required_lib_list executorch executorch_core portable_kernels)
3032
set(EXECUTORCH_LIBRARIES)
@@ -163,6 +165,7 @@ if(TARGET optimized_native_cpu_ops_lib)
163165
PROPERTIES INTERFACE_LINK_LIBRARIES
164166
"optimized_kernels;${_maybe_optimized_portable_kernels_lib}"
165167
)
168+
target_link_options_shared_lib(optimized_native_cpu_ops_lib)
166169
endif()
167170
if(TARGET extension_threadpool)
168171
target_compile_definitions(extension_threadpool INTERFACE ET_USE_THREADPOOL)
@@ -171,3 +174,14 @@ if(TARGET extension_threadpool)
171174
"cpuinfo;pthreadpool"
172175
)
173176
endif()
177+
if(TARGET xnnpack_backend)
178+
if(TARGET kleidiai)
179+
set(_deps "XNNPACK;microkernels-prod;kleidiai")
180+
else()
181+
set(_deps "XNNPACK;microkernels-prod")
182+
endif()
183+
set_target_properties(
184+
xnnpack_backend PROPERTIES INTERFACE_LINK_LIBRARIES "${_deps}"
185+
)
186+
target_link_options_shared_lib(xnnpack_backend)
187+
endif()

0 commit comments

Comments
 (0)