def run_training_epoch(self):
    train_dataloader = self.trainer.accelerator.process_dataloader(self.trainer.train_dataloader)
    epoch_output = [[] for _ in range(self.num_optimizers)]
    train_dataloader = self.trainer.data_connector.get_profiled_train_dataloader(train_dataloader)
    dataloader_idx = 0
    val_loop_called = False
    batch_idx = None
    is_last_batch = None
    for (batch_idx, (batch, is_last_batch)) in train_dataloader:
        self.trainer.batch_idx = batch_idx
        self.trainer.is_last_batch = is_last_batch
        with self.trainer.profiler.profile('run_training_batch'):
            batch_output = self.run_training_batch(batch, batch_idx, dataloader_idx)
        if (batch_output.signal == (- 1)):
            break
        self.on_train_batch_end(epoch_output, batch_output.training_step_output_for_epoch_end, batch, batch_idx, dataloader_idx)
        self.trainer.logger_connector.log_train_step_metrics(batch_output)
        should_check_val = self._should_check_val_fx(batch_idx, is_last_batch)
        if should_check_val:
            self.trainer.validating = True
            self.trainer.run_evaluation()
            self.trainer.training = True
            val_loop_called = True
        self.save_loggers_on_train_batch_end()
        monitor_metrics = deepcopy(self.trainer.logger_connector.callback_metrics)
        self.update_train_loop_lr_schedulers(monitor_metrics=monitor_metrics)
        self.trainer.checkpoint_connector.has_trained = True
        if ((self.trainer.max_steps is not None) and (self.trainer.max_steps <= (self.trainer.global_step + 1)) and self._accumulated_batches_reached()):
            break
        if self.trainer.should_stop:
            break
        self.trainer.total_batch_idx += 1
        if self._num_training_batches_reached(is_last_batch):
            break
        self.increment_accumulated_grad_global_step()
    if (batch_idx is None):
        return
    self.on_train_epoch_end(epoch_output)
    self.trainer.logger_connector.log_train_epoch_end_metrics(epoch_output)
    should_check_val = self._should_check_val_fx(batch_idx, is_last_batch, on_epoch=True)
    should_skip_eval = self.trainer.evaluation_loop.should_skip_evaluation(self.trainer.num_val_batches)
    should_train_only = (self.trainer.disable_validation or should_skip_eval)
    if ((val_loop_called and (not should_check_val)) or should_train_only):
        self.trainer.optimizer_connector.update_learning_rates(interval='epoch')
    if should_train_only:
        self.check_checkpoint_callback(True)
    if should_check_val:
        self.trainer.validating = True
        self.trainer.run_evaluation(on_epoch=True)
        self.trainer.training = True
    self.increment_accumulated_grad_global_step()
def run_training_epoch(self):
    train_dataloader = self.trainer.accelerator.process_dataloader(self.trainer.train_dataloader)
    epoch_output = [[] for _ in range(self.num_optimizers)]
    train_dataloader = self.trainer.data_connector.get_profiled_train_dataloader(train_dataloader)
    dataloader_idx = 0
    val_loop_called = False
    batch_idx = None
    is_last_batch = None
    for (batch_idx, (batch, is_last_batch)) in train_dataloader:
        self.trainer.batch_idx = batch_idx
        self.trainer.is_last_batch = is_last_batch
        with self.trainer.profiler.profile('run_training_batch'):
            batch_output = self.run_training_batch(batch, batch_idx, dataloader_idx)
        if (batch_output.signal == (- 1)):
            break
        self.on_train_batch_end(epoch_output, batch_output.training_step_output_for_epoch_end, batch, batch_idx, dataloader_idx)
        self.trainer.logger_connector.log_train_step_metrics(batch_output)
        should_check_val = self._should_check_val_fx(batch_idx, is_last_batch)
        if should_check_val:
            self.trainer.validating = True
            self.trainer.run_evaluation()
            self.trainer.training = True
            val_loop_called = True
        self.save_loggers_on_train_batch_end()
        monitor_metrics = deepcopy(self.trainer.logger_connector.callback_metrics)
        self.update_train_loop_lr_schedulers(monitor_metrics=monitor_metrics)
        self.trainer.checkpoint_connector.has_trained = True
        if ((self.trainer.max_steps is not None) and (self.trainer.max_steps <= (self.trainer.global_step + 1)) and self._accumulated_batches_reached()):
            break
        if self.trainer.should_stop:
            break
        self.trainer.total_batch_idx += 1
        if self._num_training_batches_reached(is_last_batch):
            break
        self.increment_accumulated_grad_global_step()
    if (batch_idx is None):
        return
    self.on_train_epoch_end(epoch_output)
    self.trainer.logger_connector.log_train_epoch_end_metrics(epoch_output)
    should_check_val = self._should_check_val_fx(batch_idx, is_last_batch, on_epoch=True)
    should_skip_eval = self.trainer.evaluation_loop.should_skip_evaluation(self.trainer.num_val_batches)
    should_train_only = (self.trainer.disable_validation or should_skip_eval)
    if ((val_loop_called and (not should_check_val)) or should_train_only):
        self.trainer.optimizer_connector.update_learning_rates(interval='epoch')
    if should_train_only:
        self.check_checkpoint_callback(True)
    if should_check_val:
        self.trainer.validating = True
        self.trainer.run_evaluation(on_epoch=True)
        self.trainer.training = True
    self.increment_accumulated_grad_global_step()