def training(self, epoch, lr, *args, **kwargs):
    train_stats = Statistics()
    self.mi_model.train()
    self.optimizer.zero_grad()
    num_samples = len(self.train_loader)
    epoch_start_time = time.time()
    for (batch_id, batch) in enumerate(self.train_loader):
        (words, true_diag_labels) = batch
        true_diag_labels = true_diag_labels.to(device=self.device)
        pred_diag_labels = prediction(words=words, cnn_model=self.base_feature_extractor, mi_model=self.mi_model, max_bsz_cnn_gpu0=self.max_bsz_cnn_gpu0, num_gpus=self.num_gpus, device=self.device)
        loss = self.criteria(pred_diag_labels, true_diag_labels)
        top1_acc = accuracy(pred_diag_labels, true_diag_labels, topk=(1,))
        loss.backward()
        if ((((batch_id + 1) % self.opts.accum_count) == 0) or ((batch_id + 1) == len(self.train_loader))):
            self.optimizer.step()
            self.optimizer.zero_grad()
        train_stats.update(loss=loss.item(), acc=top1_acc[0].item())
        if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
            train_stats.output(epoch=epoch, batch=batch_id, n_batches=num_samples, start=epoch_start_time, lr=lr)
    return (train_stats.avg_acc(), train_stats.avg_loss())
def training(self, epoch, lr, *args, **kwargs):
    train_stats = Statistics()
    self.mi_model.train()
    self.optimizer.zero_grad()
    num_samples = len(self.train_loader)
    epoch_start_time = time.time()
    for (batch_id, batch) in enumerate(self.train_loader):
        (words, true_diag_labels) = batch
        true_diag_labels = true_diag_labels.to(device=self.device)
        pred_diag_labels = prediction(words=words, cnn_model=self.base_feature_extractor, mi_model=self.mi_model, max_bsz_cnn_gpu0=self.max_bsz_cnn_gpu0, num_gpus=self.num_gpus, device=self.device)
        loss = self.criteria(pred_diag_labels, true_diag_labels)
        top1_acc = accuracy(pred_diag_labels, true_diag_labels, topk=(1,))
        loss.backward()
        if ((((batch_id + 1) % self.opts.accum_count) == 0) or ((batch_id + 1) == len(self.train_loader))):
            self.optimizer.step()
            self.optimizer.zero_grad()
        train_stats.update(loss=loss.item(), acc=top1_acc[0].item())
        if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
            train_stats.output(epoch=epoch, batch=batch_id, n_batches=num_samples, start=epoch_start_time, lr=lr)
    return (train_stats.avg_acc(), train_stats.avg_loss())