Skip to content

Commit 1e98d08

Browse files
authored
Revert "Arm backend: Use dbg_fail when node visitors raise exceptions (#9268)"
This reverts commit 622b79e.
1 parent f86d7e3 commit 1e98d08

File tree

4 files changed

+37
-39
lines changed

4 files changed

+37
-39
lines changed

backends/arm/ethosu_backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
# debug functionality
2525
logger = logging.getLogger(__name__)
26+
logger.setLevel(logging.WARNING)
2627

2728

2829
@final

backends/arm/process_node.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from executorch.backends.arm.operators.node_visitor import NodeVisitor
1515
from executorch.backends.arm.tosa_mapping import TosaArg
1616
from executorch.backends.arm.tosa_specification import TosaSpecification
17-
from executorch.backends.arm.tosa_utils import getNodeArgs, tosa_shape
17+
from executorch.backends.arm.tosa_utils import (
18+
get_node_debug_info,
19+
getNodeArgs,
20+
tosa_shape,
21+
)
1822
from torch.export.exported_program import ExportedProgram
1923

2024

@@ -32,7 +36,7 @@ def process_call_function(
3236
output = TosaArg(node)
3337
except ValueError as e:
3438
raise ValueError(
35-
f"Failed processing call_function: {node.name}. "
39+
f"Failed processing call_function:\n{get_node_debug_info(node)}"
3640
"Is the original torch function supported?"
3741
) from e
3842
tosa_graph.currRegion.currBasicBlock.addTensor(
@@ -70,7 +74,7 @@ def process_inputs(
7074
tosa_arg = TosaArg(node)
7175
except ValueError as e:
7276
raise ValueError(
73-
f"Failed processing input placeholder: {node.name}. "
77+
f"Failed processing input placeholder:\n{get_node_debug_info(node)}"
7478
"Is the original torch function supported?"
7579
) from e
7680
input_shape = tosa_arg.shape
@@ -96,7 +100,7 @@ def process_inputs_to_parameters(
96100
tosa_arg = TosaArg(node)
97101
except ValueError as e:
98102
raise ValueError(
99-
f"Failed processing parameter placeholder: {node.name}. "
103+
f"Failed processing parameter placeholder:\n{get_node_debug_info(node)}"
100104
"Is the original torch function supported?"
101105
) from e
102106
parameter_name = edge_program.graph_signature.inputs_to_parameters[tosa_arg.name]
@@ -125,7 +129,7 @@ def process_inputs_to_buffers(
125129
tosa_arg = TosaArg(node)
126130
except ValueError as e:
127131
raise ValueError(
128-
f"Failed processing buffer placeholder: {node.name}. "
132+
f"Failed processing buffer placeholder:\n{get_node_debug_info(node)}"
129133
"Is the original torch function supported?"
130134
) from e
131135
buffer_name = edge_program.graph_signature.inputs_to_buffers[node.name]
@@ -153,7 +157,7 @@ def process_inputs_to_lifted_tensor_constants(
153157
tosa_arg = TosaArg(node)
154158
except ValueError as e:
155159
raise ValueError(
156-
f"Failed processing lifted tensor constant placeholder: {node.name}. "
160+
f"Failed processing lifted tensor constant placeholder:\n{get_node_debug_info(node)}"
157161
"Is the original torch function supported?"
158162
) from e
159163
tensor_name = edge_program.graph_signature.inputs_to_lifted_tensor_constants[

backends/arm/tosa_backend.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
# TOSA backend debug functionality
3737
logger = logging.getLogger(__name__)
38+
logger.setLevel(logging.WARNING)
3839
TOSA_DBG_VERBOSE = os.environ.get("TOSA_DBG_VERBOSE") == "1"
3940
if TOSA_DBG_VERBOSE:
4041
logging.basicConfig(level=logging.INFO)
@@ -101,22 +102,18 @@ def preprocess( # noqa: C901
101102
input_count = 0
102103
for node in graph_module.graph.nodes:
103104
node = cast(Node, node)
104-
try:
105-
if node.op == "call_function":
106-
process_call_function(node, tosa_graph, node_visitors, tosa_spec)
107-
elif node.op == "placeholder":
108-
process_placeholder(node, tosa_graph, edge_program, tosa_spec)
109-
if node.name in edge_program.graph_signature.user_inputs:
110-
input_count += 1
111-
elif node.op == "output":
112-
process_output(node, tosa_graph)
113-
else:
114-
# This will only happen if an unpartitioned graph is passed without
115-
# any checking of compatibility.
116-
raise RuntimeError(f"{node.name} is unsupported op {node.op}")
117-
except (AssertionError, RuntimeError, ValueError):
118-
dbg_fail(node, graph_module, tosa_graph, artifact_path)
119-
raise
105+
if node.op == "call_function":
106+
process_call_function(node, tosa_graph, node_visitors, tosa_spec)
107+
elif node.op == "placeholder":
108+
process_placeholder(node, tosa_graph, edge_program, tosa_spec)
109+
if node.name in edge_program.graph_signature.user_inputs:
110+
input_count += 1
111+
elif node.op == "output":
112+
process_output(node, tosa_graph)
113+
else:
114+
# This will only happen if an unpartitioned graph is passed without
115+
# any checking of compatibility.
116+
dbg_fail(node, tosa_graph, artifact_path)
120117

121118
if len(input_order) > 0:
122119
if input_count != len(input_order):

backends/arm/tosa_utils.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,31 @@
77

88
import logging
99
import os
10-
from typing import Any, Optional, Tuple
10+
from typing import Any, Tuple
1111

1212
import serializer.tosa_serializer as ts # type: ignore
1313
import torch
1414
from executorch.backends.arm.tosa_mapping import TosaArg
1515

1616
from executorch.exir.dialects._ops import ops as exir_ops
17-
from executorch.exir.print_program import inspect_node
1817
from serializer.tosa_serializer import TosaOp
1918
from torch.fx import Node
2019

2120
logger = logging.getLogger(__name__)
21+
logger.setLevel(logging.WARNING)
2222
TOSA_DBG_VERBOSE = os.environ.get("TOSA_DBG_VERBOSE") == "1"
2323
if TOSA_DBG_VERBOSE:
2424
logging.basicConfig(level=logging.INFO)
2525
logger.setLevel(logging.INFO)
2626

2727

28-
def dbg_node(node: torch.fx.Node, graph_module: torch.fx.GraphModule):
28+
def dbg_node(node: torch.fx.Node):
2929
# Debug output of node information
30-
logger.info(get_node_debug_info(node, graph_module))
30+
logger.info(get_node_debug_info(node))
3131

3232

33-
def get_node_debug_info(node: torch.fx.Node, graph_module: torch.fx.GraphModule) -> str:
33+
def get_node_debug_info(node: torch.fx.Node) -> str:
3434
output = (
35-
f" {inspect_node(graph=graph_module.graph, node=node)}\n"
3635
"-- NODE DEBUG INFO --\n"
3736
f" Op is {node.op}\n"
3837
f" Name is {node.name}\n"
@@ -72,24 +71,21 @@ def dbg_tosa_dump(tosa_graph: ts.TosaSerializer, path: str, suffix: str = ""):
7271
assert os.path.exists(filepath_desc_json), "Failed to write TOSA JSON"
7372

7473

75-
def dbg_fail(
76-
node,
77-
graph_module,
78-
tosa_graph: Optional[ts.TosaSerializer] = None,
79-
path: Optional[str] = None,
80-
):
74+
def dbg_fail(node, tosa_graph, path):
75+
dbg_tosa_dump(tosa_graph, path)
8176
logger.warning("Internal error due to poorly handled node:")
82-
if tosa_graph is not None and path is not None:
83-
dbg_tosa_dump(tosa_graph, path)
84-
logger.warning(f"Debug output captured in '{path}'.")
85-
dbg_node(node, graph_module)
77+
dbg_node(node)
78+
logger.warning(f"Debug output captured in '{path}'.")
79+
raise RuntimeError("TOSA Internal Error on node, enable logging for further info.")
8680

8781

8882
def getNodeArgs(node: Node) -> list[TosaArg]:
8983
try:
9084
return [TosaArg(arg) for arg in node.args]
9185
except ValueError as e:
92-
raise ValueError(f"Failed processing args to op:\n{node}") from e
86+
raise ValueError(
87+
f"Failed processing args to op:\n{get_node_debug_info(node)}"
88+
) from e
9389

9490

9591
def get_output_node(node: Node) -> Node:

0 commit comments

Comments
 (0)