diff --git a/.ci/scripts/test_wheel_package_qnn.sh b/.ci/scripts/test_wheel_package_qnn.sh new file mode 100644 index 00000000000..3dab5072951 --- /dev/null +++ b/.ci/scripts/test_wheel_package_qnn.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -e # Exit on any error + +echo "=== Building Wheel Package ===" +python setup.py bdist_wheel + +# Find the wheel file +WHEEL_FILE=$(ls dist/*.whl | head -n 1) +echo "Found wheel: $WHEEL_FILE" + +echo "=== Checking for expected .so files ===" +SO_FILES=$(unzip -l "$WHEEL_FILE" | grep "\.so" | grep "qualcomm") + +# Check for the three expected .so files +if echo "$SO_FILES" | grep -q "executorch/backends/qualcomm/qnn_backend.cpython-310-x86_64-linux-gnu.so" && \ + echo "$SO_FILES" | grep -q "executorch/backends/qualcomm/python/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so" && \ + echo "$SO_FILES" | grep -q "executorch/backends/qualcomm/python/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so"; then + echo "All expected .so files found in wheel" +else + echo "ERROR: Missing expected .so files" + exit 1 +fi + +# Create a temporary directory for our test environment +TEMP_ENV_DIR=$(mktemp -d) +echo "Using temporary directory: $TEMP_ENV_DIR" + +echo "=== Creating and testing in conda environment ===" +conda create -y -p "$TEMP_ENV_DIR/env" python=3.10 +conda run -p "$TEMP_ENV_DIR/env" pip install "$WHEEL_FILE" + +echo "=== Testing import without SDK download ===" +conda run -p "$TEMP_ENV_DIR/env" python -c "import executorch; print('executorch imported successfully')" + +# Check that SDK directory doesn't exist after first import +SDK_PATH="$TEMP_ENV_DIR/env/lib/python3.10/site-packages/executorch/backends/qualcomm/sdk" +if [ -d "$SDK_PATH" ]; then + echo "ERROR: SDK directory exists after first import: $SDK_PATH" + exit 1 +else + echo "SDK directory correctly doesn't exist after first import" +fi + +echo "=== Testing import that should trigger SDK download ===" +conda run -p "$TEMP_ENV_DIR/env" python -c "import executorch.backends.qualcomm; print('executorch.backends.qualcomm imported successfully')" + +# Check that SDK directory exists after second import +if [ -d "$SDK_PATH" ]; then + echo "SDK directory correctly exists after second import: $SDK_PATH" +else + echo "ERROR: SDK directory doesn't exist after second import" + exit 1 +fi + +echo "=== Running model generation script ===" +conda run -p "$TEMP_ENV_DIR/env" python script.py + +# Check if linear.pte file was created +if [ -f "linear.pte" ]; then + echo "Model file linear.pte successfully created" +else + echo "ERROR: Model file linear.pte was not created" + exit 1 +fi + +echo "=== Cleaning up ===" +conda env remove -p "$TEMP_ENV_DIR/env" -y +rm -rf "$TEMP_ENV_DIR" + +echo "=== All tests passed! ===" diff --git a/.github/workflows/pull.yml b/.github/workflows/pull.yml index aa7be5dfb68..7206914afcb 100644 --- a/.github/workflows/pull.yml +++ b/.github/workflows/pull.yml @@ -13,8 +13,8 @@ concurrency: cancel-in-progress: true jobs: - test-setup-linux-gcc: - name: test-setup-linux-gcc + test-qnn-wheel-packages-linux: + name: test-qnn-wheel-packages-linux uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main permissions: id-token: write @@ -23,193 +23,214 @@ jobs: fail-fast: false with: runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-gcc9 + docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk submodules: 'recursive' ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 + timeout: 180 script: | # 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}" - BUILD_TOOL="cmake" + PYTHON_EXECUTABLE=python bash .ci/scripts/test_wheel_package_qnn.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Build and test ExecuTorch with the add model on portable backend. - PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "add" "${BUILD_TOOL}" "portable" + # test-setup-linux-gcc: + # name: test-setup-linux-gcc + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-gcc9 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - test-models-linux-basic: - name: test-models-linux-basic - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - model: [mv3, vit] - backend: [portable, xnnpack-quantization-delegation] - build-tool: [cmake, buck2] - runner: [linux.2xlarge, linux.arm64.2xlarge] - docker-image: [executorch-ubuntu-22.04-clang12, executorch-ubuntu-22.04-gcc11-aarch64] - # Excluding specific runner + docker image combinations that don't make sense: - # - Excluding the ARM64 gcc image on the x86 runner (linux.2xlarge) - # - Excluding the x86 clang image on the ARM64 runner (linux.arm64.2xlarge) - exclude: - - runner: linux.2xlarge - docker-image: executorch-ubuntu-22.04-gcc11-aarch64 - - runner: linux.arm64.2xlarge - docker-image: executorch-ubuntu-22.04-clang12 - # TODO: Need to figure out why buck2 doesnt work on Graviton instances. - - runner: linux.arm64.2xlarge - build-tool: buck2 - fail-fast: false - with: - runner: ${{ matrix.runner }} - docker-image: ci-image:${{ matrix.docker-image }} - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # BUILD_TOOL="cmake" - MODEL_NAME=${{ matrix.model }} - BUILD_TOOL=${{ matrix.build-tool }} - BACKEND=${{ matrix.backend }} + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Build and test ExecuTorch with the add model on portable backend. + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "add" "${BUILD_TOOL}" "portable" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Build and test ExecuTorch - PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" + # test-models-linux-basic: + # name: test-models-linux-basic + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # model: [mv3, vit] + # backend: [portable, xnnpack-quantization-delegation] + # build-tool: [cmake, buck2] + # runner: [linux.2xlarge, linux.arm64.2xlarge] + # docker-image: [executorch-ubuntu-22.04-clang12, executorch-ubuntu-22.04-gcc11-aarch64] + # # Excluding specific runner + docker image combinations that don't make sense: + # # - Excluding the ARM64 gcc image on the x86 runner (linux.2xlarge) + # # - Excluding the x86 clang image on the ARM64 runner (linux.arm64.2xlarge) + # exclude: + # - runner: linux.2xlarge + # docker-image: executorch-ubuntu-22.04-gcc11-aarch64 + # - runner: linux.arm64.2xlarge + # docker-image: executorch-ubuntu-22.04-clang12 + # # TODO: Need to figure out why buck2 doesnt work on Graviton instances. + # - runner: linux.arm64.2xlarge + # build-tool: buck2 + # fail-fast: false + # with: + # runner: ${{ matrix.runner }} + # docker-image: ci-image:${{ matrix.docker-image }} + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - test-models-linux: - name: test-models-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - model: [linear, add, add_mul, ic3, mv2, resnet18, resnet50, mobilebert, emformer_transcribe] - backend: [portable, xnnpack-quantization-delegation] - runner: [linux.2xlarge] - include: - - model: ic4 - backend: portable - runner: linux.4xlarge.memory - - model: ic4 - backend: xnnpack-quantization-delegation - runner: linux.4xlarge.memory - - model: emformer_join - backend: portable - runner: linux.4xlarge.memory - - model: emformer_join - backend: xnnpack-quantization-delegation - runner: linux.4xlarge.memory - - model: phi_4_mini - backend: portable - runner: linux.4xlarge.memory - - model: llama3_2_vision_encoder - backend: portable - runner: linux.4xlarge.memory - - model: w2l - backend: portable - runner: linux.4xlarge.memory - fail-fast: false - with: - runner: ${{ matrix.runner }} - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # MODEL_NAME=${{ matrix.model }} + # BUILD_TOOL=${{ matrix.build-tool }} + # BACKEND=${{ matrix.backend }} - MODEL_NAME=${{ matrix.model }} - BUILD_TOOL=cmake - BACKEND=${{ matrix.backend }} + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Build and test ExecuTorch + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Build and test ExecuTorch - PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" + # test-models-linux: + # name: test-models-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # model: [linear, add, add_mul, ic3, mv2, resnet18, resnet50, mobilebert, emformer_transcribe] + # backend: [portable, xnnpack-quantization-delegation] + # runner: [linux.2xlarge] + # include: + # - model: ic4 + # backend: portable + # runner: linux.4xlarge.memory + # - model: ic4 + # backend: xnnpack-quantization-delegation + # runner: linux.4xlarge.memory + # - model: emformer_join + # backend: portable + # runner: linux.4xlarge.memory + # - model: emformer_join + # backend: xnnpack-quantization-delegation + # runner: linux.4xlarge.memory + # - model: phi_4_mini + # backend: portable + # runner: linux.4xlarge.memory + # - model: llama3_2_vision_encoder + # backend: portable + # runner: linux.4xlarge.memory + # - model: w2l + # backend: portable + # runner: linux.4xlarge.memory + # fail-fast: false + # with: + # runner: ${{ matrix.runner }} + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - test-llama-runner-linux: - # Test Both linux x86 and linux aarch64 - name: test-llama-runner-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - dtype: [fp32] - mode: [xnnpack+custom+qe,xnnpack+custom+quantize_kv,xnnpack+quantize_kv] - runner: [linux.2xlarge, linux.arm64.2xlarge] - docker-image: [executorch-ubuntu-22.04-clang12, executorch-ubuntu-22.04-gcc11-aarch64] - include: - - dtype: bf16 - mode: custom - runner: linux.2xlarge - docker-image: executorch-ubuntu-22.04-clang12 - # Excluding specific runner + docker image combinations that don't make sense: - # - Excluding the ARM64 gcc image on the x86 runner (linux.2xlarge) - # - Excluding the x86 clang image on the ARM64 runner (linux.arm64.2xlarge) - exclude: - - runner: linux.2xlarge - docker-image: executorch-ubuntu-22.04-gcc11-aarch64 - - runner: linux.arm64.2xlarge - docker-image: executorch-ubuntu-22.04-clang12 - fail-fast: false - with: - runner: ${{ matrix.runner }} - docker-image: ci-image:${{ matrix.docker-image }} - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 900 - script: | - # 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}" + # MODEL_NAME=${{ matrix.model }} + # BUILD_TOOL=cmake + # BACKEND=${{ matrix.backend }} - DTYPE=${{ matrix.dtype }} - BUILD_TOOL="cmake" - MODE=${{ matrix.mode }} - ARTIFACTS_DIR_NAME="artifacts-to-be-uploaded/${DTYPE}-${MODE}" - ARTIFACTS_DIR_NAME="${ARTIFACTS_DIR_NAME/+/-}" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Build and test ExecuTorch + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "${MODEL_NAME}" "${BUILD_TOOL}" "${BACKEND}" - # Setup executorch - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Install requirements for export_llama - PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh - # Test llama2 - PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -dtype "${DTYPE}" -mode "${MODE}" -upload "${ARTIFACTS_DIR_NAME}" + # test-llama-runner-linux: + # # Test Both linux x86 and linux aarch64 + # name: test-llama-runner-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # dtype: [fp32] + # mode: [xnnpack+custom+qe,xnnpack+custom+quantize_kv,xnnpack+quantize_kv] + # runner: [linux.2xlarge, linux.arm64.2xlarge] + # docker-image: [executorch-ubuntu-22.04-clang12, executorch-ubuntu-22.04-gcc11-aarch64] + # include: + # - dtype: bf16 + # mode: custom + # runner: linux.2xlarge + # docker-image: executorch-ubuntu-22.04-clang12 + # # Excluding specific runner + docker image combinations that don't make sense: + # # - Excluding the ARM64 gcc image on the x86 runner (linux.2xlarge) + # # - Excluding the x86 clang image on the ARM64 runner (linux.arm64.2xlarge) + # exclude: + # - runner: linux.2xlarge + # docker-image: executorch-ubuntu-22.04-gcc11-aarch64 + # - runner: linux.arm64.2xlarge + # docker-image: executorch-ubuntu-22.04-clang12 + # fail-fast: false + # with: + # runner: ${{ matrix.runner }} + # docker-image: ci-image:${{ matrix.docker-image }} + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 900 + # script: | + # # 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}" - test-llama-runner-linux-android: - name: test-llama-runner-linux-android - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - 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 - script: | - # 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}" + # DTYPE=${{ matrix.dtype }} + # BUILD_TOOL="cmake" + # MODE=${{ matrix.mode }} + # ARTIFACTS_DIR_NAME="artifacts-to-be-uploaded/${DTYPE}-${MODE}" + # ARTIFACTS_DIR_NAME="${ARTIFACTS_DIR_NAME/+/-}" + + # # Setup executorch + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Install requirements for export_llama + # PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh + # # Test llama2 + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -dtype "${DTYPE}" -mode "${MODE}" -upload "${ARTIFACTS_DIR_NAME}" + + # test-llama-runner-linux-android: + # name: test-llama-runner-linux-android + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # 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 + # script: | + # # 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}" - source .ci/scripts/utils.sh - install_executorch "--use-pt-pinned-commit" - BUILD_TOOL="cmake" - PYTHON_EXECUTABLE=python \ - bash .ci/scripts/build_llama_android.sh "${BUILD_TOOL}" + # source .ci/scripts/utils.sh + # install_executorch "--use-pt-pinned-commit" + # BUILD_TOOL="cmake" + # PYTHON_EXECUTABLE=python \ + # bash .ci/scripts/build_llama_android.sh "${BUILD_TOOL}" test-custom-ops-linux: name: test-custom-ops-linux @@ -235,406 +256,460 @@ jobs: # Test custom ops PYTHON_EXECUTABLE=python bash examples/portable/custom_ops/test_custom_ops.sh "${BUILD_TOOL}" - test-selective-build-linux: - name: test-selective-build-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" - - BUILD_TOOL="cmake" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Test selective build - PYTHON_EXECUTABLE=python bash examples/selective_build/test_selective_build.sh "${BUILD_TOOL}" - - test-llava-runner-linux: - name: test-llava-runner-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-selective-build-linux: + # name: test-selective-build-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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 "cmake" + # BUILD_TOOL="cmake" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Test selective build + # PYTHON_EXECUTABLE=python bash examples/selective_build/test_selective_build.sh "${BUILD_TOOL}" - # install Llava requirements - bash examples/models/llama/install_requirements.sh - bash examples/models/llava/install_requirements.sh + # test-llava-runner-linux: + # name: test-llava-runner-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - # run python unittest - python -m unittest examples.models.llava.test.test_llava + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" - # run e2e (export, tokenizer and runner) - PYTHON_EXECUTABLE=python bash .ci/scripts/test_llava.sh + # # install Llava requirements + # bash examples/models/llama/install_requirements.sh + # bash examples/models/llava/install_requirements.sh - test-moshi-linux: - name: test-moshi-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # # run python unittest + # python -m unittest examples.models.llava.test.test_llava - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" + # # run e2e (export, tokenizer and runner) + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_llava.sh - # install Mimi requirements - bash examples/models/moshi/mimi/install_requirements.sh + # test-moshi-linux: + # name: test-moshi-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - # reinstall executorch - bash ./install_executorch.sh --minimal + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" - # run python unittest - python -m unittest examples.models.moshi.mimi.test_mimi + # # install Mimi requirements + # bash examples/models/moshi/mimi/install_requirements.sh - test-quantized-aot-lib-linux: - name: test-quantized-aot-lib-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # # reinstall executorch + # bash ./install_executorch.sh --minimal - BUILD_TOOL="cmake" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - PYTHON_EXECUTABLE=python bash examples/xnnpack/quantization/test_quantize.sh "${BUILD_TOOL}" mv2 + # # run python unittest + # python -m unittest examples.models.moshi.mimi.test_mimi - test-binary-size-linux-gcc: - name: test-binary-size-linux-gcc - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-gcc9 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-quantized-aot-lib-linux: + # name: test-quantized-aot-lib-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - ./install_requirements.sh --use-pt-pinned-commit - # build module for executorch.extension.pybindings.portable_lib - bash test/build_size_test.sh - strip cmake-out/test/size_test - output=$(ls -la cmake-out/test/size_test) - arr=($output) - size=${arr[4]} - # threshold=48120 on devserver with gcc11.4 - # todo(lfq): update once binary size is below 50kb. - threshold="63776" - if [[ "$size" -le "$threshold" ]]; then - echo "Success $size <= $threshold" - else - echo "Fail $size > $threshold" - exit 1 - fi - - test-binary-size-linux: - name: test-binary-size-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # BUILD_TOOL="cmake" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # PYTHON_EXECUTABLE=python bash examples/xnnpack/quantization/test_quantize.sh "${BUILD_TOOL}" mv2 - ./install_requirements.sh --use-pt-pinned-commit - - # build module for executorch.extension.pybindings.portable_lib - bash test/build_size_test.sh - strip cmake-out/test/size_test - output=$(ls -la cmake-out/test/size_test) - arr=($output) - size=${arr[4]} - threshold="51752" - if [[ "$size" -le "$threshold" ]]; then - echo "Success $size <= $threshold" - else - echo "Fail $size > $threshold" - exit 1 - fi - - android: - uses: ./.github/workflows/_android.yml - permissions: - id-token: write - contents: read + # test-binary-size-linux-gcc: + # name: test-binary-size-linux-gcc + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-gcc9 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - unittest: - uses: ./.github/workflows/_unittest.yml - permissions: - id-token: write - contents: read - with: - build-mode: Debug - build-tool: cmake - docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # ./install_requirements.sh --use-pt-pinned-commit + # # build module for executorch.extension.pybindings.portable_lib + # bash test/build_size_test.sh + # strip cmake-out/test/size_test + # output=$(ls -la cmake-out/test/size_test) + # arr=($output) + # size=${arr[4]} + # # threshold=48120 on devserver with gcc11.4 + # # todo(lfq): update once binary size is below 50kb. + # threshold="63776" + # if [[ "$size" -le "$threshold" ]]; then + # echo "Success $size <= $threshold" + # else + # echo "Fail $size > $threshold" + # exit 1 + # fi + + # test-binary-size-linux: + # name: test-binary-size-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - unittest-editable: - uses: ./.github/workflows/_unittest.yml - permissions: - id-token: write - contents: read - with: - build-mode: Debug - build-tool: cmake - editable: true - docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # ./install_requirements.sh --use-pt-pinned-commit + + # # build module for executorch.extension.pybindings.portable_lib + # bash test/build_size_test.sh + # strip cmake-out/test/size_test + # output=$(ls -la cmake-out/test/size_test) + # arr=($output) + # size=${arr[4]} + # threshold="51752" + # if [[ "$size" -le "$threshold" ]]; then + # echo "Success $size <= $threshold" + # else + # echo "Fail $size > $threshold" + # exit 1 + # fi + + # android: + # uses: ./.github/workflows/_android.yml + # permissions: + # id-token: write + # contents: read - unittest-buck: - uses: ./.github/workflows/_unittest.yml - permissions: - id-token: write - contents: read - with: - build-mode: Debug - build-tool: buck2 - docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # unittest: + # uses: ./.github/workflows/_unittest.yml + # permissions: + # id-token: write + # contents: read + # with: + # build-mode: Debug + # build-tool: cmake + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 - unittest-arm-backend-with-no-fvp: - name: unittest-arm-backend-with-no-fvp - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - include: - - test_arm_baremetal: test_pytest_ops - - test_arm_baremetal: test_pytest_models - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-arm-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # unittest-editable: + # uses: ./.github/workflows/_unittest.yml + # permissions: + # id-token: write + # contents: read + # with: + # build-mode: Debug + # build-tool: cmake + # editable: true + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 - source .ci/scripts/utils.sh - install_executorch "--use-pt-pinned-commit" + # unittest-buck: + # uses: ./.github/workflows/_unittest.yml + # permissions: + # id-token: write + # contents: read + # with: + # build-mode: Debug + # build-tool: buck2 + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 - .ci/scripts/setup-arm-baremetal-tools.sh + # unittest-arm-backend-with-no-fvp: + # name: unittest-arm-backend-with-no-fvp + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # include: + # - test_arm_baremetal: test_pytest_ops + # - test_arm_baremetal: test_pytest_models + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-arm-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - ARM_TEST=${{ matrix.test_arm_baremetal }} + # source .ci/scripts/utils.sh + # install_executorch "--use-pt-pinned-commit" - # Test test_arm_baremetal.sh with test - backends/arm/test/test_arm_baremetal.sh "${ARM_TEST}" + # .ci/scripts/setup-arm-baremetal-tools.sh - test-llama-runner-qnn-linux: - name: test-llama-runner-qnn-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - dtype: [fp32] - pt2e_quantize: [qnn_16a16w, qnn_8a8w] - mode: [qnn] - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 900 - script: | - # 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}" + # ARM_TEST=${{ matrix.test_arm_baremetal }} - DTYPE=${{ matrix.dtype }} - BUILD_TOOL="cmake" - MODE=${{ matrix.mode }} - PT2E_QUANTIZE=${{ matrix.pt2e_quantize }} + # # Test test_arm_baremetal.sh with test + # backends/arm/test/test_arm_baremetal.sh "${ARM_TEST}" - ./install_requirements.sh --use-pt-pinned-commit - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh + # test-llama-runner-qnn-linux: + # name: test-llama-runner-qnn-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # dtype: [fp32] + # pt2e_quantize: [qnn_16a16w, qnn_8a8w] + # mode: [qnn] + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 900 + # script: | + # # 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}" - # Setup executorch - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Install requirements for export_llama - PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh - # Test llama2 - PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -mode "${MODE}" -dtype "${DTYPE}" -pt2e_quantize "${PT2E_QUANTIZE}" + # DTYPE=${{ matrix.dtype }} + # BUILD_TOOL="cmake" + # MODE=${{ matrix.mode }} + # PT2E_QUANTIZE=${{ matrix.pt2e_quantize }} - test-static-llama-qnn-linux: - name: test-static-llama-qnn-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 180 - script: | - # 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}" + # ./install_requirements.sh --use-pt-pinned-commit + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh - BUILD_TOOL="cmake" + # # Setup executorch + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # # Install requirements for export_llama + # PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh + # # Test llama2 + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -mode "${MODE}" -dtype "${DTYPE}" -pt2e_quantize "${PT2E_QUANTIZE}" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh + # test-static-llama-qnn-linux: + # name: test-static-llama-qnn-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 180 + # script: | + # # 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}" - # Setup executorch - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # BUILD_TOOL="cmake" - # Setup install_requirements for llama - PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh - # Test static llama weight sharing and accuracy - PYTHON_EXECUTABLE=python bash .ci/scripts/test_qnn_static_llama.sh + # # Setup executorch + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - test-qnn-models-linux: - name: test-qnn-models-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 180 - script: | - # 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}" + # # Setup install_requirements for llama + # PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh - # placeholder for running test_qnn_delegate.py, can use matrix such that we can trigger different jobs, refers to test-llama-runner-qnn-linux - # reminder: make sure each job runs fast + # # Test static llama weight sharing and accuracy + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_qnn_static_llama.sh - test-phi-3-mini-runner-linux: - name: test-phi-3-mini-runner-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-qnn-models-linux: + # name: test-qnn-models-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 180 + # script: | + # # 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 "cmake" + # # placeholder for running test_qnn_delegate.py, can use matrix such that we can trigger different jobs, refers to test-llama-runner-qnn-linux + # # reminder: make sure each job runs fast - # install phi-3-mini requirements - bash examples/models/phi-3-mini/install_requirements.sh + # test-phi-3-mini-runner-linux: + # name: test-phi-3-mini-runner-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - # run e2e (export, tokenizer and runner) - PYTHON_EXECUTABLE=python bash .ci/scripts/test_phi_3_mini.sh Release + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" - test-eval_llama-wikitext-linux: - name: test-eval_llama-wikitext-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # # install phi-3-mini requirements + # bash examples/models/phi-3-mini/install_requirements.sh + + # # run e2e (export, tokenizer and runner) + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_phi_3_mini.sh Release + + # test-eval_llama-wikitext-linux: + # name: test-eval_llama-wikitext-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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 "cmake" + + # # install llama requirements + # bash examples/models/llama/install_requirements.sh + + # # run eval_llama wikitext task + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_eval_llama_wikitext.sh + + # TODO(larryliu0820): Fix this issue before reenabling it: https://gist.github.com/larryliu0820/7377ecd0d79dbc06076cec8d9f2b85d2 + # test-eval_llama-mmlu-linux: + # name: test-eval_llama-mmlu-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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 "cmake" + + # # install llama requirements + # bash examples/models/llama/install_requirements.sh + + # # run eval_llama mmlu task + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_eval_llama_mmlu.sh + + # test-llama_runner_eager-linux: + # name: test-llama_runner_eager-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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 "cmake" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" - # install llama requirements - bash examples/models/llama/install_requirements.sh + # # install llama requirements + # bash examples/models/llama/install_requirements.sh - # run eval_llama wikitext task - PYTHON_EXECUTABLE=python bash .ci/scripts/test_eval_llama_wikitext.sh + # # run llama runner in eager mode + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama_runner_eager.sh - # TODO(larryliu0820): Fix this issue before reenabling it: https://gist.github.com/larryliu0820/7377ecd0d79dbc06076cec8d9f2b85d2 - # test-eval_llama-mmlu-linux: - # name: test-eval_llama-mmlu-linux + # test-llama-lora-linux: + # name: test-llama-lora-linux # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main # permissions: # id-token: write @@ -654,280 +729,226 @@ jobs: # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "cmake" - # # install llama requirements + # # Install llama requirements # bash examples/models/llama/install_requirements.sh - # # run eval_llama mmlu task - # PYTHON_EXECUTABLE=python bash .ci/scripts/test_eval_llama_mmlu.sh - - test-llama_runner_eager-linux: - name: test-llama_runner_eager-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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 "cmake" + # # install a recent version of torchtune. + # PYTHON_EXECUTABLE=python python -m pip install torchtune==0.7.0.dev20250730 --extra-index-url https://download.pytorch.org/whl/nightly/cpu - # install llama requirements - bash examples/models/llama/install_requirements.sh + # # run llama runner in eager mode + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama_lora.sh - # run llama runner in eager mode - PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama_runner_eager.sh - - test-llama-lora-linux: - name: test-llama-lora-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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 "cmake" - - # Install llama requirements - bash examples/models/llama/install_requirements.sh - - # install a recent version of torchtune. - PYTHON_EXECUTABLE=python python -m pip install torchtune==0.7.0.dev20250730 --extra-index-url https://download.pytorch.org/whl/nightly/cpu - - # run llama runner in eager mode - PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama_lora.sh - - test-mediatek-models-linux: - name: test-mediatek-models-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.24xlarge - docker-image: ci-image:executorch-ubuntu-22.04-mediatek-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-mediatek-models-linux: + # name: test-mediatek-models-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.24xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-mediatek-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - source .ci/scripts/utils.sh - install_executorch "--use-pt-pinned-commit" + # source .ci/scripts/utils.sh + # install_executorch "--use-pt-pinned-commit" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-mediatek-deps.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/build-mediatek-sdk.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "mv3" "buck2" "mediatek" - # placeholder for mediatek to add more tests + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-mediatek-deps.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/build-mediatek-sdk.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "mv3" "buck2" "mediatek" + # # placeholder for mediatek to add more tests - test-openvino-linux: - name: test-openvino-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-gcc9 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-openvino-linux: + # name: test-openvino-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-gcc9 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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-openvino.sh - PYTHON_EXECUTABLE=python bash .ci/scripts/test_openvino.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-openvino.sh + # PYTHON_EXECUTABLE=python bash .ci/scripts/test_openvino.sh - test-build-wasm-linux: - name: test-build-wasm-linux - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # test-build-wasm-linux: + # name: test-build-wasm-linux + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - BUILD_TOOL="cmake" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # BUILD_TOOL="cmake" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Install Node.js and Emscripten - source .ci/scripts/setup-emscripten.sh + # # Install Node.js and Emscripten + # source .ci/scripts/setup-emscripten.sh - # Test selective build - PYTHON_EXECUTABLE=python bash examples/wasm/test_build_wasm.sh + # # Test selective build + # PYTHON_EXECUTABLE=python bash examples/wasm/test_build_wasm.sh - unittest-wasm-bindings: - name: unittest-wasm-bindings - uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main - permissions: - id-token: write - contents: read - strategy: - matrix: - enable-etdump: ['', '--enable-etdump'] - fail-fast: false - with: - runner: linux.2xlarge - docker-image: ci-image:executorch-ubuntu-22.04-clang12 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # unittest-wasm-bindings: + # name: unittest-wasm-bindings + # uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main + # permissions: + # id-token: write + # contents: read + # strategy: + # matrix: + # enable-etdump: ['', '--enable-etdump'] + # fail-fast: false + # with: + # runner: linux.2xlarge + # docker-image: ci-image:executorch-ubuntu-22.04-clang12 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - BUILD_TOOL="cmake" - PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" + # BUILD_TOOL="cmake" + # PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}" - # Install Node.js and Emscripten - source .ci/scripts/setup-emscripten.sh + # # Install Node.js and Emscripten + # source .ci/scripts/setup-emscripten.sh - # Test selective build - bash scripts/build_wasm_tests.sh ${{ matrix.enable-etdump }} + # # Test selective build + # bash scripts/build_wasm_tests.sh ${{ matrix.enable-etdump }} - # Install Jest - cd cmake-out-wasm/extension/wasm/test - npm install --save-dev jest + # # Install Jest + # cd cmake-out-wasm/extension/wasm/test + # npm install --save-dev jest - # Run unit test - npm test + # # Run unit test + # npm test - unittest-nxp-neutron: - 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 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - set -eux + # unittest-nxp-neutron: + # 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 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # set -eux - # 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}" + # # 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}" - # Build and install Executorch - PYTHON_EXECUTABLE=python \ - CMAKE_ARGS="-DEXECUTORCH_BUILD_NXP_NEUTRON=ON" \ - .ci/scripts/setup-linux.sh --build-tool "cmake" + # # Build and install Executorch + # PYTHON_EXECUTABLE=python \ + # CMAKE_ARGS="-DEXECUTORCH_BUILD_NXP_NEUTRON=ON" \ + # .ci/scripts/setup-linux.sh --build-tool "cmake" - # Install test requirements - pip install -r backends/nxp/requirements-tests.txt + # # Install test requirements + # pip install -r backends/nxp/requirements-tests.txt - # Run pytest - PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh + # # Run pytest + # PYTHON_EXECUTABLE=python bash backends/nxp/run_unittests.sh - # Run aot examples: - PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10 - PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh mobilenetv2 + # # Run aot examples: + # PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh cifar10 + # PYTHON_EXECUTABLE=python bash examples/nxp/run_aot_example.sh mobilenetv2 - test-vulkan-models-linux: - name: test-vulkan-models-linux - 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 - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - set -eux + # test-vulkan-models-linux: + # name: test-vulkan-models-linux + # 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 + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # set -eux - # 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}" + # # 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}" - # Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate - source .ci/scripts/setup-vulkan-linux-deps.sh + # # Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate + # source .ci/scripts/setup-vulkan-linux-deps.sh - # Setup python - PYTHON_EXECUTABLE=python \ - CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \ - .ci/scripts/setup-linux.sh --build-tool "cmake" + # # Setup python + # PYTHON_EXECUTABLE=python \ + # CMAKE_ARGS="-DEXECUTORCH_BUILD_VULKAN=ON" \ + # .ci/scripts/setup-linux.sh --build-tool "cmake" - PYTHON_EXECUTABLE=python bash backends/vulkan/test/scripts/test_model.sh --build + # PYTHON_EXECUTABLE=python bash backends/vulkan/test/scripts/test_model.sh --build - # Test models serially - models="mv2 mv3 edsr resnet18 resnet50 dl3" - for model in $models; do - python -m examples.vulkan.export --model_name=$model --test - done + # # Test models serially + # models="mv2 mv3 edsr resnet18 resnet50 dl3" + # for model in $models; do + # python -m examples.vulkan.export --model_name=$model --test + # done - nxp-build-test: - name: nxp-build-test - 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-arm-sdk - submodules: 'recursive' - ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} - timeout: 90 - script: | - # 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}" + # nxp-build-test: + # name: nxp-build-test + # 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-arm-sdk + # submodules: 'recursive' + # ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }} + # timeout: 90 + # script: | + # # 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}" - # Build - cmake -DEXECUTORCH_BUILD_NXP_NEUTRON=ON -Bcmake-out . - cmake --build cmake-out --target executorch_delegate_neutron --config Release - - # Build check for the neutron backend library - lib_neutron="cmake-out/backends/nxp/libexecutorch_delegate_neutron.a" - if [ -f $lib_neutron ]; then - echo "Neutron backend library built." - else - echo "Neutron backend library not found!" - exit 1 - fi + # # Build + # cmake -DEXECUTORCH_BUILD_NXP_NEUTRON=ON -Bcmake-out . + # cmake --build cmake-out --target executorch_delegate_neutron --config Release + + # # Build check for the neutron backend library + # lib_neutron="cmake-out/backends/nxp/libexecutorch_delegate_neutron.a" + # if [ -f $lib_neutron ]; then + # echo "Neutron backend library built." + # else + # echo "Neutron backend library not found!" + # exit 1 + # fi diff --git a/backends/qualcomm/__init__.py b/backends/qualcomm/__init__.py new file mode 100644 index 00000000000..1b4e7ba2fdd --- /dev/null +++ b/backends/qualcomm/__init__.py @@ -0,0 +1,16 @@ +import os +import pathlib + +from .scripts.download_qnn_sdk import _download_qnn_sdk, SDK_DIR + +# ----------------------------------------------------------------------------- +# Main SDK setup +# ----------------------------------------------------------------------------- +qnn_root = os.environ.get("QNN_SDK_ROOT") +if qnn_root: + SDK_DIR = pathlib.Path(qnn_root) +else: + if not SDK_DIR.exists(): + print("Qualcomm SDK not found. Downloading...") + _download_qnn_sdk() + os.environ["QNN_SDK_ROOT"] = str(SDK_DIR) diff --git a/backends/qualcomm/scripts/build.sh b/backends/qualcomm/scripts/build.sh index 43d968813a9..04f9ffdbd36 100755 --- a/backends/qualcomm/scripts/build.sh +++ b/backends/qualcomm/scripts/build.sh @@ -1,3 +1,4 @@ +#!/bin/bash # Copyright (c) Qualcomm Innovation Center, Inc. # All rights reserved # diff --git a/backends/qualcomm/scripts/download_qnn_sdk.py b/backends/qualcomm/scripts/download_qnn_sdk.py new file mode 100644 index 00000000000..9512d4be2c3 --- /dev/null +++ b/backends/qualcomm/scripts/download_qnn_sdk.py @@ -0,0 +1,130 @@ +import pathlib +import platform +import sys +import tarfile +import tempfile +import urllib.request +import zipfile + + + +def is_linux_x86() -> bool: + """ + Check if the current system is Linux running on an x86 architecture. + + Returns: + bool: True if the system is Linux and the architecture is one of + x86_64, i386, or i686. False otherwise. + """ + return sys.platform.startswith("linux") and platform.machine() in { + "x86_64", + "i386", + "i686", + } + +SDK_DIR = pathlib.Path(__file__).parent / "sdk" + +def _download_qnn_sdk() -> pathlib.Path: + """ + Download and extract the Qualcomm SDK from the given URL into target_dir. + + Args: + url (str): The URL of the archive (.zip, .tar.gz, or .tgz). + prefix_to_strip (str): Top-level directory inside the archive to strip + from extracted file paths. + target_dir (pathlib.Path): Directory to extract the SDK into. + + Notes: + - Only runs on Linux x86 platforms. Skips otherwise. + - Creates the target_dir if it does not exist. + """ + # Default path where the Qualcomm SDK will be installed (under the script directory). + + # URL to download the Qualcomm AI Runtime SDK archive. + qairt_url = ( + "https://softwarecenter.qualcomm.com/api/download/software/sdks/" + "Qualcomm_AI_Runtime_Community/All/2.34.0.250424/v2.34.0.250424.zip" + ) + + # Top-level directory inside the SDK archive to extract. + qairt_content_dir = "qairt/2.34.0.250424" + + if not is_linux_x86(): + print("Skipping Qualcomm SDK (only supported on Linux x86).") + return + + SDK_DIR.mkdir(parents=True, exist_ok=True) + + with tempfile.TemporaryDirectory() as tmpdir: + archive_path = pathlib.Path(tmpdir) / pathlib.Path(qairt_url).name + + print(f"Downloading Qualcomm SDK from {qairt_url}...") + urllib.request.urlretrieve(qairt_url, archive_path) + + if qairt_url.endswith(".zip"): + _extract_zip(archive_path, qairt_content_dir, SDK_DIR) + elif qairt_url.endswith((".tar.gz", ".tgz")): + _extract_tar(archive_path, qairt_content_dir, SDK_DIR) + else: + raise ValueError(f"Unsupported archive format: {qairt_url}") + + print(f"Qualcomm SDK extracted to {SDK_DIR}") + + return SDK_DIR + + + + +def _extract_zip(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Path): + """ + Extract files from a zip archive into target_dir, stripping a prefix. + + Args: + archive_path (pathlib.Path): Path to the .zip archive. + prefix (str): Prefix folder inside the archive to strip. + target_dir (pathlib.Path): Destination directory. + """ + with zipfile.ZipFile(archive_path, "r") as zf: + for member in zf.infolist(): + if not member.filename.startswith(prefix + "/"): + continue + relpath = pathlib.Path(member.filename).relative_to(prefix) + if not relpath.parts or relpath.parts[0] == "..": + continue + out_path = target_dir / relpath + if member.is_dir(): + out_path.mkdir(parents=True, exist_ok=True) + else: + out_path.parent.mkdir(parents=True, exist_ok=True) + with zf.open(member) as src, open(out_path, "wb") as dst: + dst.write(src.read()) + + +def _extract_tar(archive_path: pathlib.Path, prefix: str, target_dir: pathlib.Path): + """ + Extract files from a tar.gz archive into target_dir, stripping a prefix. + + Args: + archive_path (pathlib.Path): Path to the .tar.gz or .tgz archive. + prefix (str): Prefix folder inside the archive to strip. + target_dir (pathlib.Path): Destination directory. + """ + with tarfile.open(archive_path, "r:gz") as tf: + for m in tf.getmembers(): + if not m.name.startswith(prefix + "/"): + continue + relpath = pathlib.Path(m.name).relative_to(prefix) + if not relpath.parts or relpath.parts[0] == "..": + continue + + out_path = target_dir / relpath + if m.isdir(): + out_path.mkdir(parents=True, exist_ok=True) + else: + out_path.parent.mkdir(parents=True, exist_ok=True) + src = tf.extractfile(m) + if src is None: + # Skip non-regular files (links, devices, etc.) + continue + with src, open(out_path, "wb") as dst: + dst.write(src.read()) diff --git a/setup.py b/setup.py index 69f59a2a2d5..a2a290a2a94 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,14 @@ # Import this before distutils so that setuptools can intercept the distuils # imports. import setuptools # noqa: F401 # usort: skip +import os +import platform import subprocess +import sys +import tarfile +import tempfile +import urllib.request +import zipfile from distutils import log # type: ignore[import-not-found] from distutils.sysconfig import get_python_lib # type: ignore[import-not-found] @@ -67,6 +74,7 @@ from setuptools.command.build import build from setuptools.command.build_ext import build_ext from setuptools.command.build_py import build_py +from setuptools.command.install import install try: from tools.cmake.cmake_cache import CMakeCache @@ -455,6 +463,71 @@ def run(self): if self._ran_build: return + try: + from backends.qualcomm.scripts.download_qnn_sdk import ( + _download_qnn_sdk, + SDK_DIR, + ) + + print( + "SDK_DIR: ", + SDK_DIR, + "type: ", + type(SDK_DIR), + "exists: ", + os.path.exists(SDK_DIR), + ) + _download_qnn_sdk() + + sdk_path = Path(SDK_DIR).resolve() # full absolute path + except ImportError: + print("Import error: ", sys.exc_info()[0]) + sdk_path = None + + print( + "SDK_DIR: ", + SDK_DIR, + "type: ", + type(SDK_DIR), + "exists: ", + os.path.exists(SDK_DIR), + ) + _download_qnn_sdk() + + sdk_path = Path(SDK_DIR).resolve() # full absolute path + print("sdk_path: ", sdk_path) + if not sdk_path: + raise RuntimeError("Qualcomm SDK not found, cannot build backend") + + # Determine paths + prj_root = Path(__file__).parent.resolve() + build_sh = prj_root / "backends/qualcomm/scripts/build.sh" + build_root = prj_root / "build-x86" + + if not build_sh.exists(): + raise FileNotFoundError(f"{build_sh} not found") + + # Run build.sh with SDK path exported + env = dict(**os.environ) + print("str(sdk_path): ", str(sdk_path)) + env["QNN_SDK_ROOT"] = str(sdk_path) + subprocess.check_call([str(build_sh)], env=env) + + # Copy the main .so into the wheel package + so_src = build_root / "backends/qualcomm/libqnn_executorch_backend.so" + so_dst = Path(self.get_ext_fullpath("executorch.backends.qualcomm.qnn_backend")) + self.mkpath(so_dst.parent) # ensure destination exists + self.copy_file(str(so_src), str(so_dst)) + print(f"Copied Qualcomm backend: {so_src} -> {so_dst}") + + # Remove Qualcomm SDK .so so they don’t get packaged + if os.path.exists(SDK_DIR): + for root, dirs, files in os.walk(SDK_DIR): + for f in files: + if f.endswith(".so"): + os.remove(os.path.join(root, f)) + print(f"Removed SDK .so from wheel package: {f}") + if self.editable_mode: self._ran_build = True self.run_command("build")