Skip to content

Commit 245e9cb

Browse files
author
Github Executorch
committed
Update on "add begin/end to ExecuTorch pytree::arr"
Allows use of range-for. Differential Revision: [D68166302](https://our.internmc.facebook.com/intern/diff/D68166302/) [ghstack-poisoned]
2 parents 897b5fa + 3337fe5 commit 245e9cb

File tree

283 files changed

+8339
-2708
lines changed

Some content is hidden

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

283 files changed

+8339
-2708
lines changed

.buckconfig

+3
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,6 @@
3333
**/.git, \
3434
cmake-out, \
3535
pip-out
36+
37+
[buck2]
38+
restarter=true

.ci/docker/ci_commit_pins/pytorch.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0a94bb432ed75cc2d950d81b2921363218a7e459
1+
27e35de6c288bffad1b4d18b393579c1d1a95547

.ci/docker/conda-env-ci.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cmake=3.22.1
22
ninja=1.10.2
33
libuv
4+
llvm-openmp
45
pkg-config

.ci/scripts/gather_benchmark_configs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def set_output(name: str, val: Any) -> None:
238238
try:
239239
with open(github_output, "a") as env:
240240
env.write(f"{name}={val}\n")
241-
except PermissionError:
241+
except (PermissionError, FileNotFoundError):
242242
# Fall back to printing in case of permission error in unit tests
243243
print(f"::set-output name={name}::{val}")
244244

.ci/scripts/setup-linux.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,7 @@ fi
2323
# of nightly. This allows CI to test against latest commits from PyTorch
2424
install_executorch "use-pt-pinned-commit"
2525
build_executorch_runner "${BUILD_TOOL}"
26-
do_not_use_nightly_on_ci
26+
27+
if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
28+
do_not_use_nightly_on_ci
29+
fi

.ci/scripts/setup-macos.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ setup_macos_env_variables
121121
# NB: we need buck2 in all cases because cmake build also depends on calling
122122
# buck2 atm
123123
install_buck
124+
brew install libomp
124125
install_pip_dependencies
125126

126127
# TODO(huydhn): Unlike our self-hosted runner, GitHub runner doesn't have access
@@ -136,4 +137,7 @@ install_pytorch_and_domains
136137
# the pinned commit from PyTorch
137138
install_executorch "use-pt-pinned-commit"
138139
build_executorch_runner "${BUILD_TOOL}"
139-
do_not_use_nightly_on_ci
140+
141+
if [[ "${GITHUB_BASE_REF:-}" == *main* || "${GITHUB_BASE_REF:-}" == *gh* ]]; then
142+
do_not_use_nightly_on_ci
143+
fi

.github/workflows/doc-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ jobs:
8484
needs: build
8585
if: github.repository == 'pytorch/executorch' && github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
8686
permissions:
87+
id-token: write
8788
contents: write
88-
contents: read
8989
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
9090
with:
9191
repository: pytorch/executorch

.github/workflows/pull.yml

+2-17
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,14 @@ jobs:
212212
docker-image: executorch-ubuntu-22.04-clang12
213213
submodules: 'true'
214214
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
215-
timeout: 90
215+
timeout: 180
216216
script: |
217217
# The generic Linux job chooses to use base env, not the one setup by the image
218218
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
219219
conda activate "${CONDA_ENV}"
220220
221221
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
222222
223-
# install pybind
224-
bash install_executorch.sh --pybind xnnpack
225-
226223
# install Llava requirements
227224
bash examples/models/llama/install_requirements.sh
228225
bash examples/models/llava/install_requirements.sh
@@ -483,9 +480,6 @@ jobs:
483480
484481
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
485482
486-
# install pybind
487-
bash install_executorch.sh --pybind xnnpack
488-
489483
# install phi-3-mini requirements
490484
bash examples/models/phi-3-mini/install_requirements.sh
491485
@@ -513,9 +507,6 @@ jobs:
513507
514508
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
515509
516-
# install pybind
517-
bash install_executorch.sh --pybind xnnpack
518-
519510
# install llama requirements
520511
bash examples/models/llama/install_requirements.sh
521512
@@ -535,17 +526,14 @@ jobs:
535526
docker-image: executorch-ubuntu-22.04-clang12
536527
submodules: 'true'
537528
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
538-
timeout: 90
529+
timeout: 180
539530
script: |
540531
# The generic Linux job chooses to use base env, not the one setup by the image
541532
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
542533
conda activate "${CONDA_ENV}"
543534
544535
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
545536
546-
# install pybind
547-
bash install_executorch.sh --pybind xnnpack
548-
549537
# install llama requirements
550538
bash examples/models/llama/install_requirements.sh
551539
@@ -573,9 +561,6 @@ jobs:
573561
574562
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-linux.sh "cmake"
575563
576-
# install pybind
577-
bash install_executorch.sh --pybind xnnpack
578-
579564
# install llama requirements
580565
bash examples/models/llama/install_requirements.sh
581566

.github/workflows/trunk.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ jobs:
150150
conda activate "${CONDA_ENV}"
151151
152152
source .ci/scripts/utils.sh
153-
install_executorch
153+
install_executorch "use-pt-pinned-commit"
154154
155155
.ci/scripts/setup-arm-baremetal-tools.sh
156156
@@ -180,7 +180,7 @@ jobs:
180180
conda activate "${CONDA_ENV}"
181181
182182
source .ci/scripts/utils.sh
183-
install_executorch
183+
install_executorch "use-pt-pinned-commit"
184184
185185
.ci/scripts/setup-arm-baremetal-tools.sh
186186

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,6 @@
6464
[submodule "third-party/ao"]
6565
path = third-party/ao
6666
url = https://github.com/pytorch/ao.git
67+
[submodule "backends/cadence/utils/FACTO"]
68+
path = backends/cadence/utils/FACTO
69+
url = https://github.com/pytorch-labs/FACTO.git

.lintrunner.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
merge_base_with = "origin/main"
1+
merge_base_with = "main"
22

33
[[linter]]
44
code = 'FLAKE8'

.mypy.ini

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ ignore_missing_imports = True
7777
[mypy-ruamel]
7878
ignore_missing_imports = True
7979

80+
[mypy-serializer.*]
81+
ignore_missing_imports = True
82+
8083
[mypy-setuptools.*]
8184
ignore_missing_imports = True
8285

CMakeLists.txt

+36
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,13 @@ cmake_dependent_option(
240240
"NOT EXECUTORCH_BUILD_ARM_BAREMETAL" OFF
241241
)
242242

243+
244+
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
245+
set(EXECUTORCH_BUILD_EXTENSION_TENSOR ON)
246+
set(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER ON)
247+
set(EXECUTORCH_BUILD_EXTENSION_MODULE ON)
248+
endif()
249+
243250
if(EXECUTORCH_BUILD_KERNELS_CUSTOM_AOT)
244251
set(EXECUTORCH_BUILD_EXTENSION_TENSOR ON)
245252
set(EXECUTORCH_BUILD_KERNELS_CUSTOM ON)
@@ -791,6 +798,35 @@ if(EXECUTORCH_BUILD_PYBIND)
791798
install(TARGETS portable_lib
792799
LIBRARY DESTINATION executorch/extension/pybindings
793800
)
801+
802+
if(EXECUTORCH_BUILD_EXTENSION_TRAINING)
803+
804+
set(_pybind_training_dep_libs
805+
${TORCH_PYTHON_LIBRARY}
806+
etdump
807+
executorch
808+
util
809+
torch
810+
extension_training
811+
)
812+
813+
if(EXECUTORCH_BUILD_XNNPACK)
814+
# need to explicitly specify XNNPACK and microkernels-prod
815+
# here otherwise uses XNNPACK and microkernel-prod symbols from libtorch_cpu
816+
list(APPEND _pybind_training_dep_libs xnnpack_backend XNNPACK microkernels-prod)
817+
endif()
818+
819+
# pybind training
820+
pybind11_add_module(_training_lib SHARED extension/training/pybindings/_training_lib.cpp)
821+
822+
target_include_directories(_training_lib PRIVATE ${TORCH_INCLUDE_DIRS})
823+
target_compile_options(_training_lib PUBLIC ${_pybind_compile_options})
824+
target_link_libraries(_training_lib PRIVATE ${_pybind_training_dep_libs})
825+
826+
install(TARGETS _training_lib
827+
LIBRARY DESTINATION executorch/extension/training/pybindings
828+
)
829+
endif()
794830
endif()
795831

796832
if(EXECUTORCH_BUILD_KERNELS_CUSTOM)

README-wheel.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ standard on-device iOS and Android mobile deployments. One of the main goals for
44
ExecuTorch is to enable wider customization and deployment capabilities of the
55
PyTorch programs.
66

7-
The `executorch` pip package is in alpha.
8-
* Supported python versions: 3.10, 3.11
7+
The `executorch` pip package is in beta.
8+
* Supported python versions: 3.10, 3.11, 3.12
99
* Compatible systems: Linux x86_64, macOS aarch64
1010

11-
The prebuilt `executorch.extension.pybindings.portable_lib` module included in
12-
this package provides a way to run ExecuTorch `.pte` files, with some
13-
restrictions:
11+
The prebuilt `executorch.runtime` module included in this package provides a way
12+
to run ExecuTorch `.pte` files, with some restrictions:
1413
* Only [core ATen
1514
operators](https://pytorch.org/executorch/stable/ir-ops-set-definition.html)
1615
are linked into the prebuilt module
1716
* Only the [XNNPACK backend
1817
delegate](https://pytorch.org/executorch/main/native-delegates-executorch-xnnpack-delegate.html)
19-
is linked into the prebuilt module
20-
* [macOS only] [Core ML](https://pytorch.org/executorch/main/build-run-coreml.html) and [MPS](https://pytorch.org/executorch/main/build-run-mps.html) backend delegates are linked into the prebuilt module.
18+
is linked into the prebuilt module.
19+
* \[macOS only] [Core ML](https://pytorch.org/executorch/main/build-run-coreml.html)
20+
and [MPS](https://pytorch.org/executorch/main/build-run-mps.html) backend
21+
delegates are also linked into the prebuilt module.
2122

2223
Please visit the [ExecuTorch website](https://pytorch.org/executorch/) for
2324
tutorials and documentation. Here are some starting points:

README.md

+42-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1-
# ExecuTorch
2-
3-
**ExecuTorch** is an end-to-end solution for enabling on-device inference
4-
capabilities across mobile and edge devices including wearables, embedded
5-
devices and microcontrollers. It is part of the PyTorch Edge ecosystem and
6-
enables efficient deployment of PyTorch models to edge devices.
1+
<div align="center">
2+
<img src="./docs/source/_static/img/et-logo.png" alt="Logo" width="200">
3+
<h1 align="center">ExecuTorch: A powerful on-device AI Framework</h1>
4+
</div>
5+
6+
7+
<div align="center">
8+
<a href="https://github.com/pytorch/executorch/graphs/contributors"><img src="https://img.shields.io/github/contributors/pytorch/executorch?style=for-the-badge&color=blue" alt="Contributors"></a>
9+
<a href="https://github.com/pytorch/executorch/stargazers"><img src="https://img.shields.io/github/stars/pytorch/executorch?style=for-the-badge&color=blue" alt="Stargazers"></a>
10+
<a href="https://discord.gg/MeacgB7A"><img src="https://img.shields.io/badge/Discord-Join%20Us-purple?logo=discord&logoColor=white&style=for-the-badge" alt="Join our Discord community"></a>
11+
<a href="https://pytorch.org/executorch/stable/index.html"><img src="https://img.shields.io/badge/Documentation-000?logo=googledocs&logoColor=FFE165&style=for-the-badge" alt="Check out the documentation"></a>
12+
<hr>
13+
</div>
14+
15+
**ExecuTorch** is an end-to-end solution for on-device inference and training. It powers much of Meta's on-device AI experiences across Facebook, Instagram, Meta Quest, Ray-Ban Meta Smart Glasses, WhatsApp, and more.
16+
17+
It supports a wide range of models including LLMs (Large Language Models), CV (Computer Vision), ASR (Automatic Speech Recognition), and TTS (Text to Speech).
18+
19+
Platform Support:
20+
- Operating Systems:
21+
- iOS
22+
- Mac
23+
- Android
24+
- Linux
25+
- Microcontrollers
26+
27+
- Hardware Acceleration:
28+
- Apple
29+
- Arm
30+
- Cadence
31+
- MediaTek
32+
- Qualcomm
33+
- Vulkan
34+
- XNNPACK
735

836
Key value propositions of ExecuTorch are:
937

@@ -17,35 +45,21 @@ Key value propositions of ExecuTorch are:
1745
experience due to a lightweight runtime and utilizing full hardware
1846
capabilities such as CPUs, NPUs, and DSPs.
1947

20-
For a comprehensive technical overview of ExecuTorch and step-by-step tutorials,
21-
please visit our documentation website [for the latest release](https://pytorch.org/executorch/stable/index.html) (or the [main branch](https://pytorch.org/executorch/main/index.html)).
22-
23-
Check out the [Getting Started](https://pytorch.org/executorch/stable/getting-started-setup.html#quick-setup-colab-jupyter-notebook-prototype) page for a quick spin.
24-
25-
Check out the examples of [Llama](./examples/models/llama/README.md), [Llava](./examples/models/llava/README.md) and [other models](./examples/README.md) running on edge devices using ExecuTorch.
48+
## Getting Started
49+
To get started you can:
2650

51+
- Visit the [Step by Step Tutorial](https://pytorch.org/executorch/main/index.html) on getting things running locally and deploy a model to a device
52+
- Use this [Colab Notebook](https://pytorch.org/executorch/stable/getting-started-setup.html#quick-setup-colab-jupyter-notebook-prototype) to start playing around right away
53+
- Jump straight into LLMs use cases by following specific instructions for [Llama](./examples/models/llama/README.md) and [Llava](./examples/models/llava/README.md)
2754

28-
**[UPDATE - 10/24]** We have added support for running [Llama 3.2 Quantized 1B/3B](./examples/models/llama/README.md) models via ExecuTorch.
29-
30-
## Feedback
55+
## Feedback and Engagement
3156

3257
We welcome any feedback, suggestions, and bug reports from the community to help
33-
us improve our technology. Please use the [PyTorch
34-
Forums](https://discuss.pytorch.org/c/executorch) for discussion and feedback
35-
about ExecuTorch using the **ExecuTorch** category, and our [GitHub
36-
repository](https://github.com/pytorch/executorch/issues) for bug reporting.
37-
38-
We recommend using the latest release tag from the
39-
[Releases](https://github.com/pytorch/executorch/releases) page when developing.
58+
us improve our technology. Check out the [Discussion Board](https://github.com/pytorch/executorch/discussions) or chat real time with us on [Discord](https://discord.gg/MeacgB7A)
4059

4160
## Contributing
4261

43-
See [CONTRIBUTING.md](CONTRIBUTING.md) for details about issues, PRs, code
44-
style, CI jobs, and other development topics.
45-
46-
To connect with us and other community members, we invite you to join PyTorch Slack community by filling out this [form](https://docs.google.com/forms/d/e/1FAIpQLSeADnUNW36fjKjYzyHDOzEB_abKQE9b6gqqW9NXse6O0MWh0A/viewform). Once you've joined, you can:
47-
* Head to the `#executorch-general` channel for general questions, discussion, and community support.
48-
* Join the `#executorch-contributors` channel if you're interested in contributing directly to project development.
62+
We welcome contributions. To get started review the [guidelines](CONTRIBUTING.md) and chat with us on [Discord](https://discord.gg/MeacgB7A)
4963

5064

5165
## Directory Structure

backends/arm/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ The you can run the tests with
122122
pytest -c /dev/null -v -n auto backends/arm/test --arm_run_corstoneFVP
123123
```
124124

125+
## Passes
126+
127+
With the default passes in the Arm Ethos-U backend, assuming the model lowers fully to the
128+
Ethos-U, the exported program is composed of a Quantize node, Ethos-U custom delegate
129+
and a Dequantize node. In some circumstances, you may want to feed quantized input to the Neural
130+
Network straight away, e.g. if you have a camera sensor outputting (u)int8 data and keep all the
131+
arithmetic of the application in the int8 domain. For these cases, you can apply the
132+
`exir/passes/quantize_io_pass.py`. See the unit test in `executorch/backends/arm/
133+
test/passes/test_ioquantization_pass.py`for an example how to feed quantized inputs and
134+
obtain quantized outputs.
135+
136+
125137
### Code coverage
126138

127139
To get code coverage:

backends/arm/_passes/_debug_passes.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
import torch
7+
from executorch.devtools.visualization.visualization_utils import visualize_graph
8+
from executorch.exir import ExportedProgram
9+
from executorch.exir.pass_base import ExportPass, PassResult
10+
11+
12+
class VisualizePass(ExportPass):
13+
"""
14+
This pass visualizes the graph at the point of insertion in the pass manager
15+
"""
16+
17+
def __init__(self, exported_program: ExportedProgram) -> None:
18+
super().__init__()
19+
self.exported_program = exported_program
20+
21+
def call(self, graph_module: torch.fx.GraphModule) -> PassResult:
22+
visualize_graph(graph_module, self.exported_program)
23+
return PassResult(graph_module, False)

backends/arm/_passes/annotate_channels_last_dim_order_pass.py

+4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def insert_input_transpose(node, input_node, graph_module):
129129
permute_node.meta["tosa_dim_order"] = tuple(
130130
range(len(input_node.meta["val"].size()))
131131
)
132+
permute_node.meta["val"] = input_node.meta["val"]
132133

133134
@staticmethod
134135
def insert_output_transpose(node, graph_module):
@@ -141,6 +142,9 @@ def insert_output_transpose(node, graph_module):
141142
permute_node.meta["tosa_dim_order"] = (
142143
AnnotateChannelsLastDimOrder.NHWC_order
143144
)
145+
permute_node.meta["val"] = node.meta["val"].permute(
146+
AnnotateChannelsLastDimOrder.NHWC_order
147+
)
144148
node.meta["tosa_dim_order"] = (0, 1, 2, 3)
145149
users = [user for user in node.users if user != permute_node]
146150
for user in users:

0 commit comments

Comments
 (0)