Skip to content

Commit e814bb7

Browse files
committed
Update on "[Executorch] Refactor op_mul's broadcasting utils"
Summary: Refactoring broadcast handling utils that were added for op_mul. This is in prepartion use these utils to handle broadcast for other ops such as add, sub, div. Plus remove a redundant test Test Plan: optimized_kernels_test in CI Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
2 parents 27a79c4 + cd9a0d7 commit e814bb7

File tree

130 files changed

+3320
-898
lines changed

Some content is hidden

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

130 files changed

+3320
-898
lines changed

.buckconfig

Lines changed: 3 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0a94bb432ed75cc2d950d81b2921363218a7e459
1+
27e35de6c288bffad1b4d18b393579c1d1a95547

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

Lines changed: 1 addition & 0 deletions
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/setup-linux.sh

Lines changed: 4 additions & 1 deletion
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

Lines changed: 5 additions & 1 deletion
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/pull.yml

Lines changed: 2 additions & 17 deletions
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 --use-pt-pinned-commit
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 --use-pt-pinned-commit
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 --use-pt-pinned-commit
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 --use-pt-pinned-commit
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 --use-pt-pinned-commit
578-
579564
# install llama requirements
580565
bash examples/models/llama/install_requirements.sh
581566

.gitmodules

Lines changed: 3 additions & 0 deletions
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

CMakeLists.txt

Lines changed: 36 additions & 0 deletions
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)

backends/arm/_passes/annotate_decomposed_matmul.py

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

7+
# pyre-unsafe
8+
79
import itertools
810

911
from typing import List

backends/arm/_passes/fold_qdq_with_annotated_qparams_pass.py

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

7+
# pyre-unsafe
8+
79
import copy
810

911
from typing import cast, Dict, Set, Tuple

backends/arm/_passes/fuse_batchnorm2d_pass.py

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

6+
# pyre-unsafe
7+
68
import torch
79
from executorch.exir import ExportedProgram
810
from executorch.exir.dialects._ops import ops as exir_ops

backends/arm/_passes/fuse_quantized_activation_pass.py

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

6+
# pyre-unsafe
7+
68
import torch
79
from executorch.backends.arm.tosa_quant_utils import q_op
810
from executorch.exir.dialects._ops import ops as exir_ops

backends/arm/_passes/insert_table_ops.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7+
# pyre-unsafe
8+
79
from typing import Callable, Dict
810

911
import torch
@@ -31,7 +33,7 @@ class InsertTableOpsPass(ExportPass):
3133
"""
3234
For ops in self.table_ops they need to be serialized as a TOSA TABLE. This pass replaces these
3335
edge ops with a tosa._table(input: Tensor, target_str: str) where target_str == str(node.target).
34-
When loweringthe _table node target_str will be used to find the corresponding torch operator
36+
When lowering the _table node target_str will be used to find the corresponding torch operator
3537
which will be used to produce the table values in operators/op_table.py.
3638
"""
3739

@@ -43,6 +45,7 @@ class InsertTableOpsPass(ExportPass):
4345
exir_ops.edge.aten.sigmoid.default: torch.sigmoid,
4446
exir_ops.edge.aten.tanh.default: torch.tanh,
4547
exir_ops.edge.aten.hardsigmoid.default: torch.nn.functional.hardsigmoid,
48+
exir_ops.edge.aten.hardswish.default: torch.nn.functional.hardswish,
4649
}
4750

4851
def __init__(self, exported_program: ExportedProgram) -> None:

backends/arm/_passes/mm_to_bmm_pass.py

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

7+
# pyre-unsafe
8+
79
import torch
810
from executorch.backends.arm._passes.arm_pass_utils import (
911
create_node,

backends/arm/arm_partitioner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def ops_to_not_decompose(
115115
) -> Tuple[List[torch._ops.OpOverload], Optional[Callable[[torch.fx.Node], bool]]]:
116116
ops_to_not_decompose_if_quant_op = [
117117
torch.ops.aten.hardsigmoid.default,
118+
torch.ops.aten.hardswish.default,
118119
]
119120

120121
def filter_fn(node: torch.fx.Node) -> bool:

backends/arm/operator_support/right_shift_support.py

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

6+
# pyre-unsafe
7+
68

79
import logging
810

backends/arm/operator_support/tosa_supported_operators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def is_node_supported(self, submodules, node: fx.Node) -> bool:
8181
exir_ops.edge.aten.permute_copy.default,
8282
exir_ops.edge.aten.hardsigmoid.default,
8383
exir_ops.edge.aten.hardtanh.default,
84+
exir_ops.edge.aten.hardswish.default,
8485
exir_ops.edge.aten.convolution.default,
8586
exir_ops.edge.aten.div.Tensor,
8687
exir_ops.edge.aten.eq.Tensor,

backends/arm/operators/op_clamp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree
66

7+
# pyre-unsafe
8+
79
from typing import Any, List, Tuple
810

911
import serializer.tosa_serializer as ts # type: ignore

backends/arm/operators/op_rshift.py

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

7+
# pyre-unsafe
8+
79
from typing import List
810

911
import serializer.tosa_serializer as ts # type: ignore

backends/arm/quantizer/quantization_annotator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def _match_pattern(
133133
torch.ops.aten.tanh.default,
134134
torch.ops.aten.sum.dim_IntList,
135135
torch.ops.aten.hardsigmoid.default,
136+
torch.ops.aten.hardswish.default,
136137
]
137138

138139
_one_to_one_shared_input_qspec = [

backends/arm/test/common.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,17 @@
99

1010
import tempfile
1111
from datetime import datetime
12+
1213
from pathlib import Path
14+
from typing import Any
1315

16+
import pytest
1417
from executorch.backends.arm.arm_backend import ArmCompileSpecBuilder
18+
from executorch.backends.arm.test.runner_utils import (
19+
arm_executor_runner_exists,
20+
corstone300_installed,
21+
corstone320_installed,
22+
)
1523
from executorch.backends.arm.tosa_specification import TosaSpecification
1624
from executorch.exir.backend.compile_spec_schema import CompileSpec
1725

@@ -145,3 +153,44 @@ def get_u85_compile_spec_unbuilt(
145153
.dump_intermediate_artifacts_to(artifact_path)
146154
)
147155
return compile_spec # type: ignore[return-value]
156+
157+
158+
SkipIfNoCorstone300 = pytest.mark.skipif(
159+
not corstone300_installed() or not arm_executor_runner_exists("corstone-300"),
160+
reason="Did not find Corstone-300 FVP or executor_runner on path",
161+
)
162+
"""Skips a test if Corsone300 FVP is not installed, or if the executor runner is not built"""
163+
164+
SkipIfNoCorstone320 = pytest.mark.skipif(
165+
not corstone320_installed() or not arm_executor_runner_exists("corstone-320"),
166+
reason="Did not find Corstone-320 FVP or executor_runner on path",
167+
)
168+
"""Skips a test if Corsone320 FVP is not installed, or if the executor runner is not built."""
169+
170+
171+
def parametrize(
172+
arg_name: str, test_data: dict[str, Any], xfails: dict[str, str] = None
173+
):
174+
"""
175+
Custom version of pytest.mark.parametrize with some syntatic sugar and added xfail functionality
176+
- test_data is expected as a dict of (id, test_data) pairs
177+
- alllows to specifiy a dict of (id, failure_reason) pairs to mark specific tests as xfail
178+
"""
179+
if xfails is None:
180+
xfails = {}
181+
182+
def decorator_func(func):
183+
"""Test data is transformed from a dict of (id, data) pairs to a list of pytest params to work with the native pytests parametrize function"""
184+
pytest_testsuite = []
185+
for id, test_parameters in test_data.items():
186+
if id in xfails:
187+
pytest_param = pytest.param(
188+
test_parameters, id=id, marks=pytest.mark.xfail(reason=xfails[id])
189+
)
190+
else:
191+
pytest_param = pytest.param(test_parameters, id=id)
192+
pytest_testsuite.append(pytest_param)
193+
194+
return pytest.mark.parametrize(arg_name, pytest_testsuite)(func)
195+
196+
return decorator_func

0 commit comments

Comments
 (0)