forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 1
144 lines (125 loc) · 5.97 KB
/
_android.yml
File metadata and controls
144 lines (125 loc) · 5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
name: Android
on:
workflow_call:
workflow_dispatch:
jobs:
build-llm-demo:
name: build-llm-demo
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
permissions:
id-token: write
contents: read
with:
runner: linux.2xlarge
docker-image: ci-image:executorch-ubuntu-22.04-clang12-android
submodules: 'recursive'
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
timeout: 90
upload-artifact: android-apps
upload-artifact-to-s3: true
script: |
set -eux
# Use sccache for NDK compiler as well
export CMAKE_CXX_COMPILER_LAUNCHER=sccache
export CMAKE_C_COMPILER_LAUNCHER=sccache
# The generic Linux job chooses to use base env, not the one setup by the image
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
conda activate "${CONDA_ENV}"
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool buck2
export ARTIFACTS_DIR_NAME=artifacts-to-be-uploaded
mkdir -p ${ARTIFACTS_DIR_NAME}/
# Build LLM Demo for Android
export BUILD_AAR_DIR=aar-out
mkdir -p $BUILD_AAR_DIR
bash scripts/build_android_library.sh
cp ${BUILD_AAR_DIR}/executorch.aar $ARTIFACTS_DIR_NAME
mkdir -p ${ARTIFACTS_DIR_NAME}/library_test_dir
bash extension/android/executorch_android/android_test_setup.sh
(cd extension/android; ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew :executorch_android:assembleAndroidTest)
cp extension/android/executorch_android/build/outputs/apk/androidTest/debug/executorch_android-debug-androidTest.apk "${ARTIFACTS_DIR_NAME}/library_test_dir"
mkdir -p ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
bash examples/models/llama/install_requirements.sh
bash ".ci/scripts/test_llama.sh" -model stories110M -build_tool cmake -dtype fp16 -mode portable -upload ${ARTIFACTS_DIR_NAME}/fp32-xnnpack-custom
mkdir -p examples/demo-apps/android/LlamaDemo/app/libs
cp aar-out/executorch.aar examples/demo-apps/android/LlamaDemo/app/libs
pushd examples/demo-apps/android/LlamaDemo
ANDROID_HOME="${ANDROID_SDK:-/opt/android/sdk}" ./gradlew build assembleAndroidTest
popd
DEMO_APP_DIR="${ARTIFACTS_DIR_NAME}/llm_demo"
# The app directory is named using its build flavor as a suffix.
mkdir -p "${DEMO_APP_DIR}"
# Collect the app and its test suite
cp examples/demo-apps/android/LlamaDemo/app/build/outputs/apk/debug/*.apk "${DEMO_APP_DIR}"
cp examples/demo-apps/android/LlamaDemo/app/build/outputs/apk/androidTest/debug/*.apk "${DEMO_APP_DIR}"
# Running Android emulator directly on the runner and not using Docker
run-emulator:
needs: build-llm-demo
# NB: Use metal install for KVM support to run the emulator faster
runs-on: linux.24xl.spr-metal
env:
ANDROID_NDK_VERSION: r27b
API_LEVEL: 34
steps:
- name: Setup SSH (Click me for login details)
uses: pytorch/test-infra/.github/actions/setup-ssh@main
with:
github-secret: ${{ secrets.GITHUB_TOKEN }}
instructions: |
This is used to run Android emulators, ANDROID_HOME is installed at /opt/android/sdk
- uses: actions/checkout@v3
with:
submodules: false
- name: Setup conda
uses: pytorch/test-infra/.github/actions/setup-miniconda@main
with:
python-version: '3.10'
- name: Install Android dependencies
shell: bash
run: |
set -eux
# Reuse the script that install Android on ET Docker image
sudo -E bash .ci/docker/common/install_android.sh
# After https://github.com/ReactiveCircus/android-emulator-runner/releases/tag/v2.33.0 release,
# it seems that we need to chown the Android setup to the current user instead of root to
# avoid permission issue
sudo chown -R "${USER}" /opt/android
- name: Download Artifacts
shell: bash
run: |
set -eux
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug.apk
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/llm_demo/app-debug-androidTest.apk
curl -O https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/fp32-xnnpack-custom/model.zip
curl -o android-test-debug-androidTest.apk https://gha-artifacts.s3.amazonaws.com/${{ github.repository }}/${{ github.run_id }}/artifacts/library_test_dir/executorch_android-debug-androidTest.apk
unzip model.zip
mv *.pte model.pte
- name: Gradle cache
uses: gradle/actions/setup-gradle@v3
- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ env.API_LEVEL }}
# NB: It takes about 10m to cold boot the emulator here
- name: Run Android emulator
env:
ANDROID_HOME: /opt/android/sdk
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ env.API_LEVEL }}
arch: x86_64
script: ./scripts/run_android_emulator.sh
# NB: This is to boot the emulator faster following the instructions on
# https://github.com/ReactiveCircus/android-emulator-runner. The max number
# of cores we can set is 6, any higher number will be reduced to 6.
cores: 6
ram-size: 16384M
heap-size: 12288M
force-avd-creation: false
disable-animations: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
# This is to make sure that the job doesn't fail flakily
emulator-boot-timeout: 900