def train(self) -> None:
    '\n        Train method to train the model.\n        '
    if self.args.debug:
        tf.summary.trace_on(graph=True, profiler=True)
    self.gradient_accumulator.reset()
    iterations = self.optimizer.iterations
    if (iterations.numpy() > 0):
        logger.info('Start the training from the last checkpoint')
        start_epoch = ((iterations.numpy() // self.train_steps) + 1)
    else:
        start_epoch = 1
    tf.summary.experimental.set_step(iterations)
    epochs = (1 if (self.args.max_steps > 0) else self.args.num_train_epochs)
    logger.info('***** Running training *****')
    logger.info('  Num examples = %d', self.num_train_examples)
    logger.info('  Num Epochs = %d', epochs)
    logger.info('  Total optimization steps = %d', self.train_steps)
    for epoch in range(start_epoch, int((epochs + 1))):
        for training_loss in self._training_steps():
            step = iterations.numpy()
            if self.args.debug:
                with self.writer.as_default():
                    tf.summary.scalar('loss', training_loss, step=step)
            if ((step == 1) and self.args.debug):
                with self.writer.as_default():
                    tf.summary.trace_export(name='training', step=step, profiler_outdir=self.args.logging_dir)
            if (self.args.evaluate_during_training and ((step % self.args.eval_steps) == 0)):
                logs = {}
                results = self.evaluate()
                for (key, value) in results.items():
                    eval_key = 'eval_{}'.format(key)
                    logs[eval_key] = value
                if callable(self.optimizer.learning_rate):
                    logs['learning_rate'] = self.optimizer.learning_rate(step).numpy()
                else:
                    logs['learning_rate'] = self.optimizer.learning_rate.numpy()
                logger.info('Epoch {} Step {} Validation Metrics {}'.format(epoch, step, logs))
                with self.writer.as_default():
                    for (k, v) in logs.items():
                        tf.summary.scalar(k, v, step=step)
            if ((step % self.args.logging_steps) == 0):
                logger.info('Epoch {} Step {} Train Loss {:.4f}'.format(epoch, step, training_loss.numpy()))
            if ((step % self.args.save_steps) == 0):
                ckpt_save_path = self.model.ckpt_manager.save()
                logger.info('Saving checkpoint for step {} at {}'.format(step, ckpt_save_path))
            if ((step % self.train_steps) == 0):
                break
Train method to train the model.
def train(self) -> None:
    '\n        \n        '
    if self.args.debug:
        tf.summary.trace_on(graph=True, profiler=True)
    self.gradient_accumulator.reset()
    iterations = self.optimizer.iterations
    if (iterations.numpy() > 0):
        logger.info('Start the training from the last checkpoint')
        start_epoch = ((iterations.numpy() // self.train_steps) + 1)
    else:
        start_epoch = 1
    tf.summary.experimental.set_step(iterations)
    epochs = (1 if (self.args.max_steps > 0) else self.args.num_train_epochs)
    logger.info('***** Running training *****')
    logger.info('  Num examples = %d', self.num_train_examples)
    logger.info('  Num Epochs = %d', epochs)
    logger.info('  Total optimization steps = %d', self.train_steps)
    for epoch in range(start_epoch, int((epochs + 1))):
        for training_loss in self._training_steps():
            step = iterations.numpy()
            if self.args.debug:
                with self.writer.as_default():
                    tf.summary.scalar('loss', training_loss, step=step)
            if ((step == 1) and self.args.debug):
                with self.writer.as_default():
                    tf.summary.trace_export(name='training', step=step, profiler_outdir=self.args.logging_dir)
            if (self.args.evaluate_during_training and ((step % self.args.eval_steps) == 0)):
                logs = {}
                results = self.evaluate()
                for (key, value) in results.items():
                    eval_key = 'eval_{}'.format(key)
                    logs[eval_key] = value
                if callable(self.optimizer.learning_rate):
                    logs['learning_rate'] = self.optimizer.learning_rate(step).numpy()
                else:
                    logs['learning_rate'] = self.optimizer.learning_rate.numpy()
                logger.info('Epoch {} Step {} Validation Metrics {}'.format(epoch, step, logs))
                with self.writer.as_default():
                    for (k, v) in logs.items():
                        tf.summary.scalar(k, v, step=step)
            if ((step % self.args.logging_steps) == 0):
                logger.info('Epoch {} Step {} Train Loss {:.4f}'.format(epoch, step, training_loss.numpy()))
            if ((step % self.args.save_steps) == 0):
                ckpt_save_path = self.model.ckpt_manager.save()
                logger.info('Saving checkpoint for step {} at {}'.format(step, ckpt_save_path))
            if ((step % self.train_steps) == 0):
                break