Skip to content

Arm backend: Convert assert to throw TypeError in arm_pass_utils #9866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions backends/arm/_passes/arm_pass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import torch
import torch.fx
from executorch.backends.arm.tosa_utils import get_node_debug_info
from executorch.exir import ExportedProgram
from executorch.exir.dialects._ops import ops as exir_ops

Expand Down Expand Up @@ -169,9 +170,13 @@ def get_first_fake_tensor(node: torch.fx.Node) -> FakeTensor:
else:
fake_tensor = node.meta["val"]

assert isinstance(
fake_tensor, FakeTensor
), f'Found {fake_tensor} in meta["val"] of {node}, expected to find FakeTensor.'
if not isinstance(fake_tensor, FakeTensor):
raise TypeError(
f'Expected a FakeTensor in meta["val"] of node {node}, but got '
f"{type(fake_tensor).__name__}\n"
f"{get_node_debug_info(node)}"
)

return fake_tensor


Expand Down
6 changes: 5 additions & 1 deletion backends/arm/tosa_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ def dbg_node(node: torch.fx.Node, graph_module: torch.fx.GraphModule):
logger.info(get_node_debug_info(node, graph_module))


def get_node_debug_info(node: torch.fx.Node, graph_module: torch.fx.GraphModule) -> str:
def get_node_debug_info(
node: torch.fx.Node, graph_module: torch.fx.GraphModule | None = None
) -> str:
output = (
f" {inspect_node(graph=graph_module.graph, node=node)}\n"
if graph_module
else ""
"-- NODE DEBUG INFO --\n"
f" Op is {node.op}\n"
f" Name is {node.name}\n"
Expand Down
Loading