MCPcopy Create free account
hub / github.com/pytorch/executorch / inspect_node

Function inspect_node

exir/print_program.py:378–428  ·  view source on GitHub ↗

Inspect a node by highlighting the node in the graph as well as the stacktrace. Args: graph: The graph containing the node node: The node to be inspected Return: A string. An example output is: _param_constant0 error_msg: Here is the failing node in the graph mod

(graph: torch.fx.Graph, node: torch.fx.Node)

Source from the content-addressed store, hash-verified

376
377
378def inspect_node(graph: torch.fx.Graph, node: torch.fx.Node) -> str:
379 """
380 Inspect a node by highlighting the node in the graph as well as the stacktrace.
381
382 Args:
383 graph: The graph containing the node
384 node: The node to be inspected
385
386 Return: A string. An example output is:
387
388 _param_constant0 error_msg: Here is the failing node in the graph module:
389 graph():
390 %arg0_1 : [num_users=1] = placeholder[target=arg0_1]
391 --> %_param_constant0 : [num_users=1] = get_attr[target=_param_constant0]
392 %_param_constant1 : [num_users=1] = get_attr[target=_param_constant1]
393 %aten_convolution_default : [num_users=2] = call_function[target=executorch.exir.dialects.edge._ops.aten.convolution.default](args = (%arg0_1, %_param_constant0, %_param_constant1, [1, 1], [0, 0], [1, 1], False, [0, 0], 1), kwargs = {})
394 %_param_constant2 : [num_users=1] = get_attr[target=_param_constant2]
395 %_param_constant3 : [num_users=1] = get_attr[target=_param_constant3]
396 %aten_convolution_default_1 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.convolution.default](args = (%aten_convolution_default, %_param_constant2, %_param_constant3, [1, 1], [0, 0], [1, 1], False, [0, 0], 1), kwargs = {})
397 %aten_add_tensor : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%aten_convolution_default, %aten_convolution_default_1), kwargs = {})
398 %_param_constant4 : [num_users=1] = get_attr[target=_param_constant4]
399 %_param_constant5 : [num_users=1] = get_attr[target=_param_constant5]
400 %aten_convolution_default_2 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.convolution.default](args = (%aten_add_tensor, %_param_constant4, %_param_constant5, [1, 1], [0, 0], [1, 1], False, [0, 0], 1), kwargs = {})
401 %aten_gelu_default : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.gelu.default](args = (%aten_convolution_default_2,), kwargs = {})
402 return [aten_gelu_default]
403 This node _param_constant0 has metadata of:
404 The node stacktrace:
405 Traceback (most recent call last):
406 File "/tmp/ipykernel_1204253/3382880687.py", line 7, in forward
407 return self.test_model(x)
408 File "/mnt/xarfuse/uid-25337/7b86ad0c-seed-nspid4026532987_cgpid2707357-ns-4026532984/torch/nn/modules/module.py", line 1528, in _call_impl
409 return forward_call(*args, **kwargs)
410 File "/tmp/ipykernel_1204253/712280972.py", line 10, in forward
411 a = self.conv1(x)
412
413 """
414 graph_str_with_cursor = add_cursor_to_graph(graph, node)
415 error_msg = (
416 f"Here is the node in the graph module:\n"
417 f"{graph_str_with_cursor}\n"
418 f"This node {node} has metadata of:\n"
419 )
420 # Node spec error message
421 if hasattr(node.meta, "spec"):
422 error_msg += f"The node spec:\n{node.meta['spec']}\n"
423
424 # Stacktrace error message
425 if "stack_trace" in node.meta:
426 framelist = _stacktrace_to_framelist(node.meta["stack_trace"])
427 error_msg += f"The node stacktrace:\n{pretty_print_stacktraces(framelist)}\n"
428 return error_msg

Callers 3

test_inspect_nodeMethod · 0.90
get_node_debug_infoFunction · 0.90

Calls 3

add_cursor_to_graphFunction · 0.85
_stacktrace_to_framelistFunction · 0.85
pretty_print_stacktracesFunction · 0.85

Tested by 1

test_inspect_nodeMethod · 0.72