code: def graph_to_network(
      input1,
      input2,
      input1_lengths,
      input2_lengths,
      graph,
      dropout_rate,
      is_training,
      num_heads=1,
      rnn_units=256,
  ):
      topology = graph.is_topology()
      layers = dict()
      layers_sequence_lengths = dict()
      num_units = input1.get_shape().as_list()[-1]
      layers[0] = input1 * tf.sqrt(
          tf.cast(num_units, tf.float32)
      ) + positional_encoding(input1, scale=False, zero_pad=False)
      layers[1] = input2 * tf.sqrt(tf.cast(num_units, tf.float32))
      layers[0] = dropout(layers[0], dropout_rate, is_training)
      layers[1] = dropout(layers[1], dropout_rate, is_training)
      layers_sequence_lengths[0] = input1_lengths
      layers_sequence_lengths[1] = input2_lengths
      for _, topo_i in enumerate(topology):
          if topo_i == "|":
              continue
          if graph.layers[topo_i].graph_type == LayerType.input.value:
              continue
          elif (
              graph.layers[topo_i].graph_type
              == LayerType.attention.value
          ):
              with tf.variable_scope("attation_%d" % topo_i):
                  layer = multihead_attention(
                      layers[graph.layers[topo_i].input[0]],
                      layers[graph.layers[topo_i].input[1]],
                      scope="multihead_attention%d" % topo_i,
                      dropout_rate=dropout_rate,
                      is_training=is_training,
                      num_heads=num_heads,
                      num_units=rnn_units * 2,
                  )
                  layer = feedforward(
                      layer,
                      scope="feedforward%d" % topo_i,
                      num_units=[rnn_units * 2 * 4, rnn_units * 2],
                  )
              layers[topo_i] = layer
              layers_sequence_lengths[topo_i] = layers_sequence_lengths[
                  graph.layers[topo_i].input[0]
              ]
          elif (
              graph.layers[topo_i].graph_type
              == LayerType.self_attention.value
          ):
              with tf.variable_scope("self-attation_%d" % topo_i):
                  layer = multihead_attention(
                      layers[graph.layers[topo_i].input[0]],
                      layers[graph.layers[topo_i].input[0]],
                      scope="multihead_attention%d" % topo_i,
                      dropout_rate=dropout_rate,
                      is_training=is_training,
                      num_heads=num_heads,
                      num_units=rnn_units * 2,
                  )
                  layer = feedforward(
                      layer,
                      scope="feedforward%d" % topo_i,
                      num_units=[rnn_units * 2 * 4, rnn_units * 2],
                  )
              layers[topo_i] = layer
              layers_sequence_lengths[topo_i] = layers_sequence_lengths[
                  graph.layers[topo_i].input[0]
              ]
          elif graph.layers[topo_i].graph_type == LayerType.rnn.value:
              with tf.variable_scope("rnn_%d" % topo_i):
                  layer = rnn(
                      layers[graph.layers[topo_i].input[0]],
                      layers_sequence_lengths[
                          graph.layers[topo_i].input[0]
                      ],
                      dropout_rate,
                      is_training,
                      rnn_units,
                  )
              layers[topo_i] = layer
              layers_sequence_lengths[topo_i] = layers_sequence_lengths[
                  graph.layers[topo_i].input[0]
              ]
          elif (
              graph.layers[topo_i].graph_type == LayerType.output.value
          ):
              layers[topo_i] = layers[graph.layers[topo_i].input[0]]
              if (
                  layers[topo_i].get_shape().as_list()[-1]
                  != rnn_units * 1 * 2
              ):
                  with tf.variable_scope("add_dense"):
                      layers[topo_i] = tf.layers.dense(
                          layers[topo_i], units=rnn_units * 2
                      )
      return layers[2], layers[3]
  
file_path: nni/examples/trials/ga_squad/graph_to_tf.py
imports: import tensorflow
  from rnn import XGRUCell
  from util import dropout
  from graph import LayerType
label_desc: Use image node_id 6 for calling a global function with example usage: graph_to_network(input1, input2, input1_lengths, input2_lengths, graph, dropout_rate, is_training, num_heads, rnn_units) and returns: layers,  layers