Skip to content

Commit 7c45d62

Browse files
committed
Use polling to wait for the benchmark results (for now)
1 parent f857d95 commit 7c45d62

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

examples/demo-apps/android/LlamaDemo/android-llm-device-farm-test-spec.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,29 @@ phases:
7373
fi
7474
fi;
7575
76-
# Run the new generic benchmark activity
76+
# Run the new generic benchmark activity https://developer.android.com/tools/adb#am
7777
- echo "Run LLM benchmark"
7878
- |
79-
adb -s $DEVICEFARM_DEVICE_UDID shell am start -n com.example.executorchllamademo/.LlmBenchmarkRunner \
79+
adb -s $DEVICEFARM_DEVICE_UDID shell am start -W -n com.example.executorchllamademo/.LlmBenchmarkRunner \
8080
--es "model_dir" "/data/local/tmp/llama" \
8181
--es "tokenizer_path" "/data/local/tmp/llama/tokenizer.bin"
8282
8383
post_test:
8484
commands:
85-
- adb -s $DEVICEFARM_DEVICE_UDID shell "ls -la /data/local/tmp/llama/"
85+
- echo "Wait for the results"
86+
- |
87+
# TODO (huydhn): Polling like this looks brittle, figure out if there is a better way to wait
88+
# for the benchmark results
89+
adb -s $DEVICEFARM_DEVICE_UDID shell run-as com.example.executorchllamademo \
90+
while ! test -f files/benchmark_results.json; do echo "Waiting for benchmark results..."; sleep 30; done
91+
92+
adb -s $DEVICEFARM_DEVICE_UDID shell run-as com.example.executorchllamademo ls -la files/
93+
94+
- echo "Gather LLM benchmark results"
95+
- |
96+
APP_DIR=$(adb -s $DEVICEFARM_DEVICE_UDID shell run-as com.example.executorchllamademo pwd)
97+
adb -s $DEVICEFARM_DEVICE_UDID pull "${APP_DIR}"/files/benchmark_results.json $DEVICEFARM_LOG_DIR/
98+
8699
87100
artifacts:
88101
# By default, Device Farm will collect your artifacts from the $DEVICEFARM_LOG_DIR directory.

examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/LlmBenchmarkRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public void onGenerationStopped() {
9898

9999
// TODO (huydhn): Figure out on what the final JSON results looks like, we need something
100100
// with the same number of fields as https://github.com/pytorch/pytorch/pull/135042
101-
try (FileWriter writer = new FileWriter(modelDir.getPath() + "/benchmark_results.json")) {
101+
try (FileWriter writer = new FileWriter(getFilesDir() + "/benchmark_results.json")) {
102102
Gson gson = new Gson();
103103
writer.write(gson.toJson(mStatsDump));
104104
} catch (IOException e) {

0 commit comments

Comments
 (0)