Skip to content

Commit 97de632

Browse files
Dark Knightfacebook-github-bot
authored andcommitted
Revert D79905595
Summary: This diff reverts D79905595 T234264045 Depends on D79905595 Differential Revision: D80085825
1 parent 846bc1e commit 97de632

File tree

6 files changed

+79
-97
lines changed

6 files changed

+79
-97
lines changed

backends/arm/_passes/arm_pass_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import torch
1515
import torch.fx
16-
from executorch.backends.arm.common.debug import get_node_debug_info
16+
from executorch.backends.arm.tosa_utils import get_node_debug_info
1717
from executorch.exir import ExportedProgram
1818
from executorch.exir.dialects._ops import ops as exir_ops
1919

backends/arm/common/__init__.py

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

backends/arm/common/debug.py

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

backends/arm/quantizer/quantization_annotator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import torch
1212
import torch.fx
1313
import torch.nn.functional as F
14-
from executorch.backends.arm.common.debug import get_node_debug_info
1514
from executorch.backends.arm.quantizer import QuantizationConfig
15+
from executorch.backends.arm.tosa_utils import get_node_debug_info
1616
from torch._subclasses import FakeTensor
1717

1818
from torch.fx import Node

backends/arm/tosa_backend.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
from executorch.backends.arm._passes import (
2020
ArmPassManager,
2121
) # usort: skip
22-
from executorch.backends.arm.common.debug import debug_fail, debug_tosa_dump
2322
from executorch.backends.arm.process_node import (
2423
process_call_function,
2524
process_output,
2625
process_placeholder,
2726
)
27+
from executorch.backends.arm.tosa_utils import dbg_fail, dbg_tosa_dump
2828
from executorch.exir.backend.backend_details import BackendDetails, PreprocessResult
2929
from executorch.exir.backend.compile_spec_schema import CompileSpec
3030
from torch.export.exported_program import ExportedProgram
@@ -115,12 +115,12 @@ def preprocess( # noqa: C901
115115
# any checking of compatibility.
116116
raise RuntimeError(f"{node.name} is unsupported op {node.op}")
117117
except Exception:
118-
debug_fail(node, graph_module, tosa_graph, artifact_path)
118+
dbg_fail(node, graph_module, tosa_graph, artifact_path)
119119
raise
120120

121121
if artifact_path:
122122
tag = arm_get_first_delegation_tag(graph_module)
123-
debug_tosa_dump(
123+
dbg_tosa_dump(
124124
tosa_graph,
125125
artifact_path,
126126
suffix="{}".format(f"_{tag}" if tag else "") + (f"_{tosa_spec}"),

backends/arm/tosa_utils.py

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

88
import logging
9-
from typing import Any
9+
import os
10+
from typing import Any, Optional
1011

1112
import numpy as np
1213
import serializer.tosa_serializer as ts # type: ignore
@@ -19,13 +20,85 @@
1920

2021
from executorch.backends.arm.tosa_specification import TosaSpecification
2122
from executorch.exir.dialects._ops import ops as exir_ops
23+
from executorch.exir.print_program import inspect_node
2224

2325
from torch._subclasses.fake_tensor import FakeTensor
2426
from torch.fx import Node
2527

2628
logger = logging.getLogger(__name__)
2729

2830

31+
def dbg_node(node: torch.fx.Node, graph_module: torch.fx.GraphModule):
32+
# Debug output of node information
33+
logger.info(get_node_debug_info(node, graph_module))
34+
35+
36+
def get_node_debug_info(
37+
node: torch.fx.Node, graph_module: torch.fx.GraphModule | None = None
38+
) -> str:
39+
output = (
40+
f" {inspect_node(graph=graph_module.graph, node=node)}\n"
41+
if graph_module
42+
else ""
43+
"-- NODE DEBUG INFO --\n"
44+
f" Op is {node.op}\n"
45+
f" Name is {node.name}\n"
46+
f" Node target is {node.target}\n"
47+
f" Node args is {node.args}\n"
48+
f" Node kwargs is {node.kwargs}\n"
49+
f" Node users is {node.users}\n"
50+
" Node.meta = \n"
51+
)
52+
for k, v in node.meta.items():
53+
if k == "stack_trace":
54+
matches = v.split("\n")
55+
output += " 'stack_trace =\n"
56+
for m in matches:
57+
output += f" {m}\n"
58+
else:
59+
output += f" '{k}' = {v}\n"
60+
61+
if isinstance(v, list):
62+
for i in v:
63+
output += f" {i}\n"
64+
return output
65+
66+
67+
# Output TOSA flatbuffer and test harness file
68+
def dbg_tosa_dump(tosa_graph: ts.TosaSerializer, path: str, suffix: str = ""):
69+
filename = f"output{suffix}.tosa"
70+
71+
logger.info(f"Emitting debug output to: {path=}, {suffix=}")
72+
73+
os.makedirs(path, exist_ok=True)
74+
75+
fb = tosa_graph.serialize()
76+
js = tosa_graph.writeJson(filename)
77+
78+
filepath_tosa_fb = os.path.join(path, filename)
79+
with open(filepath_tosa_fb, "wb") as f:
80+
f.write(fb)
81+
assert os.path.exists(filepath_tosa_fb), "Failed to write TOSA flatbuffer"
82+
83+
filepath_desc_json = os.path.join(path, f"desc{suffix}.json")
84+
with open(filepath_desc_json, "w") as f:
85+
f.write(js)
86+
assert os.path.exists(filepath_desc_json), "Failed to write TOSA JSON"
87+
88+
89+
def dbg_fail(
90+
node,
91+
graph_module,
92+
tosa_graph: Optional[ts.TosaSerializer] = None,
93+
path: Optional[str] = None,
94+
):
95+
logger.warning("Internal error due to poorly handled node:")
96+
if tosa_graph is not None and path is not None:
97+
dbg_tosa_dump(tosa_graph, path)
98+
logger.warning(f"Debug output captured in '{path}'.")
99+
dbg_node(node, graph_module)
100+
101+
29102
def getNodeArgs(node: Node, tosa_spec: TosaSpecification) -> list[TosaArg]:
30103
try:
31104
return [TosaArg(arg, tosa_spec) for arg in node.args]

0 commit comments

Comments
 (0)