Skip to content

Commit edef966

Browse files
authored
Polish LlamaDemo README documentation (#128)
1 parent 81f47bc commit edef966

5 files changed

Lines changed: 91 additions & 91 deletions

File tree

llm/android/LlamaDemo/README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,15 @@ mModule = new LlmModule(
103103
int loadResult = mModule.load();
104104
```
105105

106-
* `modelCategory`: Indicate whether it’s a text-only or vision model
107-
* `modePath`: path to the .pte file
108-
* `tokenizerPath`: path to the tokenizer file
109-
* `temperature`: model parameter to adjust the randomness of the model’s output
110-
* `dataPath`: path to one or a list of .ptd files
106+
* `modelCategory`: Indicates whether it’s a text-only or vision model
107+
* `modelPath`: Path to the .pte file
108+
* `tokenizerPath`: Path to the tokenizer file
109+
* `temperature`: Model parameter to adjust the randomness of the model’s output
110+
* `dataPath`: Path to one or a list of .ptd files
111111

112112

113113
### User Prompt
114-
Once model is successfully loaded then enter any prompt and click the send (i.e. generate) button to send it to the model.
114+
Once the model is successfully loaded, enter any prompt and click the send (i.e., generate) button to send it to the model.
115115
<p align="center">
116116
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/load_complete_and_start_prompt.png" style="width:300px">
117117
</p>
@@ -124,11 +124,11 @@ You can provide it more follow-up questions as well.
124124
#### ExecuTorch App API
125125

126126
```java
127-
mModule.generate(prompt,sequence_length, MainActivity.this);
127+
mModule.generate(prompt, sequence_length, MainActivity.this);
128128
```
129-
* `prompt`: User formatted prompt
129+
* `prompt`: User-formatted prompt
130130
* `sequence_length`: Number of tokens to generate in response to a prompt
131-
* `MainActivity.this`: Indicate that the callback functions (OnResult(), OnStats()) are present in this class.
131+
* `MainActivity.this`: Indicates that the callback functions (`onResult()`, `onStats()`) are present in this class.
132132

133133
[*LLaVA-1.5: Only for XNNPACK delegate*]
134134

@@ -189,7 +189,7 @@ Ensure you have the following functions in your callback class that you provided
189189
```
190190

191191
## Instrumentation Test
192-
You can run the instrumentation test for sanity check. The test loads a model pte file and tokenizer.bin file
192+
You can run the instrumentation test for a sanity check. The test loads a model .pte file and tokenizer.bin file
193193
under `/data/local/tmp/llama`.
194194

195195
### Model preparation
@@ -216,4 +216,4 @@ adb push tokenizer.bin /data/local/tmp/llama
216216
```
217217

218218
## Reporting Issues
219-
If you encountered any bugs or issues following this tutorial please file a bug/issue here on [Github](https://github.com/pytorch/executorch/issues/new), or join our discord [here](https://lnkd.in/gWCM4ViK).
219+
If you encountered any bugs or issues following this tutorial, please file a bug/issue here on [GitHub](https://github.com/pytorch/executorch/issues/new), or join our Discord [here](https://lnkd.in/gWCM4ViK).

llm/android/LlamaDemo/SDK-quick-setup-guide.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Guide to set up Java/SDK/NDK for Android
1+
# Guide to Set Up Java/SDK/NDK for Android
22

3-
Follow this doc if you haven't set up Java/SDK/NDK for Android development
3+
Follow this guide if you haven't set up Java/SDK/NDK for Android development
44
already.
5-
This doc provides a CLI tutorial to set them up. Otherwise, you can do the same
6-
thing with Android Studio GUI.
5+
This guide provides a CLI tutorial to set them up. Alternatively, you can do the same
6+
thing with the Android Studio GUI.
77

8-
## Set up Java 17
9-
1. Download the archive from Oracle website.
8+
## Set Up Java 17
9+
1. Download the archive from the Oracle website.
1010
Make sure you have read and agree with the terms and conditions from the website before downloading.
1111
```bash
1212
export DEV_HOME=<path-to-dev>
@@ -40,14 +40,14 @@ export PATH="$JAVA_HOME/bin:$PATH"
4040
Note: Oracle has tutorials for installing Java on
4141
[Linux](https://docs.oracle.com/en/java/javase/17/install/installation-jdk-linux-platforms.html#GUID-4A6BD592-1840-4BB4-A758-4CD49E9EE88B)
4242
and [macOS](https://docs.oracle.com/en/java/javase/17/install/installation-jdk-macos.html#GUID-E8A251B6-D9A9-4276-ABC8-CC0DAD62EA33).
43-
Some Linux distributions has JDK package in package manager. For example, Debian users can install
44-
openjdk-17-jdk package.
43+
Some Linux distributions have a JDK package in the package manager. For example, Debian users can install
44+
the openjdk-17-jdk package.
4545

46-
## Set up Android SDK/NDK
47-
Android has a command line tool [sdkmanager](https://developer.android.com/tools/sdkmanager) which
48-
helps users managing SDK and other tools related to Android development.
46+
## Set Up Android SDK/NDK
47+
Android has a command-line tool [sdkmanager](https://developer.android.com/tools/sdkmanager) which
48+
helps users manage SDK and other tools related to Android development.
4949

50-
1. Go to https://developer.android.com/studio and download the archive from "Command line tools
50+
1. Go to https://developer.android.com/studio and download the archive from the "Command line tools
5151
only" section. Make sure you have read and agree with the terms and conditions from the website.
5252

5353
Linux:
@@ -58,7 +58,7 @@ macOS:
5858
```bash
5959
curl https://dl.google.com/android/repository/commandlinetools-mac-11076708_latest.zip -o commandlinetools.zip
6060
```
61-
2. Unzip.
61+
2. Unzip:
6262
```bash
6363
unzip commandlinetools.zip
6464
```
@@ -80,7 +80,7 @@ If you want to use Android Studio and never set up Java/SDK/NDK before, or if
8080
you use the newly installed ones, follow these steps to set Android Studio to use
8181
them.
8282

83-
Copy these output paths to be used by Android Studio
83+
Copy these output paths to be used by Android Studio:
8484
```bash
8585
echo $ANDROID_HOME
8686
echo $ANDROID_NDK

llm/android/LlamaDemo/docs/delegates/mediatek_README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
# Building ExecuTorch Android Demo for Llama running MediaTek
2-
This tutorial covers the end to end workflow for running Llama 3-8B-instruct inference on MediaTek AI accelerators on an Android device.
1+
# Building ExecuTorch Android Demo for Llama Running MediaTek
2+
This tutorial covers the end-to-end workflow for running Llama 3-8B-instruct inference on MediaTek AI accelerators on an Android device.
33
More specifically, it covers:
44
1. Export and quantization of Llama models against the MediaTek backend.
5-
2. Building and linking libraries that are required to inference on-device for Android platform using MediaTek AI accelerators.
5+
2. Building and linking libraries that are required for on-device inference on the Android platform using MediaTek AI accelerators.
66
3. Loading the needed model files on the device and using the Android demo app to run inference.
77

8-
Verified on MacOS, Linux CentOS (model export), Python 3.10, Android NDK 26.3.11579264
9-
Phone verified: MediaTek Dimensity 9300 (D9300) chip.
8+
Verified on macOS, Linux CentOS (model export), Python 3.10, Android NDK 26.3.11579264.
9+
Phones verified: MediaTek Dimensity 9300 (D9300) chip.
1010

1111
## Prerequisites
1212
* Download and link the Android NDK, and MediaTek ExecuTorch Libraries from the MediaTek Backend Readme ([link](https://github.com/pytorch/executorch/tree/main/backends/mediatek/scripts#prerequisites)).
1313
* MediaTek Dimensity 9300 (D9300) chip device
14-
* Desired Llama 3 model weights. You can download them on HuggingFace [Example](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct)).
14+
* Desired Llama 3 model weights. You can download them on Hugging Face ([Example](https://huggingface.co/meta-llama/Meta-Llama-3-8B-Instruct)).
1515
* Download NeuroPilot Express SDK from the [MediaTek NeuroPilot Portal](https://neuropilot.mediatek.com/resources/public/npexpress/en/docs/npexpress):
1616
- `libneuronusdk_adapter.mtk.so`: This universal SDK contains the implementation required for executing target-dependent code on the MediaTek chip.
1717
- `libneuron_buffer_allocator.so`: This utility library is designed for allocating DMA buffers necessary for model inference.
18-
- `mtk_converter-8.8.0.dev20240723+public.d1467db9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`: This library preprocess the model into a MediaTek representation.
18+
- `mtk_converter-8.8.0.dev20240723+public.d1467db9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`: This library preprocesses the model into a MediaTek representation.
1919
- `mtk_neuron-8.2.2-py3-none-linux_x86_64.whl`: This library converts the model to binaries.
2020

2121
## Setup ExecuTorch
2222
In this section, we will need to set up the ExecuTorch repo first with Conda environment management. Make sure you have Conda available in your system (or follow the instructions to install it [here](https://anaconda.org/anaconda/conda)). The commands below are running on Linux (CentOS).
2323

24-
Checkout ExecuTorch repo and sync submodules
24+
Checkout ExecuTorch repo and sync submodules:
2525

2626
```
2727
git clone -b viable/strict https://github.com/pytorch/executorch.git && cd executorch
@@ -39,7 +39,7 @@ Or a Conda environment:
3939
conda create -n et_xnnpack python=3.10.0 && conda activate et_xnnpack
4040
```
4141

42-
Install dependencies
42+
Install dependencies:
4343
```
4444
./install_executorch.sh
4545
```
@@ -68,11 +68,11 @@ pip3 install mtk_neuron-8.2.2-py3-none-linux_x86_64.whl
6868
pip3 install mtk_converter-8.8.0.dev20240723+public.d1467db9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
6969
```
7070

71-
This was tested with transformers version 4.40 and numpy version 1.23. If you do not have these version then, use the following commands:
71+
This was tested with transformers version 4.40 and numpy version 1.23. If you do not have these versions, use the following commands:
7272
```
7373
pip install transformers==4.40
7474
75-
pip install numpy=1.23
75+
pip install numpy==1.23
7676
```
7777

7878
### Running Export
@@ -85,20 +85,20 @@ cd examples/mediatek
8585
source shell_scripts/export_llama.sh llama3 "" "" "" alpaca.txt
8686
```
8787

88-
There will be 3 main set of files generated:
89-
* num_chunks*2 pte files: half are for prompt and the other half are for generation. Generation pte files are denoted by “1t” in the file name.
88+
There will be 3 main sets of files generated:
89+
* num_chunks*2 .pte files: half are for prompt and the other half are for generation. Generation .pte files are denoted by “1t” in the file name.
9090
* Token embedding bin file: located in the weights folder where `config.json` is placed (`examples/mediatek/modes/llm_models/weight/<model_name>/embedding_<model_name>_fp32.bin`)
9191
* Tokenizer file: `tokenizer.model` file
9292

93-
Note: Exporting model flow can take 2.5 hours (114GB RAM for num_chunks=4) to complete. (Results may vary depending on hardware)
93+
Note: The exporting model flow can take 2.5 hours (114GB RAM for num_chunks=4) to complete. Results may vary depending on hardware.
9494

95-
Before continuing forward, make sure to modify the tokenizer, token embedding, and model paths in the examples/mediatek/executor_runner/run_llama3_sample.sh.
95+
Before continuing forward, make sure to modify the tokenizer, token embedding, and model paths in the `examples/mediatek/executor_runner/run_llama3_sample.sh` file.
9696

9797
### Deploy
9898
First, make sure your Android phone’s chipset version is compatible with this demo (MediaTek Dimensity 9300 (D9300)) chip. Once you have the model, tokenizer, and runner generated ready, you can push them and the .so files to the device before we start running using the runner via shell.
9999

100100
```
101-
adb shell mkdir -p /data/local/tmp/et-mtk/ (or any other directory name)
101+
adb shell mkdir -p /data/local/tmp/et-mtk/ # or any other directory name
102102
adb push embedding_<model_name>_fp32.bin /data/local/tmp/et-mtk
103103
adb push tokenizer.model /data/local/tmp/et-mtk
104104
adb push <exported_prompt_model_0>.pte /data/local/tmp/et-mtk
@@ -113,13 +113,13 @@ adb push <exported_gen_model_n>.pte /data/local/tmp/et-mtk
113113

114114
## Populate Model Paths in Runner
115115

116-
The Mediatek runner (`examples/mediatek/executor_runner/mtk_llama_runner.cpp`) contains the logic for implementing the function calls that come from the Android app.
116+
The MediaTek runner (`examples/mediatek/executor_runner/mtk_llama_runner.cpp`) contains the logic for implementing the function calls that come from the Android app.
117117

118-
**Important!** Currently the model paths are set in the runner-level. Modify the values in `examples/mediatek/executor_runner/llama_runner/llm_helper/include/llama_runner_values.h` to set the model paths, tokenizer path, embedding file path, and other metadata.
118+
**Important!** Currently the model paths are set at the runner level. Modify the values in `examples/mediatek/executor_runner/llama_runner/llm_helper/include/llama_runner_values.h` to set the model paths, tokenizer path, embedding file path, and other metadata.
119119

120120

121121
## Build AAR Library
122-
1. Open a terminal window and navigate to the root directory of the executorch
122+
1. Open a terminal window and navigate to the root directory of the ExecuTorch:
123123
```sh
124124
cd $EXECUTORCH_ROOT
125125
```
@@ -142,14 +142,14 @@ export BUILD_AAR_DIR=aar-out
142142
sh scripts/build_android_library.sh
143143
```
144144

145-
5. Now go to demo app root (containing main README.md) and copy the AAR to the app:
145+
5. Now go to the demo app root (containing the main README.md) and copy the AAR to the app:
146146
```sh
147147
cd $DEMO_APP
148148
mkdir -p app/libs
149149
cp $EXECUTORCH_ROOT/aar-out/executorch.aar app/libs/executorch.aar
150150
```
151151

152-
If you were to unzip the .aar file or open it in Android Studio, verify it contains the following related to MediaTek backend:
152+
If you were to unzip the .aar file or open it in Android Studio, verify it contains the following files related to the MediaTek backend:
153153
* libneuron_buffer_allocator.so
154154
* libneuronusdk_adapter.mtk.so
155155
* libneuron_backend.so (generated during build)
@@ -160,14 +160,14 @@ If you were to unzip the .aar file or open it in Android Studio, verify it conta
160160
1. Open Android Studio and select “Open an existing Android Studio project” to open LlamaDemo.
161161
2. Run the app (^R). This builds and launches the app on the phone.
162162

163-
### Alternative 2: Command line
164-
Without Android Studio UI, we can run gradle directly to build the app. We need to set up the Android SDK path and invoke gradle.
163+
### Alternative 2: Command Line
164+
Without Android Studio UI, we can run Gradle directly to build the app. We need to set up the Android SDK path and invoke Gradle.
165165
```
166166
export ANDROID_HOME=<path_to_android_sdk_home>
167167
cd LlamaDemo
168168
./gradlew :app:installDebug
169169
```
170-
If the app successfully run on your device, you should see something like below:
170+
If the app successfully runs on your device, you should see something like the screenshot below:
171171

172172
<p align="center">
173173
<img src="https://raw.githubusercontent.com/pytorch/executorch/refs/heads/main/docs/source/_static/img/opening_the_app_details.png" style="width:800px">
@@ -179,4 +179,4 @@ Once you've loaded the app on the device:
179179
3. Click the "Load Model" button. This will load the models from the Runner
180180

181181
## Reporting Issues
182-
If you encountered any bugs or issues following this tutorial please file a bug/issue here on [Github](https://github.com/pytorch/executorch/issues/new).
182+
If you encountered any bugs or issues following this tutorial, please file a bug/issue here on [GitHub](https://github.com/pytorch/executorch/issues/new).

0 commit comments

Comments
 (0)