Skip to content

Commit 7c1d9e0

Browse files
author
pytorchbot
committed
2025-09-16 nightly release (e0dda90)
1 parent 9bb5401 commit 7c1d9e0

File tree

719 files changed

+38406
-12318
lines changed

Some content is hidden

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

719 files changed

+38406
-12318
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e7152ff8a6a929a0db7f3f4a72a5b6d471769cd3
1+
4d4abec80f03cd8fdefe1d9cb3a60d3690cd777e

.ci/scripts/setup-samsung-linux-deps.sh

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ install_enn_backend() {
5454
rm -rf "${NDK_INSTALLATION_DIR}" && sudo mkdir -p "${NDK_INSTALLATION_DIR}"
5555
ANDROID_NDK_VERSION=r27b
5656

57-
pushd .
58-
cd /tmp
59-
curl -Os --retry 3 "https://ossci-android.s3.amazonaws.com/android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
60-
unzip -qo "android-ndk-${ANDROID_NDK_VERSION}-linux.zip"
61-
62-
# Print the content for manual verification
63-
ls -lah "android-ndk-${ANDROID_NDK_VERSION}"
64-
sudo mv "android-ndk-${ANDROID_NDK_VERSION}"/* "${NDK_INSTALLATION_DIR}"
65-
popd
6657
# build Exynos backend
6758
export ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT:-/opt/ndk}
6859
bash backends/samsung/build.sh --build all

.ci/scripts/setup-windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
param (
2-
[string]$editable = $false
2+
[string]$editable = "false"
33
)
44

55
conda create --yes --quiet -n et python=3.12

.ci/scripts/test_model.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function ExportModel-Xnnpack {
3434
[bool]$quantize
3535
)
3636

37-
if $(quantize) {
37+
if ($quantize) {
3838
python -m examples.xnnpack.aot_compiler --model_name="${MODEL_NAME}" --delegate --quantize | Write-Host
3939
$modelFile = "$($modelName)_xnnpack_q8.pte"
4040
} else {
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
set -euxo pipefail
3+
4+
# -------------------------
5+
# Args / flags
6+
# -------------------------
7+
TEST_WITH_RUNNER=0
8+
MODEL_NAME=""
9+
10+
# Parse args
11+
if [[ $# -lt 1 ]]; then
12+
echo "Usage: $0 <model_name> [--test_with_runner]"
13+
echo "Supported model_name values: qwen3_4b, phi_4_mini"
14+
exit 1
15+
fi
16+
17+
MODEL_NAME="$1"
18+
shift
19+
20+
while [[ $# -gt 0 ]]; do
21+
case "$1" in
22+
--test_with_runner)
23+
TEST_WITH_RUNNER=1
24+
;;
25+
-h|--help)
26+
echo "Usage: $0 <model_name> [--test_with_runner]"
27+
echo " model_name: qwen3_4b | phi_4_mini"
28+
echo " --test_with_runner: build ET + run llama_main to sanity-check the export"
29+
exit 0
30+
;;
31+
*)
32+
echo "Unknown option: $1"
33+
exit 1
34+
;;
35+
esac
36+
shift
37+
done
38+
39+
if [[ -z "${PYTHON_EXECUTABLE:-}" ]]; then
40+
PYTHON_EXECUTABLE=python3
41+
fi
42+
43+
MODEL_OUT=model.pte
44+
45+
case "$MODEL_NAME" in
46+
qwen3_4b)
47+
echo "Running Qwen3-4B export..."
48+
HF_MODEL_DIR=$(hf download pytorch/Qwen3-4B-INT8-INT4)
49+
EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB
50+
$PYTHON_EXECUTABLE -m executorch.examples.models.qwen3.convert_weights \
51+
$HF_MODEL_DIR \
52+
pytorch_model_converted.bin
53+
54+
$PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \
55+
--model "qwen3_4b" \
56+
--checkpoint pytorch_model_converted.bin \
57+
--params examples/models/qwen3/config/4b_config.json \
58+
--output_name $MODEL_OUT \
59+
-kv \
60+
--use_sdpa_with_kv_cache \
61+
-X \
62+
--xnnpack-extended-ops \
63+
--max_context_length 1024 \
64+
--max_seq_length 1024 \
65+
--dtype fp32 \
66+
--metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}'
67+
;;
68+
69+
phi_4_mini)
70+
echo "Running Phi-4-mini export..."
71+
HF_MODEL_DIR=$(hf download pytorch/Phi-4-mini-instruct-INT8-INT4)
72+
EXPECTED_MODEL_SIZE_UPPER_BOUND=$((3 * 1024 * 1024 * 1024)) # 3GB
73+
$PYTHON_EXECUTABLE -m executorch.examples.models.phi_4_mini.convert_weights \
74+
$HF_MODEL_DIR \
75+
pytorch_model_converted.bin
76+
77+
$PYTHON_EXECUTABLE -m executorch.examples.models.llama.export_llama \
78+
--model "phi_4_mini" \
79+
--checkpoint pytorch_model_converted.bin \
80+
--params examples/models/phi_4_mini/config/config.json \
81+
--output_name $MODEL_OUT \
82+
-kv \
83+
--use_sdpa_with_kv_cache \
84+
-X \
85+
--xnnpack-extended-ops \
86+
--max_context_length 1024 \
87+
--max_seq_length 1024 \
88+
--dtype fp32 \
89+
--metadata '{"get_bos_id":199999, "get_eos_ids":[200020,199999]}'
90+
;;
91+
92+
*)
93+
echo "Error: unsupported model_name '$MODEL_NAME'"
94+
echo "Supported values: qwen3_4b, phi_4_mini"
95+
exit 1
96+
;;
97+
esac
98+
99+
# Check file size
100+
MODEL_SIZE=$(stat --printf="%s" $MODEL_OUT 2>/dev/null || stat -f%z $MODEL_OUT)
101+
if [[ $MODEL_SIZE -gt $EXPECTED_MODEL_SIZE_UPPER_BOUND ]]; then
102+
echo "Error: model size $MODEL_SIZE is greater than expected upper bound $EXPECTED_MODEL_SIZE_UPPER_BOUND"
103+
exit 1
104+
fi
105+
106+
# Install ET with CMake
107+
if [[ "$TEST_WITH_RUNNER" -eq 1 ]]; then
108+
echo "[runner] Building and testing llama_main ..."
109+
cmake -DPYTHON_EXECUTABLE=python \
110+
-DCMAKE_INSTALL_PREFIX=cmake-out \
111+
-DEXECUTORCH_ENABLE_LOGGING=1 \
112+
-DCMAKE_BUILD_TYPE=Release \
113+
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
114+
-DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON \
115+
-DEXECUTORCH_BUILD_EXTENSION_MODULE=ON \
116+
-DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON \
117+
-DEXECUTORCH_BUILD_XNNPACK=ON \
118+
-DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON \
119+
-DEXECUTORCH_BUILD_KERNELS_OPTIMIZED=ON \
120+
-DEXECUTORCH_BUILD_EXTENSION_LLM_RUNNER=ON \
121+
-DEXECUTORCH_BUILD_EXTENSION_LLM=ON \
122+
-DEXECUTORCH_BUILD_KERNELS_LLM=ON \
123+
-Bcmake-out .
124+
cmake --build cmake-out -j16 --config Release --target install
125+
126+
127+
# Install llama runner
128+
cmake -DPYTHON_EXECUTABLE=python \
129+
-DCMAKE_BUILD_TYPE=Release \
130+
-Bcmake-out/examples/models/llama \
131+
examples/models/llama
132+
cmake --build cmake-out/examples/models/llama -j16 --config Release
133+
134+
# Run the model
135+
./cmake-out/examples/models/llama/llama_main --model_path=$MODEL_OUT --tokenizer_path="${HF_MODEL_DIR}/tokenizer.json" --prompt="Once upon a time,"
136+
fi
137+
138+
# Clean up
139+
rm -f pytorch_model_converted.bin "$MODEL_OUT"
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
#!/bin/bash
2+
# === CI Wheel Build & Test Script ===
3+
4+
# Exit immediately on error, print each command, and capture all output to build.log
5+
set -e
6+
set -x
7+
exec > >(tee -i build.log) 2>&1
8+
9+
# Save repo root
10+
REPO_ROOT=$(pwd)
11+
12+
# ----------------------------
13+
# Dynamically create script_qnn_wheel_test.py
14+
# ----------------------------
15+
cat > "/tmp/script_qnn_wheel_test.py" << 'EOF'
16+
# pyre-ignore-all-errors
17+
import argparse
18+
19+
import torch
20+
from executorch.backends.qualcomm.quantizer.quantizer import QnnQuantizer
21+
from executorch.backends.qualcomm.utils.utils import (
22+
generate_htp_compiler_spec,
23+
generate_qnn_executorch_compiler_spec,
24+
get_soc_to_chipset_map,
25+
to_edge_transform_and_lower_to_qnn,
26+
)
27+
from executorch.exir.backend.utils import format_delegated_graph
28+
from executorch.examples.models.model_factory import EagerModelFactory
29+
from executorch.exir.capture._config import ExecutorchBackendConfig
30+
from executorch.extension.export_util.utils import save_pte_program
31+
from torchao.quantization.pt2e.quantize_pt2e import convert_pt2e, prepare_pt2e, prepare_qat_pt2e
32+
33+
def main() -> None:
34+
parser = argparse.ArgumentParser()
35+
parser.add_argument("-f", "--output_folder", type=str, default="", help="The folder to store the exported program")
36+
parser.add_argument("--soc", type=str, default="SM8650", help="Specify the SoC model.")
37+
parser.add_argument("-q", "--quantization", choices=["ptq", "qat"], help="Run post-traininig quantization.")
38+
args = parser.parse_args()
39+
40+
class LinearModule(torch.nn.Module):
41+
def __init__(self):
42+
super().__init__()
43+
self.linear = torch.nn.Linear(3, 3)
44+
def forward(self, arg):
45+
return self.linear(arg)
46+
def get_example_inputs(self):
47+
return (torch.randn(3, 3),)
48+
49+
model = LinearModule()
50+
example_inputs = model.get_example_inputs()
51+
52+
if args.quantization:
53+
quantizer = QnnQuantizer()
54+
m = torch.export.export(model.eval(), example_inputs, strict=True).module()
55+
if args.quantization == "qat":
56+
m = prepare_qat_pt2e(m, quantizer)
57+
m(*example_inputs)
58+
elif args.quantization == "ptq":
59+
m = prepare_pt2e(m, quantizer)
60+
m(*example_inputs)
61+
m = convert_pt2e(m)
62+
else:
63+
m = model
64+
65+
use_fp16 = True if args.quantization is None else False
66+
backend_options = generate_htp_compiler_spec(use_fp16=use_fp16)
67+
compile_spec = generate_qnn_executorch_compiler_spec(
68+
soc_model=get_soc_to_chipset_map()[args.soc],
69+
backend_options=backend_options,
70+
)
71+
delegated_program = to_edge_transform_and_lower_to_qnn(m, example_inputs, compile_spec)
72+
output_graph = format_delegated_graph(delegated_program.exported_program().graph_module)
73+
# Ensure QnnBackend is in the output graph
74+
assert "QnnBackend" in output_graph
75+
executorch_program = delegated_program.to_executorch(
76+
config=ExecutorchBackendConfig(extract_delegate_segments=False)
77+
)
78+
save_pte_program(executorch_program, "linear", args.output_folder)
79+
80+
if __name__ == "__main__":
81+
main()
82+
EOF
83+
84+
# ----------------------------
85+
# Wheel build and .so checks
86+
# ----------------------------
87+
echo "=== Building Wheel Package ==="
88+
source .ci/scripts/utils.sh
89+
install_executorch
90+
EXECUTORCH_BUILDING_WHEEL=1 python setup.py bdist_wheel
91+
unset EXECUTORCH_BUILDING_WHEEL
92+
93+
WHEEL_FILE=$(ls dist/*.whl | head -n 1)
94+
echo "Found wheel: $WHEEL_FILE"
95+
96+
PYTHON_VERSION=$1
97+
# ----------------------------
98+
# Check wheel does NOT contain qualcomm/sdk
99+
# ----------------------------
100+
echo "Checking wheel does not contain qualcomm/sdk..."
101+
SDK_FILES=$(unzip -l "$WHEEL_FILE" | awk '{print $4}' | grep "executorch/backends/qualcomm/sdk" || true)
102+
if [ -n "$SDK_FILES" ]; then
103+
echo "ERROR: Wheel package contains unexpected qualcomm/sdk files:"
104+
echo "$SDK_FILES"
105+
exit 1
106+
else
107+
echo "OK: No qualcomm/sdk files found in wheel"
108+
fi
109+
110+
# ----------------------------
111+
# Check .so files in the wheel
112+
# ----------------------------
113+
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)
115+
if [ -z "$WHEEL_SO_FILES" ]; then
116+
echo "ERROR: No .so files found in wheel under executorch/backends/qualcomm/python"
117+
exit 1
118+
else
119+
echo "Wheel contains the following .so files:"
120+
echo "$WHEEL_SO_FILES"
121+
fi
122+
123+
# ----------------------------
124+
# Helpers
125+
# ----------------------------
126+
get_site_packages_dir () {
127+
local PYBIN="$1"
128+
"$PYBIN" - <<'PY'
129+
import sysconfig, sys
130+
print(sysconfig.get_paths().get("purelib") or sysconfig.get_paths().get("platlib"))
131+
PY
132+
}
133+
134+
run_core_tests () {
135+
local PYBIN="$1" # path to python
136+
local PIPBIN="$2" # path to pip
137+
local LABEL="$3" # label to print (conda/venv)
138+
139+
echo "=== [$LABEL] Installing wheel & deps ==="
140+
"$PIPBIN" install --upgrade pip
141+
"$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"
144+
145+
echo "=== [$LABEL] Import smoke tests ==="
146+
"$PYBIN" -c "import executorch; print('executorch imported successfully')"
147+
"$PYBIN" -c "import executorch.backends.qualcomm; print('executorch.backends.qualcomm imported successfully')"
148+
149+
echo "=== [$LABEL] List installed executorch/backends/qualcomm/python ==="
150+
local SITE_DIR
151+
SITE_DIR="$(get_site_packages_dir "$PYBIN")"
152+
local SO_DIR="$SITE_DIR/executorch/backends/qualcomm/python"
153+
ls -l "$SO_DIR" || echo "Folder does not exist!"
154+
155+
echo "=== [$LABEL] Run export script to generate linear.pte ==="
156+
(cd "$REPO_ROOT" && "$PYBIN" "/tmp/script_qnn_wheel_test.py")
157+
158+
if [ -f "$REPO_ROOT/linear.pte" ]; then
159+
echo "[$LABEL] Model file linear.pte successfully created"
160+
else
161+
echo "ERROR: [$LABEL] Model file linear.pte was not created"
162+
exit 1
163+
fi
164+
}
165+
166+
# ----------------------------
167+
# Conda environment setup & tests
168+
# ----------------------------
169+
echo "=== Testing in Conda env ==="
170+
TEMP_ENV_DIR=$(mktemp -d)
171+
echo "Using temporary directory for conda: $TEMP_ENV_DIR"
172+
conda create -y -p "$TEMP_ENV_DIR/env" python=$PYTHON_VERSION
173+
# derive python/pip paths inside the conda env
174+
CONDA_PY="$TEMP_ENV_DIR/env/bin/python"
175+
CONDA_PIP="$TEMP_ENV_DIR/env/bin/pip"
176+
# Some images require conda run; keep pip/python direct to simplify path math
177+
run_core_tests "$CONDA_PY" "$CONDA_PIP" "conda"
178+
179+
# Cleanup conda env
180+
conda env remove -p "$TEMP_ENV_DIR/env" -y || true
181+
rm -rf "$TEMP_ENV_DIR"
182+
183+
# ----------------------------
184+
# Python venv setup & tests
185+
# ----------------------------
186+
echo "=== Testing in Python venv ==="
187+
TEMP_VENV_DIR=$(mktemp -d)
188+
echo "Using temporary directory for venv: $TEMP_VENV_DIR"
189+
python3 -m venv "$TEMP_VENV_DIR/venv"
190+
VENV_PY="$TEMP_VENV_DIR/venv/bin/python"
191+
VENV_PIP="$TEMP_VENV_DIR/venv/bin/pip"
192+
193+
# Ensure venv has wheel/build basics if needed
194+
"$VENV_PIP" install --upgrade pip
195+
196+
run_core_tests "$VENV_PY" "$VENV_PIP" "venv"
197+
198+
# Cleanup venv
199+
rm -rf "$TEMP_VENV_DIR"
200+
201+
echo "=== All tests completed! ==="

.ci/scripts/unittest-buck2.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ set -eux
99
# TODO: expand this to //...
1010
# TODO: can't query cadence & vulkan backends
1111
# TODO: can't query //kernels/prim_ops because of non-buckified stuff in OSS.
12-
buck2 query "//backends/apple/... + //backends/example/... + \
12+
# TODO: Make //backends/arm tests use runtime wrapper so we can just query //backends/arm/...
13+
buck2 query "//backends/apple/... + //backends/arm: + //backends/arm/debug/... + \
14+
//backends/arm/operator_support/... + //backends/arm/operators/... + \
15+
//backends/arm/_passes/... + //backends/arm/runtime/... + //backends/arm/tosa/... \
16+
+ //backends/example/... + \
1317
//backends/mediatek/... + //backends/transforms/... + \
1418
//backends/xnnpack/... + //configurations/... + //extension/flat_tensor: + \
1519
//extension/llm/runner: + //kernels/aten/... + //kernels/optimized/... + \

0 commit comments

Comments
 (0)