from tensorflow.python.ops import control_flow_ops

            if clones_gradients:
                if summarize_gradients:
                    # Add summaries to the gradients.
                    summaries |= set(_add_gradients_summaries(clones_gradients))

                # Create gradient updates.
                grad_updates = optimizer.apply_gradients(clones_gradients,
                                                         global_step=global_step)
                update_ops.append(grad_updates)

                update_op = tf.group(*update_ops)
                train_op = control_flow_ops.with_dependencies([update_op], total_loss,
                                                              name='train_op')
        else:
            clones_losses = []
            regularization_losses = tf.get_collection(
                    tf.GraphKeys.REGULARIZATION_LOSSES)
            for clone in clones:
                with tf.name_scope(clone.scope):
                    clone_loss = _gather_clone_loss(clone, len(clones),
                                                    regularization_losses)
                    if clone_loss is not None:
