code: def graph_to_network(
      input1,
      input2,
      input1_lengths,
      input2_lengths,
      p_graph,
      dropout_rate,
      is_training,
      num_heads=1,
      rnn_units=256,
  ):
      topology = p_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
  
          # Note: here we use the `hash_id` of layer as scope name,
          #       so that we can automatically load sharable weights from previous trained models
          with tf.variable_scope(
              p_graph.layers[topo_i].hash_id, reuse=tf.AUTO_REUSE
          ):
              if (
                  p_graph.layers[topo_i].graph_type
                  == LayerType.input.value
              ):
                  continue
              elif (
                  p_graph.layers[topo_i].graph_type
                  == LayerType.attention.value
              ):
                  with tf.variable_scope("attention"):
                      layer = multihead_attention(
                          layers[p_graph.layers[topo_i].input[0]],
                          layers[p_graph.layers[topo_i].input[1]],
                          scope="multihead_attention",
                          dropout_rate=dropout_rate,
                          is_training=is_training,
                          num_heads=num_heads,
                          num_units=rnn_units * 2,
                      )
                      layer = feedforward(
                          layer,
                          scope="feedforward",
                          num_units=[rnn_units * 2 * 4, rnn_units * 2],
                      )
                  layers[topo_i] = layer
                  layers_sequence_lengths[
                      topo_i
                  ] = layers_sequence_lengths[
                      p_graph.layers[topo_i].input[0]
                  ]
              elif (
                  p_graph.layers[topo_i].graph_type
                  == LayerType.self_attention.value
              ):
                  with tf.variable_scope("self-attention"):
                      layer = multihead_attention(
                          layers[p_graph.layers[topo_i].input[0]],
                          layers[p_graph.layers[topo_i].input[0]],
                          scope="multihead_attention",
                          dropout_rate=dropout_rate,
                          is_training=is_training,
                          num_heads=num_heads,
                          num_units=rnn_units * 2,
                      )
                      layer = feedforward(
                          layer,
                          scope="feedforward",
                          num_units=[rnn_units * 2 * 4, rnn_units * 2],
                      )
                  layers[topo_i] = layer
                  layers_sequence_lengths[
                      topo_i
                  ] = layers_sequence_lengths[
                      p_graph.layers[topo_i].input[0]
                  ]
              elif (
                  p_graph.layers[topo_i].graph_type
                  == LayerType.rnn.value
              ):
                  with tf.variable_scope("rnn"):
                      layer = rnn(
                          layers[p_graph.layers[topo_i].input[0]],
                          layers_sequence_lengths[
                              p_graph.layers[topo_i].input[0]
                          ],
                          dropout_rate,
                          is_training,
                          rnn_units,
                      )
                  layers[topo_i] = layer
                  layers_sequence_lengths[
                      topo_i
                  ] = layers_sequence_lengths[
                      p_graph.layers[topo_i].input[0]
                  ]
              elif (
                  p_graph.layers[topo_i].graph_type
                  == LayerType.output.value
              ):
                  layers[topo_i] = layers[
                      p_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/weight_sharing/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, p_graph, dropout_rate, is_training, num_heads, rnn_units) and returns: layers,  layers