Example #1
0
    def extend(op: Node):
        def normalize_port_map(port_map: dict):
            for port in port_map:
                for elem in ['axis', 'stride', 'part_size', 'start', 'end']:
                    if port.get(elem) is None:
                        port[elem] = None

        assert op.has(
            'body'
        ), 'Something wrong with TensorIterator layer {}, please check!'.format(
            op.name)

        # Now op.body is an IREngine, we need to replace it with IREngine.graph
        op.body.graph.graph['cmd_params'] = op.graph.graph['cmd_params']
        op.body.graph.graph['ir_version'] = op.graph.graph['ir_version']
        op.body.graph.name = op.name + '/body'

        for node in op.body.graph.get_op_nodes():
            node['internal_layer_id'] = int(node.id)

        op.body = copy_graph_with_ops(op.body.graph)

        normalize_port_map(op.input_port_map)
        normalize_port_map(op.output_port_map)

        for edge in op.back_edges:
            edge['from_layer'] = edge['from-layer']
            edge['to_layer'] = edge['to-layer']

            del (edge['from-layer'])
            del (edge['to-layer'])

        op['infer'] = Extender.use_shapes_from_ir
Example #2
0
    def extend(op: Node):
        assert op.has(
            'then_graph'
        ), 'There is no "then_body" attribute in the If op {}.'.format(op.name)
        assert op.has(
            'else_graph'
        ), 'There is no "else_body" attribute in the If op {}.'.format(op.name)
        # Now op.body is an IREngine, we need to replace it with IREngine.graph
        op.then_graph.graph.graph['cmd_params'] = op.graph.graph['cmd_params']
        op.then_graph.graph.graph['ir_version'] = op.graph.graph['ir_version']
        op.then_graph.graph.name = op.name + '/then_body'

        op.else_graph.graph.graph['cmd_params'] = op.graph.graph['cmd_params']
        op.else_graph.graph.graph['ir_version'] = op.graph.graph['ir_version']
        op.else_graph.graph.name = op.name + '/else_body'
        op.then_graph = copy_graph_with_ops(op.then_graph.graph)
        op.else_graph = copy_graph_with_ops(op.else_graph.graph)

        IfExtender.set_input_output_id(op.then_graph, op.then_input_port_map,
                                       op.then_output_port_map)
        IfExtender.set_input_output_id(op.else_graph, op.else_input_port_map,
                                       op.else_output_port_map)
Example #3
0
def restore_graph_from_ir(path_to_xml: str, path_to_bin: str = None) -> (Graph, dict):
    """
    Function to make valid graph and metadata for MO back stage from IR.
    :param path_to_xml:
    :param path_to_bin:
    :return: (restored graph, meta data)
    """
    ir = IREngine(path_to_xml, path_to_bin)
    assert ir.graph.graph.get('ir_version') >= 10, 'IR version {} is not supported, ' \
        'please generate actual IR for your model and use it.'.format(ir.graph.graph.get('ir_version'))

    path = get_mo_root_dir()
    collect_ops(path)
    collect_extenders(path)

    # Create a new copy of graph with correct attributes (shape & type infer, backend attrs etc.)
    new_graph = copy_graph_with_ops(ir.graph)

    return new_graph, copy(ir.meta_data)
Example #4
0
    def extend(op: Node):
        def normalize_port_map(port_map: dict):
            for port in port_map:
                for elem in [
                        'axis', 'stride', 'part_size', 'start', 'end',
                        'purpose'
                ]:
                    if port.get(elem) is None:
                        port[elem] = None

        assert op.has(
            'body'), 'There is no "body" attribute in the Loop op {}.'.format(
                op.name)

        # Now op.body is an IREngine, we need to replace it with IREngine.graph
        op.body.graph.graph['cmd_params'] = op.graph.graph['cmd_params']
        op.body.graph.graph['ir_version'] = op.graph.graph['ir_version']
        op.body.graph.name = op.name + '/body'

        for node in op.body.graph.get_op_nodes():
            node['internal_layer_id'] = int(node.id)

        op.body = copy_graph_with_ops(op.body.graph)

        normalize_port_map(op.input_port_map)
        normalize_port_map(op.output_port_map)

        # the 'external_port_id' uses end-to-end numbering of ports, but at this moment it is separate for input and
        # output ports so we need to decrease the output por_id with a number of input ports
        for record in op.output_port_map:
            if record['external_port_id'] != -1:
                record['external_port_id'] -= len(op.in_ports())

        for edge in op.back_edges:
            edge['from_layer'] = edge['from-layer']
            edge['to_layer'] = edge['to-layer']

            edge['to_port'] = 0
            edge['from_port'] = 0

            del (edge['from-layer'])
            del (edge['to-layer'])