You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: mobile/examples/phi-3/android/README.md
+33-7Lines changed: 33 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,38 @@
1
-
# Local Chatbot on Android with Phi-3, ONNX Runtime Mobile and ONNX Runtime Generate() API
1
+
# Local Chatbot on Android with ONNX Runtime Mobile and ONNX Runtime Generate() API
2
2
3
3
## Overview
4
4
5
-
This is a basic [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct)Android example application with [ONNX Runtime mobile](https://onnxruntime.ai/docs/tutorials/mobile/) and [ONNX Runtime Generate() API](https://github.com/microsoft/onnxruntime-genai)with support for efficiently running generative AI models. This app demonstrates the usage of phi-3 model in a simple question answering chatbot mode.
5
+
This is a flexible Android chatbot application with [ONNX Runtime mobile](https://onnxruntime.ai/docs/tutorials/mobile/) and [ONNX Runtime Generate() API](https://github.com/microsoft/onnxruntime-genai)that supports efficiently running generative AI models. While it uses [Phi-3](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct) by default, **it can work with any ONNX Runtime GenAI compatible model** by simply updating the model configuration in the code.
6
6
7
7
### Model
8
-
The model used here is [ONNX Phi-3 model on HuggingFace](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4) with INT4 quantization and optimizations for mobile usage.
9
-
10
-
You can also optimize your fine-tuned PyTorch Phi-3 model for mobile usage following this example [Phi3 optimization with Olive](https://github.com/microsoft/Olive/tree/main/examples/phi3).
8
+
By default, this app uses the [ONNX Phi-3 model on HuggingFace](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4) with INT4 quantization and optimizations for mobile usage.
9
+
10
+
### Using Different Models
11
+
**The app is designed to work with any ONNX Runtime GenAI compatible model.** To use a different model:
12
+
13
+
1. Open `MainActivity.java` in Android Studio
14
+
2. Locate the model configuration section at the top of the class (marked with comments)
15
+
3. Update the `MODEL_BASE_URL` to point to your model's download location
16
+
4. Update the `MODEL_FILES` list to include all required files for your model
17
+
18
+
Example for a different model:
19
+
```java
20
+
// Base URL for downloading model files (ensure it ends with '/')
**Note:** The model files will be downloaded to `/data/data/ai.onnxruntime.genai.demo/files` on the Android device.
11
36
12
37
### Requirements
13
38
- Android Studio Giraffe | 2022.3.1 or later (installed on Mac/Windows/Linux)
@@ -30,7 +55,7 @@ The current set up supports downloading Phi-3-mini model directly from Huggingfa
30
55
You can also follow this link to download **Phi-3-mini**: https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4
31
56
and manually copy to the android device file directory following the below instructions:
32
57
33
-
#### Steps for manual copying models to android device directory:
58
+
#### Steps for manual copying model files to android device directory:
34
59
From Android Studio:
35
60
- create (if necessary) and run your emulator/device
36
61
- make sure it has at least 8GB of internal storage
@@ -40,7 +65,8 @@ From Android Studio:
40
65
- Open Device Explorer in Android Studio
41
66
- Navigate to `/data/data/ai.onnxruntime.genai.demo/files`
42
67
- adjust as needed if the value returned by getFilesDir() differs for your emulator or device
43
-
- copy the whole [phi-3](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4) model folder to the `files` directory
68
+
- copy all the required model files (as specified in `MODEL_FILES` in MainActivity.java) directly to the `files` directory
69
+
- For the default Phi-3 model, copy files from [here](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct-onnx/tree/main/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4)
44
70
45
71
### Step 3: Connect Android Device and Run the app
46
72
Connect your Android Device to your computer or select the Android Emulator in Android Studio Device manager.
0 commit comments