Skip to content

Commit 5909e23

Browse files
authored
Revert "Arm backend: Add real implementation for TOSA dialect ops (re-land)" (pytorch#20670)
Reverts pytorch#20537 This breaks some internal tests due to missing BUCK dependencies on the tosa reference model. I tried to fix forward by just adding those deps (pytorch#20642), but it looks like we'll need to do lazy imports here due to some binary size expansion. I'll tackle the reland. cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell
1 parent fc408f8 commit 5909e23

32 files changed

Lines changed: 118 additions & 534 deletions

‎backends/arm/_passes/fuse_constant_ops_pass.py‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -92,20 +92,6 @@ def _is_tosa_dialect_op(target) -> bool:
9292
or "<EdgeOpOverload: tosa." in target_str
9393
)
9494

95-
@staticmethod
96-
def _has_real_tosa_dialect_impl(target) -> bool:
97-
schema = getattr(target, "_schema", None)
98-
op_name = getattr(schema, "name", None)
99-
if op_name is None:
100-
return False
101-
102-
try:
103-
return torch._C._dispatch_has_kernel_for_dispatch_key(
104-
op_name, "CompositeExplicitAutograd"
105-
)
106-
except RuntimeError:
107-
return False
108-
10995
@staticmethod
11096
def _arg_contains_symbolic_shape(arg) -> bool:
11197
if isinstance(arg, torch.fx.Node):
@@ -211,31 +197,19 @@ def resolve_arg(arg, arg_index=None):
211197

212198
return True
213199

214-
def maybe_delete(self, input_nodes_to_maybe_delete):
215-
for input_node in input_nodes_to_maybe_delete:
216-
if input_node.meta.get("is_input", False):
217-
# Never delete submodule inputs, they need to match the parameters from the outer module.
218-
continue
219-
if len(input_node.users) == 0:
220-
self._delete_constant_placeholder(input_node)
221-
222200
def call(self, graph_module):
223201
modified = False
224202
input_nodes_to_maybe_delete = set()
225203
for node in graph_module.graph.nodes:
226204
if node.op != "call_function":
227205
continue
228-
if node.target == exir_ops.backend.tosa.RESCALE.default:
229-
# Leave fusing of RESCALES to the compiler.
230-
continue
231-
if self._is_tosa_dialect_op(
232-
node.target
233-
) and not self._has_real_tosa_dialect_impl(node.target):
234-
continue
235-
# Don't fuse ops whose explicit args/kwargs include symbolic shape values.
236-
if self._arg_contains_symbolic_shape(
237-
node.args
238-
) or self._arg_contains_symbolic_shape(node.kwargs):
206+
# Don't fuse TOSA dialect ops as they do not have eager forward functions.
207+
# Also don't fuse ops whose explicit args/kwargs include symbolic shape values.
208+
if (
209+
self._is_tosa_dialect_op(node.target)
210+
or self._arg_contains_symbolic_shape(node.args)
211+
or self._arg_contains_symbolic_shape(node.kwargs)
212+
):
239213
continue
240214

241215
input_nodes = node.all_input_nodes
@@ -267,7 +241,10 @@ def call(self, graph_module):
267241

268242
if modified:
269243
graph_module.graph.eliminate_dead_code()
270-
self.maybe_delete(input_nodes_to_maybe_delete)
244+
for input_node in input_nodes_to_maybe_delete:
245+
if len(input_node.users) == 0:
246+
self._delete_constant_placeholder(input_node)
247+
271248
graph_module = super().call(graph_module).graph_module
272249

273250
return PassResult(graph_module, modified)

‎backends/arm/operators/node_visitor.py‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
TosaSpecMapping,
3232
)
3333

34-
3534
logger = logging.getLogger(__name__)
3635

3736

@@ -247,15 +246,3 @@ def get_node_visitors(*args) -> Dict[str, NodeVisitor]:
247246
node_visitors[target] = visitor(*args)
248247

249248
return node_visitors
250-
251-
252-
def get_node_visitor(target: str, tosa_spec: TosaSpecification):
253-
# Ensure all operator modules are imported so visitors are registered.
254-
import executorch.backends.arm.operators # noqa: F401
255-
256-
node_visitor_tuples = _node_visitor_tuples.get(tosa_spec)
257-
for target_name, node_visitor_cls in node_visitor_tuples:
258-
if target_name == target:
259-
return node_visitor_cls(tosa_spec)
260-
261-
raise ValueError(f"No {target} NodeVisitor registered for {tosa_spec}")

‎backends/arm/test/misc/tosa_dialect/test_tosa_gather.py‎

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

‎backends/arm/test/misc/tosa_dialect/test_tosa_identity.py‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from torch._subclasses.fake_tensor import FakeTensorMode
1414

1515

16-
def test_identity_tosa_FP_fake() -> None:
16+
def test_identity_tosa_FP() -> None:
1717
sample_input = torch.randn((1, 2, 3, 4), dtype=torch.float32)
1818

1919
with TosaLoweringContext(
@@ -23,12 +23,3 @@ def test_identity_tosa_FP_fake() -> None:
2323

2424
assert output.dtype == sample_input.dtype
2525
assert tuple(output.shape) == tuple(sample_input.shape)
26-
27-
28-
def test_identity_tosa_FP_real() -> None:
29-
sample_input = torch.randn((1, 2, 3, 4), dtype=torch.float32)
30-
31-
with TosaLoweringContext(TosaSpecification.create_from_string("TOSA-1.0+FP")):
32-
output = exir_ops.backend.tosa.IDENTITY.default(sample_input)
33-
34-
torch.testing.assert_close(output, sample_input)

‎backends/arm/test/misc/tosa_dialect/test_tosa_rescale.py‎

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

‎backends/arm/test/passes/test_ensure_unique_output_nodes_pass.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def test_ensure_unique_output_nodes_no_target_inserts_identity_per_repeated_outp
3535
"executorch_exir_dialects_backend__ops_tosa_IDENTITY_default": 2,
3636
},
3737
)
38+
pipeline.pop_stage("run_method_and_compare_outputs")
3839
pipeline.run()
3940

4041
graph_module = (
@@ -61,4 +62,5 @@ def test_ensure_unique_output_nodes_no_target_keeps_unique_outputs_unchanged() -
6162
"executorch_exir_dialects_backend__ops_tosa_IDENTITY_default",
6263
],
6364
)
65+
pipeline.pop_stage("run_method_and_compare_outputs")
6466
pipeline.run()

0 commit comments

Comments
 (0)