(epochs, model, trainloader, criterion, optimizer)
No-frills pre-training method.
  
    :param epochs: Number of epochs
    :type epochs: `int`
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param trainloader: Training dataloader
    :param criterion: Loss criterion
    :param optimizer: Optimizer to use
No-frills pre-training method.
  
    :param epochs: Number of epochs
    :type epochs: `int`
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param trainloader: Training dataloader
    :param criterion: Loss criterion
    :param optimizer: Optimizer to use
No - frills pre - training method . : param epochs : Number of epochs : type epochs : int : param model : PyTorch model : type model : torch . nn . Module : param trainloader : Training dataloader : param criterion : Loss criterion : param optimizer : Optimizer to use
def pretrain(epochs, model, trainloader, criterion, optimizer):
    """
    No-frills pre-training method.
  
    :param epochs: Number of epochs
    :type epochs: `int`
    :param model: PyTorch model
    :type model: `torch.nn.Module`
    :param trainloader: Training dataloader
    :param criterion: Loss criterion
    :param optimizer: Optimizer to use
    """
    _config = {'epochs': epochs}
    logging.info('[Condensa] PRETRAIN CONFIG [' +
                 ', '.join('{!s}={!r}'.format(k, v)
                           for k, v in _config.items()) + ']')

    use_cuda = torch.cuda.is_available()
    if use_cuda:
        model = model.cuda()
        model = torch.nn.DataParallel(model)
    mb_iterator = iter(trainloader)
    model.train()
    for j in range(0, epochs):
        if logger.isEnabledFor(logging.INFO):
            pbar = tqdm(total=len(trainloader),
                        ascii=True,
                        desc='Epoch {}'.format(j))
        for input, target in trainloader:
            if torch.cuda.is_available():
                input = input.cuda(non_blocking=True)
                target = target.cuda(non_blocking=True)
            input, target = Variable(input), Variable(target)
            optimizer.zero_grad()
            output = model(input)
            loss = criterion(output, target)
            loss.backward()
            optimizer.step()
            if logger.isEnabledFor(logging.INFO):
                pbar.update()
    if logger.isEnabledFor(logging.INFO):
        pbar.close()
    logging.info('')
def pretrain ( epochs , model , trainloader , criterion , optimizer ) : _config = { 'epochs' : epochs } logging . info ( '[Condensa] PRETRAIN CONFIG [' + ', ' . join ( '{!s}={!r}' . format ( k , v ) for k , v in _config . items ( ) ) + ']' ) use_cuda = torch . cuda . is_available ( ) if use_cuda : model = model . cuda ( ) model = torch . nn . DataParallel ( model ) mb_iterator = iter ( trainloader ) model . train ( ) for j in range ( 0 , epochs ) : if logger . isEnabledFor ( logging . INFO ) : pbar = tqdm ( total = len ( trainloader ) , ascii = True , desc = 'Epoch {}' . format ( j ) ) for input , target in trainloader : if torch . cuda . is_available ( ) : input = input . cuda ( non_blocking = True ) target = target . cuda ( non_blocking = True ) input , target = Variable ( input ) , Variable ( target ) optimizer . zero_grad ( ) output = model ( input ) loss = criterion ( output , target ) loss . backward ( ) optimizer . step ( ) if logger . isEnabledFor ( logging . INFO ) : pbar . update ( ) if logger . isEnabledFor ( logging . INFO ) : pbar . close ( ) logging . info ( '' )