code: def test_graph_multi_gpu():
      iterator_initializers = []
  
      with tf.device("/cpu:0"):
          tower_grads = []
  
          for i in range(mnist.num_available_gpus()):
              with tf.device("/gpu:{}".format(i)):
                  daliset = mnist.get_dataset(
                      "gpu", i, i, mnist.num_available_gpus()
                  )
  
                  iterator = tf_v1.data.make_initializable_iterator(
                      daliset
                  )
                  iterator_initializers.append(iterator.initializer)
                  images, labels = iterator.get_next()
  
                  images = tf_v1.reshape(
                      images,
                      [
                          mnist.BATCH_SIZE,
                          mnist.IMAGE_SIZE * mnist.IMAGE_SIZE,
                      ],
                  )
                  labels = tf_v1.reshape(
                      tf_v1.one_hot(labels, mnist.NUM_CLASSES),
                      [mnist.BATCH_SIZE, mnist.NUM_CLASSES],
                  )
  
                  logits_train = mnist.graph_model(
                      images, reuse=(i != 0), is_training=True
                  )
                  logits_test = mnist.graph_model(
                      images, reuse=True, is_training=False
                  )
  
                  loss_op = tf_v1.reduce_mean(
                      tf_v1.nn.softmax_cross_entropy_with_logits(
                          logits=logits_train, labels=labels
                      )
                  )
                  optimizer = tf_v1.train.AdamOptimizer()
                  grads = optimizer.compute_gradients(loss_op)
  
                  if i == 0:
                      correct_pred = tf_v1.equal(
                          tf_v1.argmax(logits_test, 1),
                          tf_v1.argmax(labels, 1),
                      )
                      accuracy = tf_v1.reduce_mean(
                          tf_v1.cast(correct_pred, tf_v1.float32)
                      )
  
                  tower_grads.append(grads)
  
          tower_grads = average_gradients(tower_grads)
          train_step = optimizer.apply_gradients(tower_grads)
  
      mnist.train_graph(iterator_initializers, train_step, accuracy)
  
file_path: DALI/dali/test/python/test_dali_tf_dataset_mnist_graph.py
imports: import tensorflow
  import tensorflow.compat.v1
  from nose import with_setup
  import test_dali_tf_dataset_mnist
  from nose_utils import raises
label_desc: Use image node_id 10 for calling a global function with example usage: test_graph_multi_gpu() without return types