Skip to content

Commit 0b83772

Browse files
committed
Update on "[ExecuTorch] Arm Ethos: Buckify Linear operator tests"
As title. Differential Revision: [D70018299](https://our.internmc.facebook.com/intern/diff/D70018299/) [ghstack-poisoned]
2 parents 0106f26 + 5bd93d5 commit 0b83772

File tree

277 files changed

+6401
-1916
lines changed

Some content is hidden

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

277 files changed

+6401
-1916
lines changed

.ci/scripts/gather_test_models.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ def model_should_run_on_target_os(model: str, target_os: str) -> bool:
104104
For example, a big model can be disabled in macos due to the limited macos resources.
105105
"""
106106
if target_os == "macos":
107+
# Disabled in macos due to limited resources, and should stay that way even if
108+
# we otherwise re-enable.
107109
return model not in ["llava"]
108-
return True
110+
# Disabled globally because we have test-llava-runner-linux that does a more
111+
# comprehensive E2E test of llava.
112+
return model not in ["llava"]
109113

110114

111115
def export_models_for_ci() -> dict[str, dict]:

.ci/scripts/test_model.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,17 @@ test_model() {
9191
# Install requirements for llama vision.
9292
bash examples/models/llama3_2_vision/install_requirements.sh
9393
fi
94-
# python3 -m examples.portable.scripts.export --model_name="llama2" should works too
94+
if [[ "${MODEL_NAME}" == "qwen2_5" ]]; then
95+
# Install requirements for export_llama
96+
bash examples/models/llama/install_requirements.sh
97+
# Test export_llama script: python3 -m examples.models.llama.export_llama.
98+
# Use Llama random checkpoint with Qwen 2.5 1.5b model configuration.
99+
"${PYTHON_EXECUTABLE}" -m examples.models.llama.export_llama --model "${MODEL_NAME}" -c examples/models/llama/params/demo_rand_params.pth -p examples/models/qwen2_5/1_5b_config.json
100+
rm "./${MODEL_NAME}.pte"
101+
return # Skip running with portable executor runnner since portable doesn't support Qwen's biased linears.
102+
fi
103+
104+
# Export a basic .pte and run the model.
95105
"${PYTHON_EXECUTABLE}" -m examples.portable.scripts.export --model_name="${MODEL_NAME}" "${STRICT}"
96106
run_portable_executor_runner
97107
}

.ci/scripts/unittest-linux.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,26 @@ eval "$(conda shell.bash hook)"
2727
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
2828
conda activate "${CONDA_ENV}"
2929

30-
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
31-
source .ci/scripts/setup-vulkan-linux-deps.sh
30+
if [[ "$BUILD_TOOL" == "cmake" ]]; then
31+
# Setup swiftshader and Vulkan SDK which are required to build the Vulkan delegate
32+
source .ci/scripts/setup-vulkan-linux-deps.sh
3233

33-
PYTHON_EXECUTABLE=python \
34-
EXECUTORCH_BUILD_PYBIND=ON \
35-
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
36-
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
34+
PYTHON_EXECUTABLE=python \
35+
EXECUTORCH_BUILD_PYBIND=ON \
36+
CMAKE_ARGS="-DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
37+
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
3738

38-
# Install llama3_2_vision dependencies.
39-
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
39+
# Install llama3_2_vision dependencies.
40+
PYTHON_EXECUTABLE=python ./examples/models/llama3_2_vision/install_requirements.sh
4041

41-
if [[ "$BUILD_TOOL" == "cmake" ]]; then
4242
.ci/scripts/unittest-linux-cmake.sh
4343
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
44+
# Removing this breaks sccache in the Buck build, apparently
45+
# because TMPDIR gets messed up? Please feel free to fix this and
46+
# speed up this CI job!
47+
PYTHON_EXECUTABLE=python \
48+
.ci/scripts/setup-linux.sh "$BUILD_TOOL" "$BUILD_MODE"
49+
4450
.ci/scripts/unittest-buck2.sh
4551
else
4652
echo "Unknown build tool $BUILD_TOOL"

.ci/scripts/unittest-macos.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ export TMP_DIR=$(mktemp -d)
3030
export PATH="${TMP_DIR}:$PATH"
3131
trap 'rm -rfv ${TMP_DIR}' EXIT
3232

33-
# Setup MacOS dependencies as there is no Docker support on MacOS atm
34-
PYTHON_EXECUTABLE=python \
35-
EXECUTORCH_BUILD_PYBIND=ON \
36-
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
37-
${CONDA_RUN} --no-capture-output \
38-
.ci/scripts/setup-macos.sh "${BUILD_TOOL}" "${BUILD_MODE}"
33+
if [[ "$BUILD_TOOL" == "cmake" ]]; then
34+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
35+
PYTHON_EXECUTABLE=python \
36+
EXECUTORCH_BUILD_PYBIND=ON \
37+
CMAKE_ARGS="-DEXECUTORCH_BUILD_COREML=ON -DEXECUTORCH_BUILD_MPS=ON -DEXECUTORCH_BUILD_XNNPACK=ON -DEXECUTORCH_BUILD_KERNELS_QUANTIZED=ON" \
38+
${CONDA_RUN} --no-capture-output \
39+
.ci/scripts/setup-macos.sh "${BUILD_TOOL}" "${BUILD_MODE}"
3940

40-
# Install llama3_2_vision dependencies.
41-
PYTHON_EXECUTABLE=python \
42-
${CONDA_RUN} --no-capture-output \
43-
./examples/models/llama3_2_vision/install_requirements.sh
41+
# Install llama3_2_vision dependencies.
42+
PYTHON_EXECUTABLE=python \
43+
${CONDA_RUN} --no-capture-output \
44+
./examples/models/llama3_2_vision/install_requirements.sh
4445

45-
if [[ "$BUILD_TOOL" == "cmake" ]]; then
4646
.ci/scripts/unittest-macos-cmake.sh
4747
elif [[ "$BUILD_TOOL" == "buck2" ]]; then
4848
.ci/scripts/unittest-buck2.sh

.github/workflows/pull.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,30 @@ jobs:
5656
# Build and test ExecuTorch with the add model on portable backend.
5757
PYTHON_EXECUTABLE=python bash .ci/scripts/test_model.sh "add" "${BUILD_TOOL}" "portable"
5858
59+
test-pip-install-editable-mode-linux:
60+
name: test-pip-install-editable-mode-linux
61+
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
62+
permissions:
63+
id-token: write
64+
contents: read
65+
strategy:
66+
fail-fast: false
67+
with:
68+
runner: linux.2xlarge
69+
docker-image: executorch-ubuntu-22.04-clang12
70+
submodules: 'true'
71+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
72+
timeout: 90
73+
script: |
74+
# The generic Linux job chooses to use base env, not the one setup by the image
75+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
76+
conda activate "${CONDA_ENV}"
77+
# Debug
78+
which pip
79+
PYTHON_EXECUTABLE=python bash ./install_executorch.sh --editable --pybind xnnpack --use-pt-pinned-commit
80+
# Try to import extension library
81+
python -c "from executorch.extension.llm.custom_ops import custom_ops"
82+
5983
test-models-linux:
6084
name: test-models-linux
6185
uses: pytorch/test-infra/.github/workflows/linux_job_v2.yml@main
@@ -480,7 +504,7 @@ jobs:
480504
481505
# Setup install_requirements for llama
482506
PYTHON_EXECUTABLE=python bash examples/models/llama/install_requirements.sh
483-
507+
484508
# Test static llama weight sharing and accuracy
485509
PYTHON_EXECUTABLE=python bash .ci/scripts/test_qnn_static_llama.sh
486510

.github/workflows/trunk.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,31 @@ jobs:
3636
3737
PYTHONPATH="${PWD}" python .ci/scripts/gather_test_models.py --target-os macos --event "${GITHUB_EVENT_NAME}"
3838
39+
test-pip-install-editable-mode-macos:
40+
name: test-pip-install-editable-mode-macos
41+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
42+
permissions:
43+
id-token: write
44+
contents: read
45+
strategy:
46+
fail-fast: false
47+
with:
48+
runner: macos-m1-stable
49+
python-version: '3.11'
50+
submodules: 'true'
51+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
52+
timeout: 90
53+
script: |
54+
# The generic Linux job chooses to use base env, not the one setup by the image
55+
CONDA_ENV=$(conda env list --json | jq -r ".envs | .[-1]")
56+
conda activate "${CONDA_ENV}"
57+
# Debug
58+
which pip
59+
bash .ci/scripts/setup-conda.sh
60+
PYTHON_EXECUTABLE=python ${CONDA_RUN} bash ./install_executorch.sh --editable --pybind xnnpack
61+
# Try to import extension library
62+
python -c "from executorch.extension.llm.custom_ops import custom_ops"
63+
3964
test-models-macos:
4065
name: test-models-macos
4166
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@
7070
[submodule "third-party/pocketfft"]
7171
path = third-party/pocketfft
7272
url = https://github.com/mreineck/pocketfft
73+
[submodule "shim"]
74+
path = shim
75+
url = https://github.com/facebook/buck2-shims-meta

CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
/examples/llm_manual @larryliu0820
3333
/examples/llm_pte_finetuning @JacobSzwejbka
3434
/examples/mediatek @cccclai
35-
/examples/models @lucylq
35+
/examples/models @lucylq @jackzhxng
3636
/examples/portable @larryliu0820 @manuelcandales
3737
/examples/qualcomm @cccclai
3838
/examples/selective_build @lucylq @larryliu0820 @JacobSzwejbka

backends/arm/arm_vela.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@
1212
from typing import List
1313

1414
import numpy as np
15-
from ethosu.vela import vela # type: ignore
15+
16+
try:
17+
from ethosu.vela import vela # type: ignore
18+
19+
has_vela = True
20+
except ImportError:
21+
has_vela = False
1622

1723

1824
# Pack either input or output tensor block, compose the related arrays into
@@ -45,6 +51,11 @@ def vela_compile(
4551
"""
4652
Compile a TOSA graph to a binary stream for ArmBackendEthosU using Vela.
4753
"""
54+
if not has_vela:
55+
raise RuntimeError(
56+
"ethos-u-vela pip package couldn't be imported. Make sure it's installed!"
57+
)
58+
4859
with tempfile.TemporaryDirectory() as tmpdir:
4960
tosaname = "out.tosa"
5061
tosa_path = os.path.join(tmpdir, tosaname)

backends/arm/operator_support/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
# pyre-unsafe
77

88
from . import ( # noqa
9-
bitwise_support,
109
convolution_support,
1110
pool_2d_support,
1211
reduce_sum_support,

backends/arm/operator_support/bitwise_support.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

backends/arm/operator_support/tosa_supported_operators.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
from typing import final, Optional, Sequence, Type
1212

1313
import torch
14-
1514
import torch.fx as fx
15+
1616
from executorch.backends.arm._passes.arm_pass_utils import get_first_fake_tensor
1717
from executorch.backends.arm._passes.fuse_quantized_activation_pass import (
1818
FuseQuantizedActivationPass,
1919
)
20-
from executorch.backends.arm.tosa_specification import TosaSpecification
20+
from executorch.backends.arm.tosa_specification import Tosa_0_80, TosaSpecification
2121
from executorch.exir.dialects._ops import ops as exir_ops
2222
from torch.fx.passes.operator_support import any_chain, chain, OperatorSupportBase
2323
from torch.fx.passes.utils.source_matcher_utils import get_source_partitions
@@ -90,6 +90,7 @@ def tosa_support_factory(
9090
if not tosa_spec.support_float():
9191
negative_checks.append(NeedsDecompositionCheck())
9292
negative_checks.append(CheckProperQuantization())
93+
negative_checks.append(EthosU55NotSupported(tosa_spec))
9394
return chain(
9495
any_chain(
9596
BaseTOSASupportList(),
@@ -111,6 +112,9 @@ def is_node_supported(
111112
supported = node.op == "call_function" and node.target in [
112113
exir_ops.edge.aten.abs.default,
113114
exir_ops.edge.aten.add.Tensor,
115+
exir_ops.edge.aten.bitwise_and.Tensor,
116+
exir_ops.edge.aten.bitwise_or.Tensor,
117+
exir_ops.edge.aten.bitwise_xor.Tensor,
114118
exir_ops.edge.aten.expand_copy.default,
115119
exir_ops.edge.aten.cat.default,
116120
exir_ops.edge.aten.clamp.default,
@@ -170,6 +174,31 @@ def is_node_supported(
170174
return supported
171175

172176

177+
class EthosU55NotSupported(OperatorSupportBase):
178+
"""
179+
Certain operators are not supported on U55. These are listed in `unsupported` in
180+
is_node_supported().
181+
"""
182+
183+
def __init__(self, tosa_spec: TosaSpecification):
184+
self.tosa_spec = tosa_spec
185+
186+
def is_node_supported(
187+
self, submodules: typing.Mapping[str, torch.nn.Module], node: fx.Node
188+
) -> bool:
189+
if isinstance(self.tosa_spec, Tosa_0_80) and self.tosa_spec.is_U55_subset:
190+
unsupported_ops = [
191+
exir_ops.edge.aten.bitwise_and.Tensor,
192+
exir_ops.edge.aten.bitwise_or.Tensor,
193+
exir_ops.edge.aten.bitwise_xor.Tensor,
194+
]
195+
196+
if node.target in unsupported_ops:
197+
return False
198+
199+
return True
200+
201+
173202
class NeedsDecompositionCheck(OperatorSupportBase):
174203
"""
175204
Targeted operators need to be decomposed prior to quantization in order to get a pair of q-dq-nodes surrounding
@@ -310,11 +339,11 @@ def is_node_supported(
310339
if not input_quantized:
311340
return False
312341

313-
output_quantized = output_quantized or all(
314-
(output_node.target == self.q_op)
315-
or (not get_first_fake_tensor(output_node).dtype.is_floating_point)
316-
for output_node in node.users
342+
all_q_users = all(
343+
(output_node.target == self.q_op) for output_node in node.users
317344
)
345+
is_floating_point = get_first_fake_tensor(node).dtype.is_floating_point
346+
output_quantized = output_quantized or all_q_users or not is_floating_point
318347

319348
if not output_quantized:
320349
return False

backends/arm/operators/op_avg_pool2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _build_generic_avgpool2d(
4141
output: TosaArg,
4242
input_zp: int,
4343
output_zp: int,
44-
accumulator_type,
44+
accumulator_type: ts.DType,
4545
) -> None:
4646
input_tensor = inputs[0]
4747

backends/arm/operators/op_conv2d.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from executorch.backends.arm.tosa_quant_utils import build_rescale_conv_output
2323
from executorch.backends.arm.tosa_utils import build_reshape, tosa_shape
2424

25-
from serializer.tosa_serializer import TosaOp
26-
2725

2826
@register_node_visitor
2927
class Conv2dVisitor(NodeVisitor):
@@ -36,8 +34,12 @@ def __init__(self, *args):
3634
# `(input + 2 * pad - dilation * (weight - 1) - 1) / stride`
3735
# must be an integer, but tosa currently strictly require this property.
3836
# This function adjusts the pad value to meet the requirement.
39-
def adjust_pad_if_needed(self, input, weight, stride, pad, dilation):
40-
mod_remainder = (input + 2 * pad - dilation * (weight - 1) - 1) % stride
37+
def adjust_pad_if_needed(
38+
self, input_size: int, input_weight: int, stride: int, pad: int, dilation: int
39+
) -> int:
40+
mod_remainder = (
41+
input_size + 2 * pad - dilation * (input_weight - 1) - 1
42+
) % stride
4143

4244
# No need to adjust
4345
if mod_remainder == 0:
@@ -143,11 +145,11 @@ def define_node(
143145
build_reshape(
144146
tosa_graph, weight.name, weight_post_shape, weight_reshaped.name
145147
)
146-
tosa_op = TosaOp.Op().DEPTHWISE_CONV2D
148+
tosa_op = ts.TosaOp.Op().DEPTHWISE_CONV2D
147149
weight_name = weight_reshaped.name
148150
else:
149151
"""Regular convolution case"""
150-
tosa_op = TosaOp.Op().CONV2D
152+
tosa_op = ts.TosaOp.Op().CONV2D
151153
weight_name = weight.name
152154

153155
tosa_graph.addOperator(

0 commit comments

Comments
 (0)