'Performs training on the currently defined Tensorflow graph.
Returns:
A tuple of the training Hit@1 and the training PERR.'

def run(self, start_new_model=False):

    if (self.is_master and start_new_model):
        self.remove_training_directory(self.train_dir)
    (target, device_fn) = self.start_server_if_distributed()
    meta_filename = self.get_meta_filename(start_new_model, self.train_dir)
    with tf.Graph().as_default() as graph:
        if meta_filename:
            saver = self.recover_model(meta_filename)
        with tf.device(device_fn):
            if (not meta_filename):
                saver = self.build_model(self.model, self.reader)
            global_step = tf.get_collection('global_step')[0]
            loss = tf.get_collection('loss')[0]
            predictions = tf.get_collection('predictions')[0]
            labels = tf.get_collection('labels')[0]
            train_op = tf.get_collection('train_op')[0]
            init_op = tf.global_variables_initializer()
    sv = tf.train.Supervisor(graph, logdir=self.train_dir, init_op=init_op, is_chief=self.is_master, global_step=global_step, save_model_secs=(15 * 60), save_summaries_secs=120, saver=saver)
    logging.info('%s:    Starting    managed    session.', task_as_string(self.task))
    with sv.managed_session(target, config=self.config) as sess:
        try:
            logging.info('%s:    Entering    training    loop.', task_as_string(self.task))
            while ((not sv.should_stop()) and (not self.max_steps_reached)):
                batch_start_time = time.time()
                (_, global_step_val, loss_val, predictions_val, labels_val) = sess.run([train_op, global_step, loss, predictions, labels])
                seconds_per_batch = (time.time() - batch_start_time)
                examples_per_second = (labels_val.shape[0] / seconds_per_batch)
                if (self.max_steps and (self.max_steps <= global_step_val)):
                    self.max_steps_reached = True
                if (self.is_master and ((global_step_val % 10) == 0) and self.train_dir):
                    eval_start_time = time.time()
                    hit_at_one = eval_util.calculate_hit_at_one(predictions_val, labels_val)
                    perr = eval_util.calculate_precision_at_equal_recall_rate(predictions_val, labels_val)
                    gap = eval_util.calculate_gap(predictions_val, labels_val)
                    eval_end_time = time.time()
                    eval_time = (eval_end_time - eval_start_time)
                    logging.info(((((((((((('training    step    ' + str(global_step_val)) + '    |    Loss:    ') + ('%.2f' % loss_val)) + '    Examples/sec:    ') + ('%.2f' % examples_per_second)) + '    |    Hit@1:    ') + ('%.2f' % hit_at_one)) + '    PERR:    ') + ('%.2f' % perr)) + '    GAP:    ') + ('%.2f' % gap)))
                    sv.summary_writer.add_summary(utils.MakeSummary('model/Training_Hit@1', hit_at_one), global_step_val)
                    sv.summary_writer.add_summary(utils.MakeSummary('model/Training_Perr', perr), global_step_val)
                    sv.summary_writer.add_summary(utils.MakeSummary('model/Training_GAP', gap), global_step_val)
                    sv.summary_writer.add_summary(utils.MakeSummary('global_step/Examples/Second', examples_per_second), global_step_val)
                    sv.summary_writer.flush()
                    time_to_export = ((self.last_model_export_step == 0) or ((global_step_val - self.last_model_export_step) >= self.export_model_steps))
                    if (self.is_master and time_to_export):
                        self.export_model(global_step_val, sv.saver, sv.save_path, sess)
                        self.last_model_export_step = global_step_val
                else:
                    logging.info(((((('training    step    ' + str(global_step_val)) + '    |    Loss:    ') + ('%.2f' % loss_val)) + '    Examples/sec:    ') + ('%.2f' % examples_per_second)))
        except tf.errors.OutOfRangeError:
            logging.info('%s:    Done    training    --    epoch    limit    reached.', task_as_string(self.task))
    logging.info('%s:    Exited    training    loop.', task_as_string(self.task))
    sv.Stop()
