Пример #1
0
    def find_and_replace_pattern(self, graph: Graph):
        add_output_ops(graph,
                       graph.graph['packed_outputs'],
                       inputs=graph.graph['user_shapes'])

        # For keeping tensor names information for output nodes fake outputs are added
        # to graph during the model loading. In the following code fake outputs are removed
        # and tensor names information is moved to output->Result edge.
        for node in graph.get_op_nodes(needs_removal=True):
            fw_info = None
            in_node = None
            for in_port_idx in node.in_edges():
                node_idx = node.in_edge(in_port_idx)['in']
                if node_idx in node.in_nodes():
                    in_node = node.in_node(node_idx)
                    fw_info_value = get_edge_attribute_between_nodes(
                        in_node, node, 'fw_tensor_debug_info')
                    if fw_info_value:
                        fw_info = fw_info_value
                        break
            graph.erase_node(node)

            if fw_info is not None and in_node is not None:
                for out_idx in in_node.out_nodes():
                    set_edge_attribute_between_nodes(in_node,
                                                     in_node.out_node(out_idx),
                                                     'fw_tensor_debug_info',
                                                     fw_info)
Пример #2
0
def clear_tensor_names_info(nodes: list):
    """
    Clears tensor names information from 'fw_tensor_debug_info' attribute for all edges outgoing from
    given nodes.
    This method is used in cases when transformation adds postprocessing and the result does not
    correspond to the original tensor.
    This method should only be used during the front phase.
    :param nodes: list of Node objects.
    """
    for node in nodes:
        for out_idx in node.out_nodes():
            out_node = node.out_node(out_idx)
            fw_info_list = get_edge_attribute_between_nodes(
                node, out_node, 'fw_tensor_debug_info')
            new_fw_info = []
            for fw_info in fw_info_list:
                if fw_info is not None and len(fw_info) >= 2:
                    new_fw_info.append((fw_info[0], fw_info[1], None))
            set_edge_attribute_between_nodes(node, out_node,
                                             'fw_tensor_debug_info',
                                             new_fw_info)