示例#1
0
 def step(self, optimizer, arch_optimizer):
     self.train()
     losses = []
     train_bandit = utils.get_data_queue_bandit(self.args, self.contexts,
                                                self.pos_weights)
     cnt = 0
     time_data = 0
     time_forward = 0
     time_update = 0
     end = -1
     for step, features in enumerate(train_bandit):
         if end != -1:
             time_data += time.time() - end
         begin = time.time()
         optimizer.zero_grad()
         arch_optimizer.zero_grad()
         output, error_loss, loss_alpha = self.forward(features)
         time_forward += time.time() - begin
         losses.append(error_loss.cpu().detach().item())
         begin2 = time.time()
         optimizer.step()
         arch_optimizer.step()
         time_update += time.time() - begin2
         cnt += 1
         end = time.time()
     print("time_data: ", time_data)
     print("time_forward: ", time_forward)
     print("time_update: ", time_update)
     print("cnt: ", cnt)
     return np.mean(losses)
示例#2
0
 def step(self, optimizer, arch_optimizer):
     self.train()
     losses = []
     train_bandit = utils.get_data_queue_bandit(self.args, self.contexts, self.pos_weights)
     cnt = 0
     for step, features in enumerate(train_bandit):
         optimizer.zero_grad()
         output, error_loss, loss_alpha = self.forward(features)
         losses.append(error_loss.cpu().detach().item())
         optimizer.step()
         cnt += 1
     print("cnt: ", cnt)
     return np.mean(losses)
示例#3
0
 def step(self, optimizer, arch_optimizer, epoch):
     self.train()
     losses = []
     train_bandit = utils.get_data_queue_bandit(self.args, self.contexts,
                                                self.pos_weights)
     if epoch < self.args.search_epoch:
         train_epoch = (epoch + 1) * 5
     else:
         train_epoch = 1
     for k in range(train_epoch):
         for step, features in enumerate(train_bandit):
             optimizer.zero_grad()
             output, error_loss, loss_alpha = self.forward(features)
             losses.append(error_loss.cpu().detach().item())
             optimizer.step()
     return np.mean(losses)