diff --git a/.github/workflows/android-build.yml b/.github/workflows/android-build.yml index c6f77fd00c..e66a839a97 100644 --- a/.github/workflows/android-build.yml +++ b/.github/workflows/android-build.yml @@ -7,8 +7,6 @@ name: Android Build on: - pull_request: - branches: [main] schedule: # Run nightly at midnight UTC - cron: '0 0 * * *' @@ -69,71 +67,3 @@ jobs: name: ${{ matrix.name }}-apk path: ${{ matrix.path }}/app/build/outputs/apk/ if-no-files-found: warn - - instrumentation-test: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - include: - - name: LlamaDemo - path: llm/android/LlamaDemo - env: - API_LEVEL: 34 - ARCH: x86_64 - EMULATOR_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none - - name: Instrumentation Test ${{ matrix.name }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Enable KVM group perms - run: | - echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules - sudo udevadm control --reload-rules - sudo udevadm trigger --name-match=kvm - - - name: Set up JDK 17 - uses: actions/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - - name: AVD cache - uses: actions/cache@v4 - id: avd-cache - with: - path: | - ~/.android/avd/* - ~/.android/adb* - key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }} - - - name: Create AVD and generate snapshot for caching - if: steps.avd-cache.outputs.cache-hit != 'true' - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.API_LEVEL }} - arch: ${{ env.ARCH }} - force-avd-creation: false - ram-size: 16384M - emulator-options: ${{ env.EMULATOR_OPTIONS }} - disable-animations: false - working-directory: ${{ matrix.path }} - script: echo "Generated AVD snapshot for caching." - - - name: Run instrumentation tests - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ env.API_LEVEL }} - arch: ${{ env.ARCH }} - force-avd-creation: false - ram-size: 6144M - emulator-options: -no-snapshot-save ${{ env.EMULATOR_OPTIONS }} - disable-animations: true - working-directory: ${{ matrix.path }} - script: | - ./gradlew connectedCheck diff --git a/.github/workflows/llm-android.yml b/.github/workflows/llm-android.yml new file mode 100644 index 0000000000..2d0d7b6a96 --- /dev/null +++ b/.github/workflows/llm-android.yml @@ -0,0 +1,132 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +name: LlamaDemo Android + +on: + pull_request: + branches: [main] + paths: + - 'llm/android/**' + - '.github/workflows/llm-android.yml' + workflow_dispatch: + inputs: + local_aar: + description: 'URL to download a local AAR file. When set, the workflow will download the AAR and use it instead of the Maven dependency.' + required: false + type: string + +permissions: + contents: read + +jobs: + build: + runs-on: ubuntu-latest + name: Build LlamaDemo + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Download local AAR + if: ${{ inputs.local_aar }} + run: | + mkdir -p llm/android/LlamaDemo/app/libs + curl -fL -o llm/android/LlamaDemo/app/libs/executorch.aar "${{ inputs.local_aar }}" + + - name: Build with Gradle + working-directory: llm/android/LlamaDemo + run: | + if [ -n "${{ inputs.local_aar }}" ]; then + ./gradlew build --no-daemon -PuseLocalAar=true + else + ./gradlew build --no-daemon + fi + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: LlamaDemo-apk + path: llm/android/LlamaDemo/app/build/outputs/apk/ + if-no-files-found: warn + + instrumentation-test: + runs-on: linux.24xl.spr-metal + env: + API_LEVEL: 34 + ARCH: x86_64 + EMULATOR_OPTIONS: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none + MODEL_URL: https://huggingface.co/pytorch/Qwen3-4B-INT8-INT4/resolve/main/model.pte + TOKENIZER_URL: https://huggingface.co/pytorch/Qwen3-4B-INT8-INT4/resolve/main/tokenizer.json + + name: Instrumentation Test LlamaDemo + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Enable KVM group perms + run: | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules + sudo udevadm control --reload-rules + sudo udevadm trigger --name-match=kvm + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Download model and tokenizer + run: | + mkdir -p llm/android/LlamaDemo/app/src/androidTest/assets + curl -fL -o llm/android/LlamaDemo/app/src/androidTest/assets/model.pte "${{ env.MODEL_URL }}" + curl -fL -o llm/android/LlamaDemo/app/src/androidTest/assets/tokenizer.json "${{ env.TOKENIZER_URL }}" + + - name: AVD cache + uses: actions/cache@v4 + id: avd-cache + with: + path: | + ~/.android/avd/* + ~/.android/adb* + key: avd-${{ env.API_LEVEL }}-${{ env.ARCH }} + + - name: Create AVD and generate snapshot for caching + if: steps.avd-cache.outputs.cache-hit != 'true' + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.API_LEVEL }} + arch: ${{ env.ARCH }} + force-avd-creation: false + ram-size: 16384M + emulator-options: ${{ env.EMULATOR_OPTIONS }} + disable-animations: false + working-directory: llm/android/LlamaDemo + script: echo "Generated AVD snapshot for caching." + + - name: Run instrumentation tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ env.API_LEVEL }} + arch: ${{ env.ARCH }} + force-avd-creation: false + ram-size: 6144M + emulator-options: -no-snapshot-save ${{ env.EMULATOR_OPTIONS }} + disable-animations: true + working-directory: llm/android/LlamaDemo + script: | + ./gradlew connectedCheck