def train(self, args, path, dataloader, log_every=1, verbose=True):
    self.model.train()
    optimizer = get_optimizer(self.model.parameters(), self.base_lr)
    for epoch in range(self.epoch, self.num_epochs):
        (optimizer, lr) = update_lr(optimizer, epoch, self.num_epochs, self.base_lr, self.num_warmup_steps)
        epoch_loss = []
        epoch_acc = []
        pbar = dataloader
        for (count, batch) in enumerate(pbar):
            (_, features) = self.get_features(batch)
            (loss, acc) = self.train_batch(features, optimizer)
            epoch_loss.append(loss)
            epoch_acc.append(acc)
            if (verbose and ((count % log_every) == 0)):
                print('(node {}) training epoch ({}/{}) iter ({}/{}) (lr: {:04f}, loss: {:04f}, acc: {:04f})'.format(du.get_rank(), epoch, self.num_epochs, count, len(dataloader), lr, loss, acc))
        epoch_loss = np.array(epoch_loss).mean()
        epoch_acc = np.array(epoch_acc).mean()
        if verbose:
            print('(node {}) epoch ({}/{}) done (lr: {:04f}, loss: {:04f}, acc: {:04f})'.format(du.get_rank(), epoch, self.num_epochs, lr, epoch_loss, epoch_acc))
        self.epoch = epoch
        self.save_cache(args, path, epoch, verbose)
    return
def train(self, args, path, dataloader, log_every=1, verbose=True):
    self.model.train()
    optimizer = get_optimizer(self.model.parameters(), self.base_lr)
    for epoch in range(self.epoch, self.num_epochs):
        (optimizer, lr) = update_lr(optimizer, epoch, self.num_epochs, self.base_lr, self.num_warmup_steps)
        epoch_loss = []
        epoch_acc = []
        pbar = dataloader
        for (count, batch) in enumerate(pbar):
            (_, features) = self.get_features(batch)
            (loss, acc) = self.train_batch(features, optimizer)
            epoch_loss.append(loss)
            epoch_acc.append(acc)
            if (verbose and ((count % log_every) == 0)):
                print('(node {}) training epoch ({}/{}) iter ({}/{}) (lr: {:04f}, loss: {:04f}, acc: {:04f})'.format(du.get_rank(), epoch, self.num_epochs, count, len(dataloader), lr, loss, acc))
        epoch_loss = np.array(epoch_loss).mean()
        epoch_acc = np.array(epoch_acc).mean()
        if verbose:
            print('(node {}) epoch ({}/{}) done (lr: {:04f}, loss: {:04f}, acc: {:04f})'.format(du.get_rank(), epoch, self.num_epochs, lr, epoch_loss, epoch_acc))
        self.epoch = epoch
        self.save_cache(args, path, epoch, verbose)
    return