def warm_up(self, *args, **kwargs):
    self.mi_model.train()
    num_samples = len(self.train_loader)
    warm_up_iterations = int((math.ceil(((self.opts.warm_up_iterations * 1.0) / num_samples)) * num_samples))
    print_info_message('Warming Up')
    print_log_message('LR will linearly change from {} to {} in about {} steps'.format(self.opts.warm_up_min_lr, self.opts.lr, warm_up_iterations))
    lr_list = np.linspace(1e-07, self.opts.lr, warm_up_iterations)
    epoch_start_time = time.time()
    iteration = (- 1)
    while (iteration < warm_up_iterations):
        warm_up_stats = Statistics()
        for (batch_id, batch) in enumerate(self.train_loader):
            if (iteration >= warm_up_iterations):
                break
            iteration += 1
            try:
                lr_iter = lr_list[iteration]
            except:
                lr_iter = self.opts.lr
            self.optimizer = update_optimizer(optimizer=self.optimizer, lr_value=lr_iter)
            (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()
            warm_up_stats.update(loss=loss.item(), acc=top1_acc[0].item())
            if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
                warm_up_stats.output(epoch=(- 1), batch=iteration, n_batches=warm_up_iterations, start=epoch_start_time, lr=lr_iter)
        gc.collect()
    print_log_message('Warming Up... Done!!!')
def warm_up(self, *args, **kwargs):
    self.mi_model.train()
    num_samples = len(self.train_loader)
    warm_up_iterations = int((math.ceil(((self.opts.warm_up_iterations * 1.0) / num_samples)) * num_samples))
    print_info_message('Warming Up')
    print_log_message('LR will linearly change from {} to {} in about {} steps'.format(self.opts.warm_up_min_lr, self.opts.lr, warm_up_iterations))
    lr_list = np.linspace(1e-07, self.opts.lr, warm_up_iterations)
    epoch_start_time = time.time()
    iteration = (- 1)
    while (iteration < warm_up_iterations):
        warm_up_stats = Statistics()
        for (batch_id, batch) in enumerate(self.train_loader):
            if (iteration >= warm_up_iterations):
                break
            iteration += 1
            try:
                lr_iter = lr_list[iteration]
            except:
                lr_iter = self.opts.lr
            self.optimizer = update_optimizer(optimizer=self.optimizer, lr_value=lr_iter)
            (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()
            warm_up_stats.update(loss=loss.item(), acc=top1_acc[0].item())
            if (((batch_id % self.opts.log_interval) == 0) and (batch_id > 0)):
                warm_up_stats.output(epoch=(- 1), batch=iteration, n_batches=warm_up_iterations, start=epoch_start_time, lr=lr_iter)
        gc.collect()
    print_log_message('Warming Up... Done!!!')