Skip to content

Commit 389ba62

Browse files
authored
Merge branch 'main' into Arm-backend-Update-weight-observer-for-QAT
2 parents 21b28c1 + 0cac45b commit 389ba62

File tree

310 files changed

+7940
-5017
lines changed

Some content is hidden

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

310 files changed

+7940
-5017
lines changed

.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 {

.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: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,38 @@ set -euxo pipefail
99

1010
# This script is run before building ExecuTorch binaries
1111

12+
if [[ "$(uname -m)" == "aarch64" ]]; then
13+
# On some Linux aarch64 systems, the "atomic" library is not found during linking.
14+
# To work around this, replace "atomic" with the literal ${ATOMIC_LIB} so the
15+
# build system uses the full path to the atomic library.
16+
file="extension/llm/tokenizers/third-party/sentencepiece/src/CMakeLists.txt"
17+
sed 's/list(APPEND SPM_LIBS "atomic")/list(APPEND SPM_LIBS ${ATOMIC_LIB})/' \
18+
"$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
19+
20+
grep -n 'list(APPEND SPM_LIBS ${ATOMIC_LIB})' "$file" && \
21+
echo "the file $file has been modified for atomic to use full path"
22+
fi
23+
24+
# Clone nested submodules for tokenizers - this is a workaround for recursive
25+
# submodule clone failing due to path length limitations on Windows. Eventually,
26+
# we should update the core job in test-infra to enable long paths before
27+
# checkout to avoid needing to do this.
28+
pushd extension/llm/tokenizers
29+
git submodule update --init
30+
popd
31+
32+
# On Windows, enable symlinks and re-checkout the current revision to create
33+
# the symlinked src/ directory. This is needed to build the wheel.
34+
UNAME_S=$(uname -s)
35+
if [[ $UNAME_S == *"MINGW"* || $UNAME_S == *"MSYS"* ]]; then
36+
echo "Enabling symlinks on Windows"
37+
git config core.symlinks true
38+
git checkout -f HEAD
39+
fi
40+
1241
# Manually install build requirements because `python setup.py bdist_wheel` does
1342
# not install them. TODO(dbort): Switch to using `python -m build --wheel`,
1443
# which does install them. Though we'd need to disable build isolation to be
1544
# able to see the installed torch package.
1645

17-
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh" --example
46+
"${GITHUB_WORKSPACE}/${REPOSITORY}/install_requirements.sh" --example
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
import test_base
9+
from examples.models import Backend, Model
10+
11+
if __name__ == "__main__":
12+
# coremltools does not support linux aarch64 yet and install from the source fails on runtime
13+
# https://github.com/apple/coremltools/issues/1254
14+
# https://github.com/apple/coremltools/issues/2195
15+
test_base.run_tests(
16+
model_tests=[
17+
test_base.ModelTest(
18+
model=Model.Mv3,
19+
backend=Backend.XnnpackQuantizationDelegation,
20+
),
21+
]
22+
)

.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
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# From https://github.com/pytorch/test-infra/wiki/Using-Nova-Reusable-Build-Workflows
2+
name: Build Aarch64 Linux Wheels
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- .ci/**/*
8+
- .github/workflows/build-wheels-aarch64-linux.yml
9+
- examples/**/*
10+
- pyproject.toml
11+
- setup.py
12+
tags:
13+
- ciflow/binaries/*
14+
push:
15+
branches:
16+
- nightly
17+
- release/*
18+
tags:
19+
# NOTE: Binary build pipelines should only get triggered on release candidate builds
20+
# Release candidate tags look like: v1.11.0-rc1
21+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
22+
- ciflow/binaries/*
23+
workflow_dispatch:
24+
25+
jobs:
26+
generate-matrix:
27+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
28+
with:
29+
package-type: wheel
30+
os: linux-aarch64
31+
test-infra-repository: pytorch/test-infra
32+
test-infra-ref: main
33+
with-cuda: disabled
34+
with-rocm: disabled
35+
python-versions: '["3.10", "3.11", "3.12"]'
36+
37+
build:
38+
needs: generate-matrix
39+
permissions:
40+
id-token: write
41+
contents: read
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- repository: pytorch/executorch
47+
pre-script: .ci/scripts/wheel/pre_build_script.sh
48+
post-script: .ci/scripts/wheel/post_build_script.sh
49+
smoke-test-script: .ci/scripts/wheel/test_linux_aarch64.py
50+
package-name: executorch
51+
name: ${{ matrix.repository }}
52+
uses: pytorch/test-infra/.github/workflows/build_wheels_linux.yml@main
53+
with:
54+
repository: ${{ matrix.repository }}
55+
ref: ""
56+
test-infra-repository: pytorch/test-infra
57+
test-infra-ref: main
58+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
59+
submodules: recursive
60+
env-var-script: .ci/scripts/wheel/envvar_linux.sh
61+
pre-script: ${{ matrix.pre-script }}
62+
post-script: ${{ matrix.post-script }}
63+
package-name: ${{ matrix.package-name }}
64+
smoke-test-script: ${{ matrix.smoke-test-script }}
65+
trigger-event: ${{ github.event_name }}
66+
architecture: aarch64
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Build Windows Wheels
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- nightly
8+
- main
9+
- release/*
10+
tags:
11+
# NOTE: Binary build pipelines should only get triggered on release candidate builds
12+
# Release candidate tags look like: v1.11.0-rc1
13+
- v[0-9]+.[0-9]+.[0-9]+-rc[0-9]+
14+
workflow_dispatch:
15+
16+
permissions:
17+
id-token: write
18+
contents: read
19+
20+
jobs:
21+
generate-matrix:
22+
uses: pytorch/test-infra/.github/workflows/generate_binary_build_matrix.yml@main
23+
with:
24+
package-type: wheel
25+
os: windows
26+
test-infra-repository: pytorch/test-infra
27+
test-infra-ref: main
28+
with-cuda: disabled
29+
with-rocm: disabled
30+
python-versions: '["3.10", "3.11", "3.12"]'
31+
32+
build:
33+
needs: generate-matrix
34+
strategy:
35+
fail-fast: false
36+
matrix:
37+
include:
38+
- repository: pytorch/executorch
39+
pre-script: .ci\\scripts\\wheel\\pre_build_script.sh
40+
env-script: .ci\\scripts\\wheel\\vc_env_helper.bat
41+
post-script: .ci\\scripts\\wheel\\post_build_script.sh
42+
smoke-test-script: .ci/scripts/wheel/test_windows.py
43+
package-name: executorch
44+
name: ${{ matrix.repository }}
45+
uses: pytorch/test-infra/.github/workflows/build_wheels_windows.yml@main
46+
with:
47+
repository: ${{ matrix.repository }}
48+
ref: ""
49+
test-infra-repository: pytorch/test-infra
50+
test-infra-ref: main
51+
build-matrix: ${{ needs.generate-matrix.outputs.matrix }}
52+
pre-script: ${{ matrix.pre-script }}
53+
env-script: ${{ matrix.env-script }}
54+
post-script: ${{ matrix.post-script }}
55+
package-name: ${{ matrix.package-name }}
56+
smoke-test-script: ${{ matrix.smoke-test-script }}
57+
trigger-event: ${{ github.event_name }}
58+
wheel-build-params: "--verbose"
59+
submodules: true

.github/workflows/pull.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ jobs:
874874
contents: read
875875
with:
876876
runner: linux.2xlarge
877-
docker-image: ci-image:executorch-ubuntu-22.04-gcc9
877+
docker-image: ci-image:executorch-ubuntu-22.04-clang12-android
878878
submodules: 'recursive'
879879
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
880880
timeout: 90
@@ -892,7 +892,7 @@ jobs:
892892
source .ci/scripts/setup-samsung-linux-deps.sh
893893
894894
# Test models serially
895-
models="mv2 ic3 resnet18 resnet50"
895+
models="mv2 ic3 resnet18 resnet50 mv3 ic4 dl3 edsr vit w2l"
896896
for model in $models; do
897897
python -m executorch.examples.samsung.aot_compiler --model_name=$model -c E9955
898898
done

0 commit comments

Comments
 (0)