调试后端委托¶
我们提供了一个 util 函数列表,让用户能够深入了解图形模块在阶段中发生了什么。to_backend()
获取委托摘要¶
该方法提供了调用后模型所发生情况的摘要:get_delegation_info()
to_backend()
from executorch.devtools.backend_debug import get_delegation_info
from tabulate import tabulate
# ... After call to to_backend(), but before to_executorch()
graph_module = edge_manager.exported_program().graph_module
delegation_info = get_delegation_info(graph_module)
print(delegation_info.get_summary())
df = delegation_info.get_operator_delegation_dataframe()
print(tabulate(df, headers="keys", tablefmt="fancy_grid"))
打印输出示例:
Total delegated subgraphs: 86
Number of delegated nodes: 473
Number of non-delegated nodes: 430
op_type |
occurrences_in_delegated_graphs |
occurrences_in_non_delegated_graphs |
|
---|---|---|---|
0 |
aten__softmax_default |
12 |
0 |
1 |
aten_add_tensor |
37 |
0 |
2 |
aten_addmm_default |
48 |
0 |
3 |
aten_arange_start_step |
0 |
25 |
… |
|||
23 |
aten_view_copy_default |
170 |
48 |
… |
|||
26 |
总 |
473 |
430 |
从表中可以看出,该运算符在委托图中出现 170 次,在非委托图中出现 48 次。用户可以使用此类信息进行调试。aten_view_copy_default
可视化委托图¶
要查看更详细的视图,请使用该方法获取整个图形的 str 打印输出,或者直接用于打印:format_delegated_graph()
print_delegated_graph()
from executorch.exir.backend.utils import format_delegated_graph
graph_module = edge_manager.exported_program().graph_module
print(format_delegated_graph(graph_module)) # or call print_delegated_graph(graph_module)
它将打印整个模型以及后端消耗的子图。fx like or 提供的通用调试函数只会显示但隐藏后端使用的子图,而此函数则公开子图内部的内容。print_tabular()
print_readable()
call_delegate
在下面的示例打印输出中,请注意 and 运算符被委托给,而运算符未被委托。embedding
add
XNNPACK
sub
%aten_unsqueeze_copy_default_22 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.unsqueeze_copy.default](args = (%aten_arange_start_step_23, -2), kwargs = {})
%aten_unsqueeze_copy_default_23 : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.unsqueeze_copy.default](args = (%aten_arange_start_step_24, -1), kwargs = {})
%lowered_module_0 : [num_users=1] = get_attr[target=lowered_module_0]
backend_id: XnnpackBackend
lowered graph():
%aten_embedding_default : [num_users=1] = placeholder[target=aten_embedding_default]
%aten_embedding_default_1 : [num_users=1] = placeholder[target=aten_embedding_default_1]
%aten_add_tensor : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.add.Tensor](args = (%aten_embedding_default, %aten_embedding_default_1), kwargs = {})
return (aten_add_tensor,)
%executorch_call_delegate : [num_users=1] = call_function[target=torch.ops.higher_order.executorch_call_delegate](args = (%lowered_module_0, %aten_embedding_default, %aten_embedding_default_1), kwargs = {})
%aten_sub_tensor : [num_users=1] = call_function[target=executorch.exir.dialects.edge._ops.aten.sub.Tensor](args = (%aten_unsqueeze_copy_default, %aten_unsqueeze_copy_default_1), kwargs = {})