Skip to content

Commit 241e9d6

Browse files
committed
Update setup.sh for tokenizer selection
Summary: For LLAMA3, users need to use tiktoken. Add a option to load from env var. Differential Revision: D56374673
1 parent 7469a28 commit 241e9d6

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

examples/demo-apps/android/LlamaDemo/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ Note: `<path_to_android_ndk>` is the root for the NDK, which is usually under
3838
`~/Library/Android/sdk/ndk/XX.Y.ZZZZZ` for macOS, and contains NOTICE and README.md.
3939
We use `<path_to_android_ndk>/build/cmake/android.toolchain.cmake` for CMake to cross-compile.
4040

41-
3. Run the following command set up the required JNI library:
41+
3. (Optional) If you need to use tiktoken as the tokenizer (for LLaMA3), set
42+
`EXECUTORCH_USE_TIKTOKEN=ON` and later CMake will use it as the tokenizer.
43+
If you need to run other models like LLaMA2, skip this skip.
44+
45+
```bash
46+
export EXECUTORCH_USE_TIKTOKEN=ON # Only for LLaMA3
47+
```
48+
49+
4. Run the following command set up the required JNI library:
4250
```bash
4351
pushd examples/demo-apps/android/LlamaDemo
4452
./gradlew :app:setup

examples/demo-apps/android/LlamaDemo/setup.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
set -eu
99

1010
CMAKE_OUT="${CMAKE_OUT:-cmake-out-android}"
11+
EXECUTORCH_USE_TIKTOKEN="${EXECUTORCH_USE_TIKTOKEN:-OFF}"
1112
# Note: Set up ANDROID_NDK and ANDROID_ABI
1213
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
1314
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
@@ -32,6 +33,7 @@ cmake examples/models/llama2 \
3233
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
3334
-DANDROID_ABI="$ANDROID_ABI" \
3435
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
36+
-DEXECUTORCH_USE_TIKTOKEN="${EXECUTORCH_USE_TIKTOKEN}" \
3537
-DCMAKE_BUILD_TYPE=Release \
3638
-B"${CMAKE_OUT}"/examples/models/llama2
3739

@@ -42,6 +44,7 @@ cmake extension/android \
4244
-DANDROID_ABI="${ANDROID_ABI}" \
4345
-DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
4446
-DEXECUTORCH_BUILD_LLAMA_JNI=ON \
47+
-DEXECUTORCH_USE_TIKTOKEN="${EXECUTORCH_USE_TIKTOKEN}" \
4548
-DCMAKE_BUILD_TYPE=Release \
4649
-B"${CMAKE_OUT}"/extension/android
4750

extension/android/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,14 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
8080
target_link_libraries(executorch_llama_jni ${link_libraries} llama_runner
8181
custom_ops cpublas eigen_blas)
8282
target_compile_options(executorch_llama_jni PUBLIC ${_common_compile_options})
83+
if(EXECUTORCH_USE_TIKTOKEN)
84+
set(ABSL_ENABLE_INSTALL ON)
85+
set(_pic_flag
86+
${CMAKE_POSITION_INDEPENDENT_CODE})
87+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
88+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../examples/models/llama2/third-party/abseil-cpp ${CMAKE_CURRENT_BINARY_DIR}/abseil-cpp)
89+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../examples/models/llama2/third-party/re2 ${CMAKE_CURRENT_BINARY_DIR}/re2)
90+
set(CMAKE_POSITION_INDEPENDENT_CODE ${_pic_flag})
91+
target_link_libraries(executorch_llama_jni re2::re2)
92+
endif()
8393
endif()

0 commit comments

Comments
 (0)