Skip to content

Commit c256723

Browse files
Add CMake preset for LLM (#11066)
This PR was created by the merge bot to help merge the original PR into the main branch. ghstack PR number: #11052 by @larryliu0820 ^ Please use this as the source of truth for the PR details, comments, and reviews ghstack PR base: https://github.com/pytorch/executorch/tree/gh/larryliu0820/64/base ghstack PR head: https://github.com/pytorch/executorch/tree/gh/larryliu0820/64/head Merge bot PR base: https://github.com/pytorch/executorch/tree/main Merge bot PR head: https://github.com/pytorch/executorch/tree/gh/larryliu0820/64/orig @diff-train-skip-merge Co-authored-by: Mengwei Liu <[email protected]>
1 parent 936ac2b commit c256723

File tree

6 files changed

+59
-32
lines changed

6 files changed

+59
-32
lines changed

.ci/scripts/build_llama_android.sh

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,12 @@ install_executorch_and_backend_lib() {
2222
ANDROID_NDK=/opt/ndk
2323
BUCK2=buck2
2424
ANDROID_ABI=arm64-v8a
25-
cmake -DBUCK2="${BUCK2}" \
25+
cmake --preset llm \
26+
-DBUCK2="${BUCK2}" \
2627
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
2728
-DANDROID_ABI="${ANDROID_ABI}" \
2829
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
2930
-DCMAKE_BUILD_TYPE=Release \
30-
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
31-
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
32-
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
33-
-DEXECUTORCH_BUILD_XNNPACK=ON \
34-
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
35-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
36-
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
3731
-DXNNPACK_ENABLE_ARM_BF16=OFF \
3832
-Bcmake-android-out .
3933

@@ -51,11 +45,7 @@ build_llama_runner() {
5145
-DCMAKE_TOOLCHAIN_FILE="$ANDROID_NDK"/build/cmake/android.toolchain.cmake \
5246
-DANDROID_ABI="${ANDROID_ABI}" \
5347
-DCMAKE_INSTALL_PREFIX=cmake-android-out \
54-
-DCMAKE_BUILD_TYPE=Release -DPYTHON_EXECUTABLE=python \
55-
-DEXECUTORCH_BUILD_XNNPACK=ON \
56-
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
57-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
58-
-DEXECUTORCH_BUILD_KERNELS_CUSTOM=ON \
48+
-DCMAKE_BUILD_TYPE=Release \
5949
-Bcmake-android-out/examples/models/llama examples/models/llama
6050

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

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,11 @@ which "${PYTHON_EXECUTABLE}"
152152
cmake_install_executorch_libraries() {
153153
echo "Installing libexecutorch.a, libextension_module.so, libportable_ops_lib.a"
154154
rm -rf cmake-out
155-
retry cmake \
155+
retry cmake --preset llm \
156156
-DCMAKE_INSTALL_PREFIX=cmake-out \
157157
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
158-
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
159-
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
160-
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
161-
-DEXECUTORCH_BUILD_KERNELS_CUSTOM="$CUSTOM" \
162-
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
163-
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
164-
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
165-
-DEXECUTORCH_BUILD_MPS="$MPS" \
166-
-DEXECUTORCH_BUILD_COREML="$COREML" \
167158
-DEXECUTORCH_BUILD_QNN="$QNN" \
168159
-DQNN_SDK_ROOT="$QNN_SDK_ROOT" \
169-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
170160
-Bcmake-out .
171161
cmake --build cmake-out -j9 --target install --config "$CMAKE_BUILD_TYPE"
172162
}
@@ -181,10 +171,6 @@ cmake_build_llama_runner() {
181171
retry cmake \
182172
-DCMAKE_INSTALL_PREFIX=cmake-out \
183173
-DCMAKE_BUILD_TYPE="$CMAKE_BUILD_TYPE" \
184-
-DEXECUTORCH_BUILD_KERNELS_CUSTOM="$CUSTOM" \
185-
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
186-
-DEXECUTORCH_BUILD_XNNPACK="$XNNPACK" \
187-
-DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
188174
-Bcmake-out/${dir} \
189175
${dir}
190176
cmake --build cmake-out/${dir} -j9 --config "$CMAKE_BUILD_TYPE"

.github/workflows/build-presets.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
preset: [macos-arm64, pybind]
23+
preset: [macos-arm64, pybind, llm]
2424
with:
2525
job-name: build
2626
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
@@ -39,7 +39,7 @@ jobs:
3939
strategy:
4040
fail-fast: false
4141
matrix:
42-
preset: [pybind]
42+
preset: [pybind, llm]
4343
runner: [linux.2xlarge, linux.arm64.2xlarge]
4444
docker-image: [executorch-ubuntu-22.04-clang12, executorch-ubuntu-22.04-gcc11-aarch64]
4545
# Excluding specific runner + docker image combinations that don't make sense:

CMakePresets.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@
3636
"string": "${hostSystemName}",
3737
"list": ["Darwin", "Linux", "Windows"]
3838
}
39+
},
40+
{
41+
"name": "llm",
42+
"displayName": "Build LLM libraries",
43+
"inherits": [
44+
"common"
45+
],
46+
"cacheVariables": {
47+
"EXECUTORCH_BUILD_PRESET_FILE": "${sourceDir}/tools/cmake/preset/llm.cmake",
48+
"CMAKE_OSX_DEPLOYMENT_TARGET": "10.15"
49+
},
50+
"condition": {
51+
"type": "inList",
52+
"string": "${hostSystemName}",
53+
"list": [
54+
"Darwin",
55+
"Linux",
56+
"Windows"
57+
]
58+
}
3959
}
4060
]
4161
}

examples/models/llama/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ add_subdirectory(runner)
8888
set(link_libraries executorch gflags)
8989
set(_srcs main.cpp)
9090

91-
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
91+
if(TARGET optimized_native_cpu_ops_lib)
9292
list(
9393
APPEND
9494
link_libraries
@@ -108,7 +108,7 @@ endif()
108108
target_link_options_shared_lib(quantized_ops_lib)
109109
list(APPEND link_libraries quantized_kernels quantized_ops_lib)
110110

111-
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
111+
if(TARGET custom_ops)
112112
target_link_options_shared_lib(custom_ops)
113113
list(APPEND link_libraries custom_ops)
114114
endif()

tools/cmake/preset/llm.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# Enable logging even when in release mode. We are building for desktop, where
8+
# saving a few kB is less important than showing useful error information to
9+
# users.
10+
# keep sorted
11+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON)
12+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR ON)
13+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_MODULE ON)
14+
set_overridable_option(EXECUTORCH_BUILD_EXTENSION_TENSOR ON)
15+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_CUSTOM ON)
16+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_OPTIMIZED ON)
17+
set_overridable_option(EXECUTORCH_BUILD_KERNELS_QUANTIZED ON)
18+
set_overridable_option(EXECUTORCH_BUILD_XNNPACK ON)
19+
20+
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
21+
set_overridable_option(EXECUTORCH_BUILD_COREML ON)
22+
set_overridable_option(EXECUTORCH_BUILD_MPS ON)
23+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
24+
# Linux-specific code here
25+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "WIN32")
26+
# Windows or other OS-specific code here
27+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Android")
28+
# Android-specific code here
29+
else()
30+
message(FATAL_ERROR "Unsupported CMAKE_SYSTEM_NAME for LLM: ${CMAKE_SYSTEM_NAME}")
31+
endif()

0 commit comments

Comments
 (0)