Skip to content

MTK Android Llama Runner #6208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 29, 2024
Merged

MTK Android Llama Runner #6208

merged 11 commits into from
Oct 29, 2024

Conversation

cmodi-meta
Copy link
Contributor

@cmodi-meta cmodi-meta commented Oct 15, 2024

Adding the new MediaTek Runner that will work with the Android Demo app.

Run script to generate aar like below:

export NEURON_BUFFER_ALLOCATOR_LIB=path_to_buffer_allocator/libneuron_buffer_allocator.so 
export NEURON_USDK_ADAPTER_LIB=path_to_usdk_adapter/libneuronusdk_adapter.mtk.so  
export ANDROID_ABIS=arm64-v8a
sh build/build_android_llm_demo.sh

.aar file will live in examples/demo-apps/android/Llamademo/app/libs as executorch-llama.aar

Note: The new runner (mtk_llama_runner.cpp) is a fork of the existing mtk_llama_executor_runner.cpp. If mtk_llama_executor_runner.cpp is modified then mtk_llama_runner.cpp will need to as well. Another alternative is to adopt the mtk_llama_runner.cpp and it's flow as primary.

Copy link

pytorch-bot bot commented Oct 15, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/6208

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 6db8726 with merge base 2c32bf3 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 15, 2024
@cmodi-meta
Copy link
Contributor Author

TODO: Name space changes (reflect latest on #5478)

@cmodi-meta
Copy link
Contributor Author

Also pointing to @kirklandsign on how he wants to handle the extension/android/CMakeLists.txt changes.

ref: https://github.com/pytorch/executorch/pull/5301/files#diff-6cfdc4894f08602902337ade7d271ab292754ef664107aa216ac6f30350c48d5

@@ -155,6 +155,26 @@ if(EXECUTORCH_BUILD_LLAMA_JNI)
${EXECUTORCH_ROOT}/examples/models/llama2/runner
${CMAKE_CURRENT_BINARY_DIR}/../../examples/models/llama2/runner
)

target_sources(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should protect this under a flag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligned with @kirklandsign that he will help make change to this as it is CMake

@@ -17,6 +17,7 @@

#include <executorch/examples/models/llama2/runner/runner.h>
#include <executorch/examples/models/llava/runner/llava_runner.h>
#include <executorch/examples/mediatek/executor_runner/mtk_llama_runner.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to put this under a preprocessor macro. We don't want to add MTK header library to our build always

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aligned with @kirklandsign that he will help make change to this as he would like to refactor jni a bit.

@cmodi-meta
Copy link
Contributor Author

TODO: Name space changes (reflect latest on #5478)

completed in commit 4e310cb in PR stack

@cmodi-meta
Copy link
Contributor Author

@kirklandsign as part of the build scripts and jni changes you'll make. Just an fyi that there is an lintrunner error on the mixed upper and lower case:

    >>> 175  |  ADD_LIBRARY(libneuron_buffer_allocator SHARED IMPORTED)
    >>> 176  |  SET_PROPERTY(TARGET libneuron_buffer_allocator PROPERTY IMPORTED_LOCATION ${NEURON_BUFFER_ALLOCATOR_LIB})

@kirklandsign kirklandsign force-pushed the mtk-runner-landing branch 4 times, most recently from 82d4ff2 to 03c12c8 Compare October 18, 2024 23:29
const std::string TOKENIZER_PATH =
"/data/local/tmp/et-mtk/llama3/tokenizer.model";
const std::string TOKEN_EMBEDDING_PATH =
"/data/local/tmp/et-mtk/llama3/embedding_llama3-8B-instruct_fp32.bin";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix those

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for right now, tokenizer path, token embedding path and model paths will be hardcoded in aar. We will then make changes to see if we want to have a different flow.

@cccclai
Copy link
Contributor

cccclai commented Oct 21, 2024

@neuropilot-captain please take a look at the media llama runner change

@facebook-github-bot
Copy link
Contributor

@cmodi-meta has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@cccclai cccclai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accept the same reason as #6304, @neuropilot-captain please let us know if you have any concern

@@ -37,6 +37,7 @@ build_android_native_library() {
cmake . -DCMAKE_INSTALL_PREFIX="${CMAKE_OUT}" \
-DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \
-DANDROID_ABI="${ANDROID_ABI}" \
-DANDROID_PLATFORM=android-26 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we bump to more recent version?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that here 26 is needed? Thought 30 is stricter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

26 is needed here since otherwise I get errors in the build like attached
image

@cmodi-meta
Copy link
Contributor Author

rebase

@facebook-github-bot
Copy link
Contributor

@cmodi-meta has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

1 similar comment
@facebook-github-bot
Copy link
Contributor

@cmodi-meta has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot merged commit 47bca20 into main Oct 29, 2024
40 checks passed
@facebook-github-bot facebook-github-bot deleted the mtk-runner-landing branch October 29, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants