TrainingExtensions/torch/src/python/aimet_torch/meta/connectedgraph.py
def _handle_tuple_unpack_ir_node(ir_node: IrNode, connections_to_ir_nodes_dict: ConnectionsToIrDictType):
    """
    Update connections of tuple unpack nodes, as well as connections to children of the node.
    :param ir_node: Tuple or list construct node
    :param connections_to_ir_nodes_dict: Dictionary mapping connections to input node and output nodes
    """
    # For tuple unpack, either input came from tuple pack, or an op that had multiple outputs
    assert len(ir_node.inputs) == 1
    tuple_unpack_input = ir_node.inputs[0]
    if isinstance(tuple_unpack_input, List):
        # Case where input came from tuple pack
        # Length of unpacked output should be same as length of input to tuple pack
        assert len(tuple_unpack_input) == len(ir_node.outputs)
        # For each output, find consumers of the output. For the input connection to the consumer that matches
        # the output, replace it with the corresponding input connection to tuple_unpack.
        # Also replace the output of tuple unpack with the corresponding input connection.
        for idx, output in enumerate(ir_node.outputs):
            consumers = connections_to_ir_nodes_dict[output][1]
            for consumer in consumers:
                connection_index = consumer.inputs.index(output)
                consumer.inputs[connection_index] = tuple_unpack_input[idx]
            ir_node.outputs[idx] = tuple_unpack_input[idx]
            del connections_to_ir_nodes_dict[output]
    else:
        # Case where input came from op with multiple outputs
        # Replace the output connection of the op with the outputs of TupleUnpack
        producer = connections_to_ir_nodes_dict[tuple_unpack_input][0]

        # Producer can be None if a ListUnpack follows a values passthrough op for processing dict inputs
        if producer is not None:
            producer.outputs = ir_node.outputs
        ir_node.inputs = ir_node.outputs
        # Remove what used to be the input to the tuple unpack node from connections_to_ir_nodes_dict
        del connections_to_ir_nodes_dict[tuple_unpack_input]

    Update connections of tuple unpack nodes, as well as connections to children of the node.
    :param ir_node: Tuple or list construct node
    :param connections_to_ir_nodes_dict: Dictionary mapping connections to input node and output nodes
    
Update connections of tuple unpack nodes, as well as connections to children of the node.
Update connections of tuple unpack nodes as well as connections to children of the node .
def _handle_tuple_unpack_ir_node(ir_node: IrNode, connections_to_ir_nodes_dict: ConnectionsToIrDictType):
    assert len(ir_node.inputs) == 1
    tuple_unpack_input = ir_node.inputs[0]
    if isinstance(tuple_unpack_input, List):
        assert len(tuple_unpack_input) == len(ir_node.outputs)
        for idx, output in enumerate(ir_node.outputs):
            consumers = connections_to_ir_nodes_dict[output][1]
            for consumer in consumers:
                connection_index = consumer.inputs.index(output)
                consumer.inputs[connection_index] = tuple_unpack_input[idx]
            ir_node.outputs[idx] = tuple_unpack_input[idx]
            del connections_to_ir_nodes_dict[output]
    else:
        producer = connections_to_ir_nodes_dict[tuple_unpack_input][0]
        if producer is not None:
            producer.outputs = ir_node.outputs
        ir_node.inputs = ir_node.outputs
        del connections_to_ir_nodes_dict[tuple_unpack_input]
def _handle_tuple_unpack_ir_node ( ir_node : IrNode , connections_to_ir_nodes_dict : ConnectionsToIrDictType ) : assert len ( ir_node . inputs ) == 1 tuple_unpack_input = ir_node . inputs [ 0 ] if isinstance ( tuple_unpack_input , List ) : assert len ( tuple_unpack_input ) == len ( ir_node . outputs ) for idx , output in enumerate ( ir_node . outputs ) : consumers = connections_to_ir_nodes_dict [ output ] [ 1 ] for consumer in consumers : connection_index = consumer . inputs . index ( output ) consumer . inputs [ connection_index ] = tuple_unpack_input [ idx ] ir_node . outputs [ idx ] = tuple_unpack_input [ idx ] del connections_to_ir_nodes_dict [ output ] else : producer = connections_to_ir_nodes_dict [ tuple_unpack_input ] [ 0 ] if producer is not None : producer . outputs = ir_node . outputs ir_node . inputs = ir_node . outputs del connections_to_ir_nodes_dict [ tuple_unpack_input ]
Update connections of tuple unpack nodes, as well as connections to children of the node.
Update connections of tuple unpack nodes as well as connections to children of the node .
"""
    Update connections of tuple unpack nodes, as well as connections to children of the node.
    :param ir_node: Tuple or list construct node
    :param connections_to_ir_nodes_dict: Dictionary mapping connections to input node and output nodes
    """ # For tuple unpack, either input came from tuple pack, or an op that had multiple outputs # Case where input came from tuple pack # Length of unpacked output should be same as length of input to tuple pack # For each output, find consumers of the output. For the input connection to the consumer that matches # the output, replace it with the corresponding input connection to tuple_unpack. # Also replace the output of tuple unpack with the corresponding input connection. # Case where input came from op with multiple outputs # Replace the output connection of the op with the outputs of TupleUnpack # Producer can be None if a ListUnpack follows a values passthrough op for processing dict inputs # Remove what used to be the input to the tuple unpack node from connections_to_ir_nodes_dict
ir_node
IrNode
Tuple or list construct node
Tuple or list construct node
connections_to_ir_nodes_dict
ConnectionsToIrDictType
Dictionary mapping connections to input node and output nodes
Dictionary mapping connections to input node and output nodes