Skip to content

Commit 86c84ff

Browse files
committed
Log prompt processing time and add screenshot
1 parent d276879 commit 86c84ff

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

mobile/examples/phi-3/android/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ Here are some sample example screenshots of the app.
5858

5959
<img width=20% src="images/Local_LLM_3.jpg" alt="App Screenshot 3" />
6060

61+
<img width=20% src="images/Local_LLM_4.png" alt="App Screenshot 3" />

mobile/examples/phi-3/android/app/src/main/java/ai/onnxruntime/genai/demo/MainActivity.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ public void run() {
148148

149149
// try to measure average time taken to generate each token.
150150
long startTime = System.currentTimeMillis();
151+
long firstTokenTime = startTime;
151152
long currentTime = startTime;
152153
int numTokens = 0;
153154
while (!generator.isDone()) {
@@ -158,14 +159,18 @@ public void run() {
158159

159160
tokenListener.accept(stream.decode(token));
160161

162+
if (numTokens == 0) { //first token
163+
firstTokenTime = System.currentTimeMillis();
164+
}
161165
Log.i(TAG, "Generated token: " + token + ": " + stream.decode(token));
162166
Log.i(TAG, "Time taken to generate token: " + (System.currentTimeMillis() - currentTime)/ 1000.0 + " seconds");
163167
currentTime = System.currentTimeMillis();
164168
numTokens++;
165169
}
166-
long totalTime = System.currentTimeMillis() - startTime;
167-
Log.i(TAG, "Total time taken to generate + " + numTokens + "tokens: " + totalTime);
168-
Log.i(TAG, "Tokens generated per second: " + 1000 * (numTokens / totalTime));
170+
long totalTime = System.currentTimeMillis() - firstTokenTime;
171+
172+
Log.i(TAG, "Prompt processing time (first token): " + (firstTokenTime - startTime)/ 1000.0 + " seconds");
173+
Log.i(TAG, "Tokens generated per second (excluding prompt processing): " + 1000 * ((numTokens -1) / totalTime));
169174
}
170175
catch (GenAIException e) {
171176
Log.e(TAG, "Exception occurred during model query: " + e.getMessage());

mobile/examples/phi-3/android/app/src/main/res/layout/bottom_sheet.xml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
34
android:layout_width="match_parent"
45
android:layout_height="wrap_content"
56
android:orientation="vertical"
@@ -47,9 +48,14 @@
4748
android:id="@+id/applySettingsButton"
4849
android:layout_width="wrap_content"
4950
android:layout_height="wrap_content"
50-
android:text="Apply"
51-
android:textColor="@android:color/white"
52-
android:padding="8dp"
5351
android:layout_gravity="center_horizontal"
54-
android:layout_marginTop="24dp"/>
52+
android:layout_marginTop="24dp"
53+
android:background="#89CC04"
54+
android:backgroundTint="#89CC04"
55+
android:tint="@color/white"
56+
android:padding="8dp"
57+
android:text="Apply"
58+
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
59+
android:visibility="visible"
60+
tools:visibility="visible" />
5561
</LinearLayout>
43.7 KB
Loading

0 commit comments

Comments
 (0)