Skip to content

Commit 9697232

Browse files
committed
Update base for Update on "[exir] Allow verifiers in _transform"
This is to allow users to transform an ExportedProgram using passes in places where it may result in a dialect that is not compliant with the original creation context. For example, if an ExportedProgram was created in an edge dialect and now needs to be run and transformed in a way that is not compliant with the EdgeDialectVerifier, such as in a delegate preprocess() function, then the user may want to override the verifier with their own or simply disable it. Differential Revision: [D73205727](https://our.internmc.facebook.com/intern/diff/D73205727/) [ghstack-poisoned]
2 parents e42d013 + ef99fff commit 9697232

File tree

30 files changed

+207
-78
lines changed

30 files changed

+207
-78
lines changed

backends/arm/test/ops/test_tanh.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
from typing import Tuple
1111

12+
import pytest
13+
1214
import torch
1315

14-
from executorch.backends.arm.test import common
16+
from executorch.backends.arm.test import common, conftest
1517
from executorch.backends.arm.test.tester.arm_tester import ArmTester
1618
from executorch.exir.backend.compile_spec_schema import CompileSpec
1719
from parameterized import parameterized
@@ -40,7 +42,7 @@ def forward(self, x):
4042
def _test_tanh_tosa_MI_pipeline(
4143
self, module: torch.nn.Module, test_data: Tuple[torch.tensor]
4244
):
43-
(
45+
tester = (
4446
ArmTester(
4547
module,
4648
example_inputs=test_data,
@@ -54,11 +56,13 @@ def _test_tanh_tosa_MI_pipeline(
5456
.check_not(["executorch_exir_dialects_edge__ops_aten_tanh_default"])
5557
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
5658
.to_executorch()
57-
.run_method_and_compare_outputs(inputs=test_data)
5859
)
5960

61+
if conftest.is_option_enabled("tosa_ref_model"):
62+
tester.run_method_and_compare_outputs(inputs=test_data)
63+
6064
def _test_tanh_tosa_BI_pipeline(self, module: torch.nn.Module, test_data: Tuple):
61-
(
65+
tester = (
6266
ArmTester(
6367
module,
6468
example_inputs=test_data,
@@ -73,9 +77,11 @@ def _test_tanh_tosa_BI_pipeline(self, module: torch.nn.Module, test_data: Tuple)
7377
.check_not(["executorch_exir_dialects_edge__ops_aten_tanh_default"])
7478
.check_count({"torch.ops.higher_order.executorch_call_delegate": 1})
7579
.to_executorch()
76-
.run_method_and_compare_outputs(inputs=test_data)
7780
)
7881

82+
if conftest.is_option_enabled("tosa_ref_model"):
83+
tester.run_method_and_compare_outputs(inputs=test_data)
84+
7985
def _test_tanh_tosa_ethos_BI_pipeline(
8086
self,
8187
compile_spec: list[CompileSpec],
@@ -114,6 +120,7 @@ def _test_tanh_tosa_u85_BI_pipeline(
114120
)
115121

116122
@parameterized.expand(test_data_suite)
123+
@pytest.mark.tosa_ref_model
117124
def test_tanh_tosa_MI(
118125
self,
119126
test_name: str,
@@ -122,6 +129,7 @@ def test_tanh_tosa_MI(
122129
self._test_tanh_tosa_MI_pipeline(self.Tanh(), (test_data,))
123130

124131
@parameterized.expand(test_data_suite)
132+
@pytest.mark.tosa_ref_model
125133
def test_tanh_tosa_BI(self, test_name: str, test_data: torch.Tensor):
126134
self._test_tanh_tosa_BI_pipeline(self.Tanh(), (test_data,))
127135

backends/arm/test/targets.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def define_arm_tests():
1616
"ops/test_linear.py",
1717
"ops/test_slice.py",
1818
"ops/test_sigmoid.py",
19+
"ops/test_tanh.py",
1920
]
2021

2122
TESTS = {}

backends/qualcomm/aot/ir/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ load(
44
)
55
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
66
load("@fbsource//xplat/executorch/backends/qualcomm:targets.bzl", "generate_schema_header")
7-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
7+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
88

99
QCIR_NAME = "qcir"
1010
INPUT_QCIR = QCIR_NAME + ".fbs"
@@ -56,7 +56,7 @@ def define_common_targets():
5656
platforms = [ANDROID],
5757
visibility = ["@EXECUTORCH_CLIENTS"],
5858
deps = [
59-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
59+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
6060
"//executorch/runtime/backend:interface",
6161
"//executorch/runtime/core:core",
6262
"//executorch/backends/qualcomm/aot/wrappers:wrappers",

backends/qualcomm/aot/python/targets.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"ANDROID",
44
)
55
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
6-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
6+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
77

88
PYTHON_MODULE_NAME = "PyQnnManagerAdaptor"
99

@@ -34,7 +34,7 @@ def define_common_targets():
3434
"//executorch/backends/qualcomm/aot/ir:qcir_utils",
3535
"//executorch/backends/qualcomm/runtime:runtime",
3636
"fbsource//third-party/pybind11:pybind11",
37-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
37+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
3838
],
3939
external_deps = [
4040
"libtorch_python",
@@ -67,7 +67,7 @@ def define_common_targets():
6767
"//executorch/backends/qualcomm/aot/ir:qcir_utils",
6868
"//executorch/backends/qualcomm/runtime:runtime",
6969
"fbsource//third-party/pybind11:pybind11",
70-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
70+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
7171
],
7272
external_deps = [
7373
"libtorch_python",
@@ -94,6 +94,6 @@ def define_common_targets():
9494
"//executorch/backends/qualcomm/aot/ir:qcir_utils",
9595
"//executorch/backends/qualcomm/runtime:runtime",
9696
"fbsource//third-party/pybind11:pybind11",
97-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
97+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
9898
],
9999
)

backends/qualcomm/aot/wrappers/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"ANDROID",
44
)
55
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
6-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
6+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
77

88
def define_common_targets():
99
"""Defines targets that should be shared between fbcode and xplat.
@@ -23,7 +23,7 @@ def define_common_targets():
2323
platforms = [ANDROID],
2424
visibility = ["@EXECUTORCH_CLIENTS"],
2525
deps = [
26-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
26+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
2727
"//executorch/runtime/backend:interface",
2828
"//executorch/runtime/core:core",
2929
],

backends/qualcomm/builders/op_rms_norm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ def define_node(
8181
{}, # kwargs
8282
)
8383
if quant_attrs := node.meta.get(QCOM_QUANT_ATTRS):
84+
quant_attrs = quant_attrs.copy()
85+
quant_attrs[QCOM_ZERO_POINT] = 0
8486
bias_node.meta[QCOM_QUANT_ATTRS] = quant_attrs
85-
bias_node.meta[QCOM_QUANT_ATTRS][QCOM_ZERO_POINT] = 0
8687
bias_tensor_wrapper = self.define_tensor(
8788
bias_node,
8889
node,

backends/qualcomm/runtime/backends/QnnProfiler.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
8484
"ProfileData failed to get events: %d", QNN_GET_ERROR_CODE(error));
8585
return error;
8686
}
87+
88+
auto get_unit = [](QnnProfile_EventUnit_t unit) {
89+
switch (unit) {
90+
case QNN_PROFILE_EVENTUNIT_MICROSEC:
91+
return " (us)";
92+
case QNN_PROFILE_EVENTUNIT_BYTES:
93+
return " (bytes)";
94+
case QNN_PROFILE_EVENTUNIT_COUNT:
95+
return " (count)";
96+
case QNN_PROFILE_EVENTUNIT_BACKEND:
97+
// cycle unit is default appeared
98+
case QNN_PROFILE_EVENTUNIT_CYCLES:
99+
default:
100+
return "";
101+
}
102+
};
87103
QnnProfile_EventData_t event_data;
88104
for (std::uint32_t i = 0; i < num_events; ++i) {
89105
error =
@@ -96,6 +112,16 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
96112
QNN_GET_ERROR_CODE(error));
97113
return error;
98114
}
115+
// add events for other important metrics, e.g. RPC execution time
116+
std::string identifier =
117+
std::string(event_data.identifier) + get_unit(event_data.unit);
118+
executorch::runtime::event_tracer_log_profiling_delegate(
119+
event_tracer,
120+
identifier.c_str(),
121+
/*delegate_debug_id=*/
122+
static_cast<executorch::runtime::DebugHandle>(-1),
123+
0,
124+
event_data.value);
99125
// Check an event's sub events only if it relates to graph execution time
100126
// (and its sub events are the individual op executions):
101127
if (backend_->IsProfileEventTypeParentOfNodeTime(event_data.type)) {
@@ -109,6 +135,7 @@ Qnn_ErrorHandle_t QnnProfile::ProfileData(
109135
QNN_GET_ERROR_CODE(error));
110136
return error;
111137
}
138+
112139
QnnProfile_EventData_t sub_event_data;
113140
for (std::uint32_t j = 0; j < num_sub_events; ++j) {
114141
error = qnn_interface.qnn_profile_get_event_data(

backends/qualcomm/runtime/targets.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"ANDROID",
44
)
55
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
6-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
6+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
77

88
def define_common_targets():
99
"""Defines targets that should be shared between fbcode and xplat.
@@ -24,7 +24,7 @@ def define_common_targets():
2424
platforms = [ANDROID],
2525
visibility = ["@EXECUTORCH_CLIENTS"],
2626
deps = [
27-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
27+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
2828
"//executorch/runtime/backend:interface",
2929
],
3030
exported_deps = [
@@ -60,11 +60,11 @@ def define_common_targets():
6060
platforms = [ANDROID],
6161
visibility = ["@EXECUTORCH_CLIENTS"],
6262
resources = ({
63-
"qnn_lib": "fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs".format(get_qnn_library_verision()),
63+
"qnn_lib": "fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs".format(get_qnn_library_version()),
6464
} if include_aot_qnn_lib else {
6565
}),
6666
deps = [
67-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
67+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
6868
":logging",
6969
"//executorch/backends/qualcomm:schema",
7070
"//executorch/backends/qualcomm/aot/ir:qcir_utils",

backends/qualcomm/targets.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ load(
33
"ANDROID",
44
)
55
load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime")
6-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
6+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
77

88
# Construct the input and output file names. All input and output files rely on scalar_type file.
99
SCHEMA_NAME = "qc_compiler_spec"
@@ -84,7 +84,7 @@ def define_common_targets():
8484
define_static_target = True,
8585
visibility = ["@EXECUTORCH_CLIENTS"],
8686
deps = [
87-
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_verision()),
87+
"fbsource//third-party/qualcomm/qnn/qnn-{0}:api".format(get_qnn_library_version()),
8888
"//executorch/runtime/backend:interface",
8989
"//executorch/runtime/core:core",
9090
"//executorch/backends/qualcomm/runtime:runtime_android_build",

backends/qualcomm/tests/TARGETS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
load("@fbcode_macros//build_defs:python_library.bzl", "python_library")
22
load("@fbcode_macros//build_defs:python_unittest.bzl", "python_unittest")
3-
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_verision")
3+
load("@fbsource//xplat/executorch/backends/qualcomm/qnn_version.bzl", "get_qnn_library_version")
44

55
python_library(
66
name = "models",
@@ -17,7 +17,7 @@ python_library(
1717
"utils.py",
1818
],
1919
# env = {
20-
# "LD_LIBRARY_PATH": "$(location fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs)".format(get_qnn_library_verision()),
20+
# "LD_LIBRARY_PATH": "$(location fbsource//third-party/qualcomm/qnn/qnn-{0}:qnn_offline_compile_libs)".format(get_qnn_library_version()),
2121
# },
2222
deps = [
2323
":models",

0 commit comments

Comments
 (0)