Skip to content

Commit 50a8b60

Browse files
committed
Update
1 parent 47b121a commit 50a8b60

File tree

7 files changed

+41
-43
lines changed

7 files changed

+41
-43
lines changed

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 & 7 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,16 +55,16 @@ 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})
58+
59+
set(runner_deps executorch_core extension_module extension_tensor tokenizers)
5860

5961
target_link_libraries(extension_llm_runner PUBLIC ${runner_deps})
6062
set_target_properties(extension_llm_runner PROPERTIES POSITION_INDEPENDENT_CODE ON)
6163

64+
target_compile_definitions(extension_llm_runner PUBLIC C10_USING_CUSTOM_GENERATED_MACROS)
6265
target_include_directories(
6366
extension_llm_runner
64-
INTERFACE ${_common_include_directories}
67+
PUBLIC ${_common_include_directories}
6568
${EXECUTORCH_ROOT}/extension/llm/tokenizers/include
6669
)
6770

extension/llm/runner/text_llm_runner.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,14 @@ std::unordered_map<std::string, int64_t> get_llm_metadata(
353353
}
354354
// Check if we are using cache positions instead of input pos.
355355
auto second_input_info = method_meta.input_tensor_meta(1).get();
356-
// For input_pos, size is [1], for cache_positions, size is [1, max_seq_len]
357-
metadata[llm::kUseCachePositions] = second_input_info.sizes().size() == 2;
356+
// For input_pos, numel is 1, for cache_positions, numel is max_seq_len
357+
auto sizes = second_input_info.sizes();
358+
int64_t total_size = 1;
359+
for (const auto& size : sizes) {
360+
total_size *= size;
361+
}
362+
metadata[llm::kUseCachePositions] = total_size > 1;
363+
return metadata;
358364
}
359365

360366
std::unordered_set<uint64_t> get_eos_ids(
@@ -420,6 +426,7 @@ std::unique_ptr<TextLLMRunner> create_text_llm_runner(
420426
auto text_prefiller = std::make_unique<TextPrefiller>(
421427
text_decoder_runner.get(),
422428
metadata.at(kUseKVCache),
429+
metadata.at(kUseCachePositions),
423430
metadata.at(kEnableDynamicShape),
424431
metadata.at(kMaxSeqLen));
425432

tools/cmake/executorch-config.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
cmake_minimum_required(VERSION 3.19)
2727
include("${CMAKE_CURRENT_LIST_DIR}/Utils.cmake")
2828

29+
include(${CMAKE_CURRENT_LIST_DIR}/Utils.cmake)
30+
2931
set(_root "${CMAKE_CURRENT_LIST_DIR}/../../..")
3032
set(required_lib_list executorch executorch_core portable_kernels)
3133
set(EXECUTORCH_LIBRARIES)
@@ -164,6 +166,7 @@ if(TARGET optimized_native_cpu_ops_lib)
164166
PROPERTIES INTERFACE_LINK_LIBRARIES
165167
"optimized_kernels;${_maybe_optimized_portable_kernels_lib}"
166168
)
169+
target_link_options_shared_lib(optimized_native_cpu_ops_lib)
167170
endif()
168171
if(TARGET extension_threadpool)
169172
target_compile_definitions(extension_threadpool INTERFACE ET_USE_THREADPOOL)

0 commit comments

Comments
 (0)