Skip to content

Commit de9d52f

Browse files
committed
Update
[ghstack-poisoned]
2 parents 946f2e0 + e6f66ab commit de9d52f

File tree

231 files changed

+7254
-133163
lines changed

Some content is hidden

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

231 files changed

+7254
-133163
lines changed

.ci/scripts/setup-openvino.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
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+
set -ex
9+
10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
13+
git clone https://github.com/openvinotoolkit/openvino.git
14+
cd openvino && git checkout releases/2025/1
15+
git submodule update --init --recursive
16+
sudo ./install_build_dependencies.sh
17+
mkdir build && cd build
18+
cmake .. -DCMAKE_BUILD_TYPE=Release -DENABLE_PYTHON=ON
19+
make -j$(nproc)
20+
21+
cd ..
22+
cmake --install build --prefix dist
23+
24+
source dist/setupvars.sh
25+
cd ../backends/openvino
26+
pip install -r requirements.txt
27+
cd scripts
28+
./openvino_build.sh --enable_python

.ci/scripts/test_llama.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ $PYTHON_EXECUTABLE -m examples.models.llama.export_llama ${EXPORT_ARGS}
269269

270270
# Create tokenizer.bin.
271271
echo "Creating tokenizer.bin"
272-
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
272+
$PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
273273

274274

275275
RUNTIME_ARGS="--model_path=${EXPORTED_MODEL_NAME} --tokenizer_path=tokenizer.bin --prompt=Once --temperature=0 --seq_len=10 --warmup=1"

.ci/scripts/test_llama_torchao_lowbit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ cmake --build cmake-out/examples/models/llama -j16 --config Release
5555
download_stories_model_artifacts
5656

5757
echo "Creating tokenizer.bin"
58-
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
58+
$PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
5959

6060
# Export model
6161
LLAMA_CHECKPOINT=stories110M.pt

.ci/scripts/test_openvino.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
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+
set -ex
9+
10+
# shellcheck source=/dev/null
11+
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
12+
13+
source openvino/dist/setupvars.sh
14+
cd backends/openvino/tests
15+
python test_runner.py --test_type ops
16+
python test_runner.py --test_type models

.ci/scripts/test_phi_3_mini.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ cmake_build_phi_3_mini() {
5656
prepare_tokenizer() {
5757
echo "Downloading and converting tokenizer.model"
5858
wget -O tokenizer.model "https://huggingface.co/microsoft/Phi-3-mini-128k-instruct/resolve/main/tokenizer.model?download=true"
59-
$PYTHON_EXECUTABLE -m executorch.extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
59+
$PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
6060
}
6161

6262
# Export phi-3-mini model to pte

.ci/scripts/test_qnn_static_llama.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
77

8-
set -exu
8+
set -euxo pipefail
99

1010
source "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
1111

@@ -30,7 +30,7 @@ pip install graphviz
3030
# Download stories llama110m artifacts
3131
download_stories_model_artifacts
3232
echo "Creating tokenizer.bin"
33-
$PYTHON_EXECUTABLE -m extension.llm.tokenizer.tokenizer -t tokenizer.model -o tokenizer.bin
33+
$PYTHON_EXECUTABLE -m pytorch_tokenizers.tools.llama2c.convert -t tokenizer.model -o tokenizer.bin
3434

3535
set +e
3636
# Compile only as weight sharing is not applicable on x86
@@ -56,4 +56,3 @@ if [ $exit_code1 -ne 0 ] || [ $exit_code2 -ne 0 ]; then
5656
else
5757
exit 0
5858
fi
59-
set -e

.ci/scripts/utils.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ install_executorch() {
3232
which pip
3333
# Install executorch, this assumes that Executorch is checked out in the
3434
# current directory.
35-
./install_executorch.sh --pybind xnnpack "$@"
35+
./install_executorch.sh "$@"
3636
# Just print out the list of packages for debugging
3737
pip list
3838
}

.github/workflows/apple.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
id: set_version
3838
shell: bash
3939
run: |
40-
VERSION="0.5.0.$(TZ='PST8PDT' date +%Y%m%d)"
40+
VERSION="0.7.0.$(TZ='PST8PDT' date +%Y%m%d)"
4141
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
4242
4343
build-demo-ios:

.github/workflows/pull.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,6 @@ jobs:
573573
574574
BUILD_TOOL="cmake"
575575
576-
./install_requirements.sh --use-pt-pinned-commit
577576
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-qnn-deps.sh
578577
PYTHON_EXECUTABLE=python bash .ci/scripts/build-qnn-sdk.sh
579578
@@ -736,3 +735,25 @@ jobs:
736735
conda activate "${CONDA_ENV}"
737736
738737
# placeholder for mediatek to add more tests
738+
739+
test-openvino-linux:
740+
name: test-openvino-linux
741+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
742+
permissions:
743+
id-token: write
744+
contents: read
745+
strategy:
746+
fail-fast: false
747+
with:
748+
runner: linux.2xlarge
749+
docker-image: executorch-ubuntu-22.04-gcc9
750+
submodules: 'true'
751+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
752+
timeout: 90
753+
script: |
754+
# The generic Linux job chooses to use base env, not the one setup by the image
755+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
756+
conda activate "${CONDA_ENV}"
757+
758+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-openvino.sh
759+
PYTHON_EXECUTABLE=python bash .ci/scripts/test_openvino.sh

.lintrunner.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ include_patterns = [
299299
# TODO(https://github.com/pytorch/executorch/issues/7441): Gradually start enabling all folders.
300300
# 'backends/**/*.py',
301301
'backends/arm/**/*.py',
302+
'backends/openvino/**/*.py',
302303
'build/**/*.py',
303304
'codegen/**/*.py',
304305
# 'devtools/**/*.py',
305306
'devtools/visualization/**/*.py',
306307
'docs/**/*.py',
307308
# 'examples/**/*.py',
309+
'examples/openvino/**/*.py',
308310
# 'exir/**/*.py',
309311
# 'extension/**/*.py',
310312
'kernels/**/*.py',

CMakeLists.txt

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ option(EXECUTORCH_BUILD_MPS "Build the MPS backend" OFF)
204204

205205
option(EXECUTORCH_BUILD_NEURON "Build the backends/mediatek directory" OFF)
206206

207+
option(EXECUTORCH_BUILD_OPENVINO "Build the Openvino backend" OFF)
208+
207209
option(EXECUTORCH_BUILD_PYBIND "Build the Python Bindings" OFF)
208210

209211
option(EXECUTORCH_BUILD_QNN "Build the Qualcomm backend" OFF)
@@ -720,6 +722,10 @@ if(EXECUTORCH_BUILD_NEURON)
720722
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/mediatek)
721723
endif()
722724

725+
if(EXECUTORCH_BUILD_OPENVINO)
726+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/openvino)
727+
endif()
728+
723729
if(EXECUTORCH_BUILD_QNN)
724730
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/qualcomm)
725731
endif()
@@ -756,17 +762,13 @@ if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR)
756762
endif()
757763

758764
if(EXECUTORCH_BUILD_EXTENSION_LLM)
759-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizer)
765+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers)
760766
endif()
761767

762768
if(EXECUTORCH_BUILD_EXTENSION_MODULE)
763769
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/module)
764770
endif()
765771

766-
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
767-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training)
768-
endif()
769-
770772
if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
771773
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util)
772774
endif()
@@ -822,6 +824,10 @@ if(EXECUTORCH_BUILD_PYBIND)
822824
list(APPEND _dep_libs mpsdelegate)
823825
endif()
824826

827+
if(EXECUTORCH_BUILD_OPENVINO)
828+
list(APPEND _dep_libs openvino_backend)
829+
endif()
830+
825831
if(EXECUTORCH_BUILD_XNNPACK)
826832
# need to explicitly specify XNNPACK and microkernels-prod
827833
# here otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
@@ -867,34 +873,13 @@ if(EXECUTORCH_BUILD_PYBIND)
867873

868874
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
869875

870-
set(_pybind_training_dep_libs
871-
${TORCH_PYTHON_LIBRARY}
872-
etdump
873-
executorch
874-
util
875-
torch
876-
extension_training
877-
)
878-
879-
if(EXECUTORCH_BUILD_XNNPACK)
880-
# need to explicitly specify XNNPACK and microkernels-prod
881-
# here otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
882-
list(APPEND _pybind_training_dep_libs xnnpack_backend XNNPACK microkernels-prod)
883-
endif()
884-
885-
# pybind training
886-
pybind11_add_module(_training_lib SHARED extension/training/pybindings/_training_lib.cpp)
887-
888-
target_include_directories(_training_lib PRIVATE ${TORCH_INCLUDE_DIRS})
889-
target_compile_options(_training_lib PUBLIC ${_pybind_compile_options})
890-
target_link_libraries(_training_lib PRIVATE ${_pybind_training_dep_libs})
891-
892-
install(TARGETS _training_lib
893-
LIBRARY DESTINATION executorch/extension/training/pybindings
894-
)
895876
endif()
896877
endif()
897878

879+
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
880+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training)
881+
endif()
882+
898883
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)
899884
# TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom
900885
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/custom_ops)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Platform Support:
2929
- Arm
3030
- Cadence
3131
- MediaTek
32+
- OpenVINO
3233
- Qualcomm
3334
- Vulkan
3435
- XNNPACK

backends/apple/coreml/scripts/install_requirements.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SCRIPT_DIR_PATH="$(
1212

1313
# TODO(jathu): remove the need to fetch coremltools to build deps for coreml_executor_runner.
1414
# Keep this version in sync with: pyproject.toml
15-
COREMLTOOLS_VERSION="8.1"
15+
COREMLTOOLS_VERSION="8.2"
1616

1717
red=`tput setaf 1`
1818
green=`tput setaf 2`

backends/arm/_passes/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from . import arm_pass_utils # noqa
88
from .annotate_channels_last_dim_order_pass import AnnotateChannelsLastDimOrder # noqa
99
from .annotate_decomposed_matmul import AnnotateDecomposedMatmulPass # noqa
10+
from .arm_pass import ArmPass # noqa
1011
from .cast_int64_pass import CastInt64BuffersToInt32Pass # noqa
1112
from .cast_to_int32_pass import CastToInt32Pass # noqa
1213
from .conv1d_unsqueeze_pass import Conv1dUnsqueezePass # noqa
@@ -41,6 +42,10 @@
4142
from .meandim_to_averagepool_pass import ConvertMeanDimToAveragePoolPass # noqa
4243
from .mm_to_bmm_pass import ConvertMmToBmmPass # noqa
4344
from .remove_clone_pass import RemoveClonePass # noqa
45+
from .replace_scalar_with_tensor_pass import ( # noqa
46+
ReplaceScalarWithTensorArgPassTOSABI,
47+
ReplaceScalarWithTensorArgPassTOSAMI,
48+
)
4449
from .scalars_to_attribute_pass import ScalarsToAttributePass # noqa
4550
from .size_adjust_conv2d_pass import SizeAdjustConv2DPass # noqa
4651
from .unsqueeze_before_repeat_pass import UnsqueezeBeforeRepeatPass # noqa

backends/arm/_passes/arm_pass.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Copyright 2025 Arm Limited and/or its affiliates.
2+
#
3+
# This source code is licensed under the BSD-style license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
# pyre-unsafe
7+
8+
import traceback
9+
from typing import Optional
10+
11+
import torch
12+
from executorch.exir.pass_base import ExportPass, NodeMetadata
13+
14+
15+
class ArmPass(ExportPass):
16+
"""Base class for Arm passes"""
17+
18+
def __init__(self, exported_program: Optional[torch.export.ExportedProgram] = None):
19+
super(ArmPass, self).__init__()
20+
self.exported_program = exported_program
21+
22+
def call_operator(self, op, args, kwargs, meta, updated: Optional[bool] = False):
23+
if not updated:
24+
return super().call_operator(op, args, kwargs, meta)
25+
26+
# if updated we should update metadata
27+
new_meta = {}
28+
keys = meta.data.keys()
29+
for key in keys:
30+
new_meta[key] = meta[key]
31+
old_stack_trace = new_meta.get("stack_trace", "")
32+
new_meta["stack_trace"] = f"{old_stack_trace}\n{traceback.format_stack()[-2]}"
33+
return super().call_operator(op, args, kwargs, NodeMetadata(new_meta))

backends/arm/_passes/arm_pass_manager.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,17 @@
4242
MatchArgRanksPass,
4343
QuantizeOperatorArguments,
4444
RemoveClonePass,
45+
ReplaceScalarWithTensorArgPassTOSABI,
46+
ReplaceScalarWithTensorArgPassTOSAMI,
4547
RetraceFoldedDtypesPass,
4648
ScalarsToAttributePass,
4749
SizeAdjustConv2DPass,
4850
UnsqueezeBeforeRepeatPass,
4951
UnsqueezeScalarPlaceholdersPass,
5052
)
53+
5154
from executorch.backends.arm.tosa_specification import Tosa_0_80, TosaSpecification
5255
from executorch.backends.transforms.fuse_view_copy import FuseViewCopyTransform
53-
54-
from executorch.backends.transforms.replace_scalar_with_tensor import (
55-
ReplaceScalarWithTensorArgPass,
56-
)
5756
from executorch.backends.xnnpack._passes.remove_getitem_op import RemoveGetItemPass
5857
from executorch.exir import ExportedProgram
5958
from executorch.exir.pass_manager import PassManager
@@ -84,7 +83,7 @@ def _tosa_080_BI_pipeline(self, exported_program: ExportedProgram) -> GraphModul
8483
if isinstance(self.tosa_spec, Tosa_0_80) and self.tosa_spec.is_U55_subset:
8584
self.add_pass(CastToInt32Pass())
8685

87-
self.add_pass(ReplaceScalarWithTensorArgPass())
86+
self.add_pass(ReplaceScalarWithTensorArgPassTOSABI())
8887
self.add_pass(AnnotateDecomposedMatmulPass())
8988
self.add_pass(QuantizeOperatorArguments())
9089
self.add_pass(FoldAndAnnotateQParamsPass()) # type: ignore[call-arg]
@@ -113,7 +112,7 @@ def _tosa_080_BI_pipeline(self, exported_program: ExportedProgram) -> GraphModul
113112
return self._transform(exported_program.graph_module)
114113

115114
def _tosa_080_MI_pipeline(self, exported_program: ExportedProgram) -> GraphModule:
116-
self.add_pass(ReplaceScalarWithTensorArgPass())
115+
self.add_pass(ReplaceScalarWithTensorArgPassTOSAMI())
117116
self.add_pass(FuseQuantizedActivationPass())
118117
self.add_pass(RemoveGetItemPass())
119118
self.add_pass(ConvertSplitToSlicePass())
@@ -170,7 +169,7 @@ def transform_to_backend_pipeline(self, exported_program: ExportedProgram):
170169
)
171170

172171
def transform_for_annotation_pipeline(self, graph_module: GraphModule):
173-
self.add_pass(ReplaceScalarWithTensorArgPass())
172+
self.add_pass(ReplaceScalarWithTensorArgPassTOSABI())
174173
self.add_pass(ScalarsToAttributePass())
175174
self.add_pass(DecomposeLayerNormPass())
176175
self.add_pass(DecomposeVarPass())

0 commit comments

Comments
 (0)