def _load(self, file):
    self.trainer.writer.write('Loading checkpoint')
    ckpt = self._torch_load(file)
    data_parallel = registry.get('data_parallel')
    if ('model' in ckpt):
        ckpt_model = ckpt['model']
    else:
        ckpt_model = ckpt
        ckpt = {'model': ckpt}
    pretrained_mapping = self.config.training_parameters.pretrained_mapping
    if (not self.config.training_parameters.load_pretrained):
        pretrained_mapping = {}
    new_dict = {}
    for attr in ckpt_model:
        if ('fa_history' in attr):
            new_dict[attr.replace('fa_history', 'fa_context')] = ckpt_model[attr]
        elif ((data_parallel is False) and attr.startswith('module.')):
            new_dict[attr.replace('module.', '', 1)] = ckpt_model[attr]
        else:
            new_dict[attr] = ckpt_model[attr]
    if (len(pretrained_mapping.items()) == 0):
        final_dict = new_dict
        self.trainer.model.load_state_dict(final_dict)
        if ('optimizer' in ckpt):
            self.trainer.optimizer.load_state_dict(ckpt['optimizer'])
        else:
            warnings.warn("'optimizer' key is not present in the checkpoint asked to be loaded. Skipping.")
        self.trainer.early_stopping.init_from_checkpoint(ckpt)
        self.trainer.writer.write('Checkpoint loaded')
        if ('best_iteration' in ckpt):
            self.trainer.current_iteration = ckpt['best_iteration']
            registry.register('current_iteration', self.trainer.current_iteration)
        if ('best_epoch' in ckpt):
            self.trainer.current_epoch = ckpt['best_epoch']
            registry.register('current_epoch', self.trainer.current_epoch)
    else:
        final_dict = {}
        model = self.trainer.model
        own_state = model.state_dict()
        for (key, value) in pretrained_mapping.items():
            key += '.'
            value += '.'
            for attr in new_dict:
                for own_attr in own_state:
                    if ((key in attr) and (value in own_attr) and (attr.replace(key, '') == own_attr.replace(value, ''))):
                        self.trainer.writer.write(((('Copying ' + attr) + ' ') + own_attr))
                        own_state[own_attr].copy_(new_dict[attr])
        self.trainer.writer.write('Pretrained model loaded')
def _load(self, file):
    self.trainer.writer.write('Loading checkpoint')
    ckpt = self._torch_load(file)
    data_parallel = registry.get('data_parallel')
    if ('model' in ckpt):
        ckpt_model = ckpt['model']
    else:
        ckpt_model = ckpt
        ckpt = {'model': ckpt}
    pretrained_mapping = self.config.training_parameters.pretrained_mapping
    if (not self.config.training_parameters.load_pretrained):
        pretrained_mapping = {}
    new_dict = {}
    for attr in ckpt_model:
        if ('fa_history' in attr):
            new_dict[attr.replace('fa_history', 'fa_context')] = ckpt_model[attr]
        elif ((data_parallel is False) and attr.startswith('module.')):
            new_dict[attr.replace('module.', , 1)] = ckpt_model[attr]
        else:
            new_dict[attr] = ckpt_model[attr]
    if (len(pretrained_mapping.items()) == 0):
        final_dict = new_dict
        self.trainer.model.load_state_dict(final_dict)
        if ('optimizer' in ckpt):
            self.trainer.optimizer.load_state_dict(ckpt['optimizer'])
        else:
            warnings.warn("'optimizer' key is not present in the checkpoint asked to be loaded. Skipping.")
        self.trainer.early_stopping.init_from_checkpoint(ckpt)
        self.trainer.writer.write('Checkpoint loaded')
        if ('best_iteration' in ckpt):
            self.trainer.current_iteration = ckpt['best_iteration']
            registry.register('current_iteration', self.trainer.current_iteration)
        if ('best_epoch' in ckpt):
            self.trainer.current_epoch = ckpt['best_epoch']
            registry.register('current_epoch', self.trainer.current_epoch)
    else:
        final_dict = {}
        model = self.trainer.model
        own_state = model.state_dict()
        for (key, value) in pretrained_mapping.items():
            key += '.'
            value += '.'
            for attr in new_dict:
                for own_attr in own_state:
                    if ((key in attr) and (value in own_attr) and (attr.replace(key, ) == own_attr.replace(value, ))):
                        self.trainer.writer.write(((('Copying ' + attr) + ' ') + own_attr))
                        own_state[own_attr].copy_(new_dict[attr])
        self.trainer.writer.write('Pretrained model loaded')