Skip to content

Commit a6181ef

Browse files
committed
Update
[ghstack-poisoned]
2 parents f4e54ae + 6d8583d commit a6181ef

File tree

406 files changed

+12661
-7654
lines changed

Some content is hidden

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

406 files changed

+12661
-7654
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/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 -euo 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"

.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/... + \

.ci/scripts/wheel/pre_build_script.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,26 @@ set -euxo pipefail
99

1010
# This script is run before building ExecuTorch binaries
1111

12+
# Clone nested submodules for tokenizers - this is a workaround for recursive
13+
# submodule clone failing due to path length limitations on Windows. Eventually,
14+
# we should update the core job in test-infra to enable long paths before
15+
# checkout to avoid needing to do this.
16+
pushd extension/llm/tokenizers
17+
git submodule update --init
18+
popd
19+
20+
# On Windows, enable symlinks and re-checkout the current revision to create
21+
# the symlinked src/ directory. This is needed to build the wheel.
22+
UNAME_S=$(uname -s)
23+
if [[ $UNAME_S == *"MINGW"* || $UNAME_S == *"MSYS"* ]]; then
24+
echo "Enabling symlinks on Windows"
25+
git config core.symlinks true
26+
git checkout -f HEAD
27+
fi
28+
1229
# Manually install build requirements because `python setup.py bdist_wheel` does
1330
# not install them. TODO(dbort): Switch to using `python -m build --wheel`,
1431
# which does install them. Though we'd need to disable build isolation to be
1532
# able to see the installed torch package.
1633

17-
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh" --example
34+
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh" --example

.ci/scripts/wheel/test_windows.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
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+
from typing import List
9+
10+
import torch
11+
from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
12+
from executorch.examples.models import Backend, Model, MODEL_NAME_TO_MODEL
13+
from executorch.examples.models.model_factory import EagerModelFactory
14+
from executorch.examples.xnnpack import MODEL_NAME_TO_OPTIONS
15+
from executorch.examples.xnnpack.quantization.utils import quantize as quantize_xnn
16+
from executorch.exir import EdgeCompileConfig, to_edge_transform_and_lower
17+
from executorch.extension.pybindings.portable_lib import (
18+
_load_for_executorch_from_buffer,
19+
)
20+
from test_base import ModelTest
21+
22+
23+
def test_model_xnnpack(model: Model, quantize: bool) -> None:
24+
model_instance, example_inputs, _, _ = EagerModelFactory.create_model(
25+
*MODEL_NAME_TO_MODEL[str(model)]
26+
)
27+
28+
model_instance.eval()
29+
ref_outputs = model_instance(*example_inputs)
30+
31+
if quantize:
32+
quant_type = MODEL_NAME_TO_OPTIONS[str(model)].quantization
33+
model_instance = torch.export.export_for_training(
34+
model_instance, example_inputs
35+
)
36+
model_instance = quantize_xnn(
37+
model_instance.module(), example_inputs, quant_type
38+
)
39+
40+
lowered = to_edge_transform_and_lower(
41+
torch.export.export(model_instance, example_inputs),
42+
partitioner=[XnnpackPartitioner()],
43+
compile_config=EdgeCompileConfig(
44+
_check_ir_validity=False,
45+
),
46+
).to_executorch()
47+
48+
loaded_model = _load_for_executorch_from_buffer(lowered.buffer)
49+
et_outputs = loaded_model([*example_inputs])
50+
51+
if isinstance(ref_outputs, torch.Tensor):
52+
ref_outputs = (ref_outputs,)
53+
54+
assert len(ref_outputs) == len(et_outputs)
55+
for i in range(len(ref_outputs)):
56+
torch.testing.assert_close(ref_outputs[i], et_outputs[i], atol=1e-4, rtol=1e-5)
57+
58+
59+
def run_tests(model_tests: List[ModelTest]) -> None:
60+
for model_test in model_tests:
61+
if model_test.backend == Backend.Xnnpack:
62+
test_model_xnnpack(model_test.model, quantize=False)
63+
else:
64+
raise RuntimeError(f"Unsupported backend {model_test.backend}.")
65+
66+
67+
if __name__ == "__main__":
68+
run_tests(
69+
model_tests=[
70+
ModelTest(
71+
model=Model.Mv3,
72+
backend=Backend.Xnnpack,
73+
),
74+
]
75+
)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
REM This is lightly modified from the torchvision Windows build logic.
2+
REM See https://github.com/pytorch/vision/blob/main/packaging/windows/internal/vc_env_helper.bat
3+
4+
@echo on
5+
6+
set VC_VERSION_LOWER=17
7+
set VC_VERSION_UPPER=18
8+
9+
for /f "usebackq tokens=*" %%i in (`"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -legacy -products * -version [%VC_VERSION_LOWER%^,%VC_VERSION_UPPER%^) -property installationPath`) do (
10+
if exist "%%i" if exist "%%i\VC\Auxiliary\Build\vcvarsall.bat" (
11+
set "VS15INSTALLDIR=%%i"
12+
set "VS15VCVARSALL=%%i\VC\Auxiliary\Build\vcvarsall.bat"
13+
goto vswhere
14+
)
15+
)
16+
17+
:vswhere
18+
if "%VSDEVCMD_ARGS%" == "" (
19+
call "%VS15VCVARSALL%" x64 || exit /b 1
20+
) else (
21+
call "%VS15VCVARSALL%" x64 %VSDEVCMD_ARGS% || exit /b 1
22+
)
23+
24+
@echo on
25+
26+
if "%CU_VERSION%" == "xpu" call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat"
27+
28+
set DISTUTILS_USE_SDK=1
29+
30+
set args=%1
31+
shift
32+
:start
33+
if [%1] == [] goto done
34+
set args=%args% %1
35+
shift
36+
goto start
37+
38+
:done
39+
if "%args%" == "" (
40+
echo Usage: vc_env_helper.bat [command] [args]
41+
echo e.g. vc_env_helper.bat cl /c test.cpp
42+
)
43+
44+
set work_dir=%CD%
45+
if exist setup.py (
46+
echo "Creating symlink..."
47+
REM Setup a symlink to shorten the path length.
48+
REM Note that the ET directory has to be named "executorch".
49+
cd %GITHUB_WORKSPACE%
50+
if not exist et\ (
51+
mkdir et
52+
)
53+
cd et
54+
echo Work dir: %work_dir%
55+
if not exist executorch\ (
56+
mklink /d executorch %work_dir%
57+
)
58+
cd executorch
59+
)
60+
61+
%args% || exit /b 1

0 commit comments

Comments
 (0)