Skip to content

Commit de0a970

Browse files
Merge branch 'main' into remove_ChecksNeedsDecomposition
2 parents c1c55f8 + 049c9fc commit de0a970

File tree

140 files changed

+6087
-871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+6087
-871
lines changed

.ci/scripts/test_llava.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ cmake_build_llava_runner_for_android() {
107107
# only export the one without custom op for now since it's
108108
export_llava() {
109109
echo "Starting to export Llava. This will take about 6 mins"
110-
$PYTHON_EXECUTABLE -m executorch.examples.models.llava.export_llava --pte-name llava.pte --with-artifacts
110+
$PYTHON_EXECUTABLE -m executorch.examples.models.llava.export_llava --pte-name llava.pte --with-artifacts --max-context-len 768
111111
}
112112

113113
# Download a new image
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# Copyright (c) Qualcomm Innovation Center, Inc.
3+
# All rights reserved
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
set -euo pipefail
9+
10+
echo ">>> Script invoked with arguments: $@"
11+
12+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
13+
14+
# Download QNN_SDK. If already downloaded, export environment path
15+
source "$(dirname "${BASH_SOURCE[0]}")/../../backends/qualcomm/scripts/install_qnn_sdk.sh"
16+
install_qnn
17+
18+
export EXECUTORCH_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
19+
export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang"
20+
export PYTHONPATH=".."
21+
cp schema/program.fbs exir/_serialize/program.fbs
22+
cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs
23+
cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python
24+
cp -f build-x86/backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python
25+
26+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
27+
PYTHON_EXECUTABLE=python3
28+
fi
29+
30+
which "${PYTHON_EXECUTABLE}"
31+
32+
# -------------------------------
33+
# Parse args
34+
# -------------------------------
35+
EXTRA_FLAGS=""
36+
THRESHOLD=62.0 # default fallback
37+
38+
while [[ $# -gt 0 ]]; do
39+
case "$1" in
40+
--flags)
41+
EXTRA_FLAGS="$2"
42+
shift 2
43+
;;
44+
--threshold)
45+
THRESHOLD="$2"
46+
shift 2
47+
;;
48+
*)
49+
echo "Unknown option: $1"
50+
exit 1
51+
;;
52+
esac
53+
done
54+
55+
# Config
56+
PYTHON_EXECUTABLE="${PYTHON_EXECUTABLE:-python3}"
57+
MODEL="qwen2_5-0_5b"
58+
MAX_SEQ=1024
59+
PTQ="16a4w"
60+
61+
EXTRA_FLAGS="$@"
62+
63+
# Run command and capture *both stdout and stderr*
64+
LOG_FILE="eval_${MODEL}_$(date +%Y%m%d_%H%M%S).log"
65+
66+
echo ">>> Running evaluation with flags: $EXTRA_FLAGS | threshold: $THRESHOLD"
67+
$PYTHON_EXECUTABLE -m executorch.examples.qualcomm.oss_scripts.llama.eval_llama_qnn \
68+
--decoder_model "$MODEL" \
69+
--quant_linear_only \
70+
--max_seq_length "$MAX_SEQ" \
71+
--ptq "$PTQ" \
72+
$EXTRA_FLAGS 2>&1 | tee "$LOG_FILE"
73+
74+
# Extract last word_perplexity
75+
LAST_PERP=$(grep "INFO:root:wikitext:" "$LOG_FILE" | tail -n 1 | sed -E "s/.*'word_perplexity,none': ([0-9.]+).*/\1/")
76+
77+
if [[ -z "$LAST_PERP" ]]; then
78+
echo "❌ Could not find word_perplexity in logs!"
79+
exit 1
80+
fi
81+
82+
echo ">>> Last word_perplexity = $LAST_PERP"
83+
84+
# Compare against threshold
85+
awk -v val="$LAST_PERP" -v thr="$THRESHOLD" 'BEGIN {exit (val > thr)}'
86+
if [[ $? -ne 0 ]]; then
87+
echo "❌ Regression detected: word_perplexity ($LAST_PERP) > threshold ($THRESHOLD)"
88+
exit 1
89+
fi
90+
91+
echo "✅ Check passed: word_perplexity ($LAST_PERP) <= $THRESHOLD"

.ci/scripts/test_wheel_package_qnn.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ PYTHON_VERSION=$1
9898
# Check wheel does NOT contain qualcomm/sdk
9999
# ----------------------------
100100
echo "Checking wheel does not contain qualcomm/sdk..."
101-
SDK_FILES=$(unzip -l "$WHEEL_FILE" | awk '{print $4}' | grep "executorch/backends/qualcomm/sdk" || true)
101+
SDK_FILES=$(unzip -l "$WHEEL_FILE" | awk '{print $4}' | grep -E "executorch/backends/qualcomm/sdk" || true)
102102
if [ -n "$SDK_FILES" ]; then
103103
echo "ERROR: Wheel package contains unexpected qualcomm/sdk files:"
104104
echo "$SDK_FILES"
@@ -111,7 +111,7 @@ fi
111111
# Check .so files in the wheel
112112
# ----------------------------
113113
echo "Checking for .so files inside the wheel..."
114-
WHEEL_SO_FILES=$(unzip -l "$WHEEL_FILE" | awk '{print $4}' | grep "executorch/backends/qualcomm/python" || true)
114+
WHEEL_SO_FILES=$(unzip -l "$WHEEL_FILE" | awk '{print $4}' | grep -E "executorch/backends/qualcomm/python" || true)
115115
if [ -z "$WHEEL_SO_FILES" ]; then
116116
echo "ERROR: No .so files found in wheel under executorch/backends/qualcomm/python"
117117
exit 1
@@ -139,8 +139,30 @@ run_core_tests () {
139139
echo "=== [$LABEL] Installing wheel & deps ==="
140140
"$PIPBIN" install --upgrade pip
141141
"$PIPBIN" install "$WHEEL_FILE"
142-
"$PIPBIN" install torch=="2.9.0.dev20250906" --index-url "https://download.pytorch.org/whl/nightly/cpu"
143-
"$PIPBIN" install --pre torchao --index-url "https://download.pytorch.org/whl/nightly/cpu"
142+
TORCH_VERSION=$(
143+
"$PYBIN" - <<'PY'
144+
import runpy
145+
module_vars = runpy.run_path("torch_pin.py")
146+
print(module_vars["TORCH_VERSION"])
147+
PY
148+
)
149+
150+
NIGHTLY_VERSION=$(
151+
"$PYBIN" - <<'PY'
152+
import runpy
153+
module_vars = runpy.run_path("torch_pin.py")
154+
print(module_vars["NIGHTLY_VERSION"])
155+
PY
156+
)
157+
echo "=== [$LABEL] Install torch==${TORCH_VERSION}.${NIGHTLY_VERSION} ==="
158+
159+
# Install torchao based on the pinned PyTorch version
160+
"$PIPBIN" install torch=="${TORCH_VERSION}.${NIGHTLY_VERSION}" --index-url "https://download.pytorch.org/whl/nightly/cpu"
161+
162+
# Install torchao based on the pinned commit from third-party/ao submodule
163+
pushd "$REPO_ROOT/third-party/ao" > /dev/null
164+
USE_CPP=0 "$PYBIN" setup.py develop
165+
popd > /dev/null
144166

145167
echo "=== [$LABEL] Import smoke tests ==="
146168
"$PYBIN" -c "import executorch; print('executorch imported successfully')"

.ci/scripts/unittest-buck2.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ BUILDABLE_KERNELS_PRIM_OPS_TARGETS=$(buck2 query //kernels/prim_ops/... | grep -
3535
for op in "build" "test"; do
3636
buck2 $op $BUILDABLE_OPTIMIZED_OPS \
3737
//examples/selective_build:select_all_dtype_selective_lib_portable_lib \
38+
//extension/llm/custom_ops/spinquant/test:fast_hadamard_transform_test \
39+
//extension/llm/runner/test:test_multimodal_input \
40+
//extension/llm/runner/test:test_generation_config \
3841
//kernels/portable/... \
3942
$BUILDABLE_KERNELS_PRIM_OPS_TARGETS //runtime/backend/... //runtime/core/... \
4043
//runtime/executor: //runtime/kernel/... //runtime/platform/...
4144
done
4245

4346
# Build only without testing
44-
buck2 build //codegen/tools/... # Needs torch for testing which we don't have in our OSS buck setup.
47+
buck2 build //codegen/tools/... \
48+
//extension/llm/runner/io_manager:io_manager \
49+
//extension/llm/modules/... \
50+
//extension/llm/runner:multimodal_runner_lib \
51+
//extension/llm/runner:text_decoder_runner

.github/workflows/add-unanswered-to-project.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ jobs:
1212
- name: Add open issues and open, non-draft PRs to org project (excluding certain authors)
1313
uses: actions/github-script@v7
1414
with:
15-
github-token: ${{ secrets.GITHUB_TOKEN }}
1615
script: |
1716
const projectId = "PVT_kwDOAUB9vs4A_PUL"; // PyTorch org project 136
1817
const owner = 'pytorch';

.github/workflows/android-release-artifacts.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,11 @@ on:
1515
type: choice
1616
options:
1717
- "xnnpack"
18-
- "vulkan+xnnpack"
18+
- "vulkan"
1919
- "qnn"
2020
schedule:
2121
- cron: 0 10 * * *
2222

23-
concurrency:
24-
group: ${{ github.workflow }}-${{ github.ref }}
25-
cancel-in-progress: true
26-
2723
jobs:
2824
check-if-aar-exists:
2925
name: check-if-aar-exists
@@ -34,12 +30,13 @@ jobs:
3430
shell: bash
3531
run: |
3632
VERSION="${{ inputs.version }}"
33+
FLAVOR="${{ inputs.flavor }}"
3734
if [ -z "$VERSION" ]; then
3835
echo "No version name specified. Will create a snapshot AAR"
3936
exit 0
4037
fi
41-
if curl -I "https://ossci-android.s3.amazonaws.com/executorch/release/${VERSION}/executorch.aar" | grep "200 OK"; then
42-
echo "AAR already exists at https://ossci-android.s3.amazonaws.com/executorch/release/${VERSION}/executorch.aar"
38+
if curl -I "https://ossci-android.s3.amazonaws.com/executorch/release/${VERSION}-${FLAVOR}/executorch.aar" | grep "200 OK"; then
39+
echo "AAR already exists at https://ossci-android.s3.amazonaws.com/executorch/release/${VERSION}-${FLAVOR}/executorch.aar"
4340
echo "Will skip build/upload"
4441
exit 1
4542
fi
@@ -93,7 +90,10 @@ jobs:
9390
fi
9491
9592
FLAVOR="${{ inputs.flavor }}"
96-
if [[ "$FLAVOR" == "vulkan+xnnpack" || -z "$FLAVOR" ]]; then
93+
if [[ "$FLAVOR" == "vulkan" || -z "$FLAVOR" ]]; then
94+
curl -O https://sdk.lunarg.com/sdk/download/1.4.321.1/linux/vulkansdk-linux-x86_64-1.4.321.1.tar.xz
95+
tar xf vulkansdk-linux-x86_64-1.4.321.1.tar.xz -C /tmp
96+
export PATH="/tmp/1.4.321.1/x86_64/bin:$PATH"
9797
export EXECUTORCH_BUILD_VULKAN=ON
9898
fi
9999
@@ -145,8 +145,12 @@ jobs:
145145
pip install awscli==1.32.18
146146
AWS_CMD="aws s3 cp"
147147
VERSION="${{ inputs.version }}"
148+
FLAVOR="${{ inputs.flavor }}"
148149
if [ -z "$VERSION" ]; then
149150
VERSION="snapshot-$(date +"%Y%m%d")"
150151
fi
151-
${AWS_CMD} executorch.aar s3://ossci-android/executorch/release/${VERSION}/executorch.aar --acl public-read
152-
${AWS_CMD} executorch.aar.sha256sums s3://ossci-android/executorch/release/${VERSION}/executorch.aar.sha256sums --acl public-read
152+
if [ -z "$FLAVOR" ]; then
153+
FLAVOR="xnnpack"
154+
fi
155+
${AWS_CMD} executorch.aar s3://ossci-android/executorch/release/${VERSION}-${FLAVOR}/executorch.aar --acl public-read
156+
${AWS_CMD} executorch.aar.sha256sums s3://ossci-android/executorch/release/${VERSION}-${FLAVOR}/executorch.aar.sha256sums --acl public-read

.github/workflows/pull.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,7 @@ jobs:
10091009
./cmake-out/backends/vulkan/test/custom_ops/q8csw_conv2d
10101010
./cmake-out/backends/vulkan/test/custom_ops/q4gsw_linear
10111011
./cmake-out/backends/vulkan/test/custom_ops/choose_qparams_per_row
1012+
./cmake-out/backends/vulkan/test/custom_ops/qdq8ta_conv2d_activations
10121013
10131014
# "Classic" Operator tests
10141015
PYTHON_EXECUTABLE=python bash backends/vulkan/test/scripts/test_op.sh --build

.github/workflows/trunk.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,60 @@ jobs:
973973
# Test llama2
974974
PYTHON_EXECUTABLE=python bash .ci/scripts/test_llama.sh -model stories110M -build_tool "${BUILD_TOOL}" -mode "${MODE}" -dtype "${DTYPE}" -pt2e_quantize "${PT2E_QUANTIZE}"
975975
976+
# this is for filtering out the qnn changes such that qnn jobs only triggered when the specific files are changed
977+
changes:
978+
runs-on: ubuntu-latest
979+
outputs:
980+
qnn: ${{ steps.filter.outputs.qnn }}
981+
steps:
982+
- uses: actions/checkout@v4
983+
- uses: dorny/paths-filter@v3
984+
id: filter
985+
with:
986+
filters: |
987+
qnn:
988+
- 'backends/qualcomm/**'
989+
- 'examples/qualcomm/**'
990+
- 'examples/models/llama/**'
991+
992+
test-static-llama-qnn-eval-linux:
993+
needs: changes # has dependency on changes jobs defined above
994+
if: needs.changes.outputs.qnn == 'true'
995+
name: test-static-llama-qnn-eval-linux
996+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
997+
permissions:
998+
id-token: write
999+
contents: read
1000+
strategy:
1001+
fail-fast: false
1002+
matrix:
1003+
config:
1004+
- name: "baseline"
1005+
flags: ""
1006+
threshold: 62.0
1007+
with:
1008+
runner: linux.2xlarge
1009+
docker-image: ci-image:executorch-ubuntu-22.04-qnn-sdk
1010+
submodules: 'recursive'
1011+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
1012+
timeout: 180
1013+
script: |
1014+
# The generic Linux job chooses to use base env, not the one setup by the image
1015+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
1016+
conda activate "${CONDA_ENV}"
1017+
BUILD_TOOL="cmake"
1018+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
1019+
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
1020+
# Setup executorch
1021+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh --build-tool "${BUILD_TOOL}"
1022+
# Setup install_requirements for llama
1023+
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh
1024+
1025+
echo ">>> Running config: ${{ matrix.config.name }}"
1026+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_qnn_static_llama_eval.sh \
1027+
--flags "${{ matrix.config.flags }}" \
1028+
--threshold "${{ matrix.config.threshold }}"
1029+
9761030
unittest-release:
9771031
uses: ./.github/workflows/_unittest.yml
9781032
permissions:

.lintrunner.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ exclude_patterns = [
206206
'**/*.png',
207207
'**/*.webp',
208208
'**/*.jpeg',
209+
'**/*.mp3',
209210
'**/*.mp4',
210211
'**/*.pte',
211212
'**/*.pth',
@@ -216,6 +217,8 @@ exclude_patterns = [
216217
'**/*.jpg',
217218
'**/*.jar',
218219
'**/*.gif',
220+
'extension/llm/tokenizers',
221+
'extension/llm/tokenizers/**',
219222
# File contains @generated
220223
'extension/llm/custom_ops/spinquant/fast_hadamard_transform_special.h',
221224
'extension/llm/custom_ops/spinquant/test/fast_hadamard_transform_special_unstrided_cpu.h',

backends/aoti/CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
# All rights reserved.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
#
7+
# Build AOTI backend for runtime.
8+
#
9+
# ### Editing this file ###
10+
#
11+
# This file should be formatted with
12+
# ~~~
13+
# cmake-format -i CMakeLists.txt
14+
# ~~~
15+
# It should also be cmake-lint clean.
16+
#
17+
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
18+
19+
# Source root directory for executorch.
20+
if(NOT EXECUTORCH_ROOT)
21+
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
22+
endif()
23+
24+
# Use ExecuTorch's standard way to find PyTorch libraries for AOTI
25+
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
26+
find_package_torch()
27+
28+
# Common AOTI functionality - combines all AOTI common components
29+
set(_aoti_common_sources aoti_model_container.cpp common_shims.cpp)
30+
add_library(aoti_common STATIC ${_aoti_common_sources})
31+
target_include_directories(
32+
aoti_common
33+
PUBLIC $<BUILD_INTERFACE:${EXECUTORCH_ROOT}> $<INSTALL_INTERFACE:include>
34+
# PyTorch AOTI headers from ExecuTorch's torch detection
35+
${TORCH_INCLUDE_DIRS}
36+
)
37+
target_compile_options(aoti_common PUBLIC -fexceptions -frtti -fPIC)
38+
# Ensure symbols are exported properly
39+
target_link_options(aoti_common PUBLIC -Wl,--export-dynamic)
40+
41+
# Link against PyTorch libraries and standard libraries
42+
target_link_libraries(
43+
aoti_common
44+
PUBLIC extension_tensor ${CMAKE_DL_LIBS}
45+
# Link PyTorch libraries for AOTI functions
46+
${TORCH_LIBRARIES}
47+
)
48+
executorch_target_link_options_shared_lib(aoti_common)
49+
50+
install(
51+
TARGETS aoti_common
52+
EXPORT ExecuTorchTargets
53+
DESTINATION lib
54+
)

0 commit comments

Comments
 (0)