Skip to content

Commit 1c098fb

Browse files
authored
Fix android instrumentation (#10125)
For CI, just run module test. LLM test won't work on emulator. OOM. Locally, use the instructions and it will work.
1 parent 72fefb5 commit 1c098fb

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

.github/workflows/_android.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ jobs:
131131
# https://github.com/ReactiveCircus/android-emulator-runner. The max number
132132
# of cores we can set is 6, any higher number will be reduced to 6.
133133
cores: 6
134-
ram-size: 12288M
134+
ram-size: 16384M
135+
heap-size: 12288M
135136
force-avd-creation: false
136137
disable-animations: true
137138
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none

extension/android/executorch_android/android_test_setup.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
1212
fi
1313
which "${PYTHON_EXECUTABLE}"
1414

15-
BASEDIR=$(dirname "$0")
15+
BASEDIR=$(dirname "$(realpath $0)")
1616
cp "${BASEDIR}/../../../extension/module/test/resources/add.pte" "${BASEDIR}/src/androidTest/resources"
1717

1818
pushd "${BASEDIR}/../../../"
19-
curl -Ls "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt" --output stories110M.pt
20-
curl -Ls "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model" --output tokenizer.model
19+
curl -C - -Ls "https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.pt" --output stories110M.pt
20+
curl -C - -Ls "https://raw.githubusercontent.com/karpathy/llama2.c/master/tokenizer.model" --output tokenizer.model
2121
# Create params.json file
2222
touch params.json
2323
echo '{"dim": 768, "multiple_of": 32, "n_heads": 12, "n_layers": 12, "norm_eps": 1e-05, "vocab_size": 32000}' > params.json
24-
python -m examples.models.llama.export_llama -c stories110M.pt -p params.json -X -kv --model=stories110m
24+
python -m examples.models.llama.export_llama -c stories110M.pt -p params.json -d fp16 -n stories110m_h.pte -kv
25+
python -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
2526

26-
cp *.pte "${BASEDIR}/src/androidTest/resources/stories.pte"
27-
cp tokenizer.model "${BASEDIR}/src/androidTest/resources/tokenizer.bin"
27+
cp stories110m_h.pte "${BASEDIR}/src/androidTest/resources/stories.pte"
28+
cp tokenizer.bin "${BASEDIR}/src/androidTest/resources/tokenizer.bin"
2829
popd

extension/android/executorch_android/src/androidTest/java/org/pytorch/executorch/LlmModuleInstrumentationTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ public void testGenerate() throws IOException, URISyntaxException{
8686

8787
@Test
8888
public void testGenerateAndStop() throws IOException, URISyntaxException{
89-
int seqLen = 32;
9089
mModule.generate(TEST_PROMPT, SEQ_LEN, new LlmCallback() {
9190
@Override
9291
public void onResult(String result) {

scripts/run_android_emulator.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,14 @@ $ADB_PATH wait-for-device shell 'while [[ -z $(getprop sys.boot_completed) ]]; d
1818
echo "List all running emulators"
1919
$ADB_PATH devices
2020

21-
adb uninstall com.example.executorchllamademo || true
22-
adb uninstall com.example.executorchllamademo.test || true
23-
adb install -t app-debug.apk
24-
adb install -t app-debug-androidTest.apk
25-
26-
adb shell mkdir -p /data/local/tmp/llama
27-
adb push model.pte /data/local/tmp/llama
28-
adb push tokenizer.bin /data/local/tmp/llama
29-
adb shell am instrument -w -r com.example.executorchllamademo.test/androidx.test.runner.AndroidJUnitRunner
30-
3121
adb uninstall org.pytorch.executorch.test || true
3222
adb install -t android-test-debug-androidTest.apk
3323

34-
adb shell am instrument -w -r org.pytorch.executorch.test/androidx.test.runner.AndroidJUnitRunner
24+
adb logcat -c
25+
adb shell am instrument -w -r -e class org.pytorch.executorch.ModuleInstrumentationTest \
26+
org.pytorch.executorch.test/androidx.test.runner.AndroidJUnitRunner >result.txt 2>&1
27+
adb logcat -d > logcat.txt
28+
cat logcat.txt
29+
grep -q FAILURES result.txt && cat result.txt
30+
grep -q FAILURES result.txt && exit -1
31+
exit 0

0 commit comments

Comments
 (0)