dfo.py
def _prep_model(self):
        """
        Builds and initialized the model as described in the configuration.
        The model can be initialized randomly or from a checkpoint. In addition, pre-trained embeddings can
        loaded from a different checkpoint. See configs/example.yaml for more info.
        """

        # initialize model weights according to model_cfg
        self.model = build_model(self.model_cfg, src_vocab=self.src_vocab, trg_vocab=self.trg_vocab)
        self.logger.info('Model loaded.')

        if self.train_cfg.get('start', False):

            # load all model weights from a given checkpoint                                                  
            self.model_start = load_checkpoint(path=self.train_cfg['start'], use_cuda=self.use_cuda) 
            self.model.load_state_dict(self.model_start['model_state'])

            self.logger.info('Model checkpoint loaded from {}.'.format(self.train_cfg['start']))

        if self.train_cfg.get('emb_start', False):

            # load only the embeddings from a given checkpoint
            emb_start = load_checkpoint(path=self.train_cfg['emb_start'], use_cuda=self.use_cuda)                                          
            pretrained_embeddings = {name:param for name,param in emb_start['model_state'].items() if '_embed' in name}                                                 
            self.model.load_state_dict(pretrained_embeddings, strict=False)                     
            self.train_embeddings = False
            self.get_embedding_idxs()        # prepare to set all embedding perturbations to 0

            self.logger.info('Embeddings loaded from {}.'.format(self.train_cfg['emb_start']))

        for param in self.model.parameters():
            param.requires_grad = False           # disable gradients for faster computation and lower memory usage

        if self.use_cuda:
            self.model.cuda()       # move all the model parameters to CUDA; might be redundant

        self.model.eval()

        Builds and initialized the model as described in the configuration.
        The model can be initialized randomly or from a checkpoint. In addition, pre-trained embeddings can
        loaded from a different checkpoint. See configs/example.yaml for more info.
        
Builds and initialized the model as described in the configuration.
The model can be initialized randomly or from a checkpoint. In addition, pre-trained embeddings can
loaded from a different checkpoint. See configs/example.yaml for more info.
Builds and initialized the model as described in the configuration . The model can be initialized randomly or from a checkpoint . In addition pre - trained embeddings can loaded from a different checkpoint . See configs / example . yaml for more info .
def _prep_model(self):
        self.model = build_model(self.model_cfg, src_vocab=self.src_vocab, trg_vocab=self.trg_vocab)
        self.logger.info('Model loaded.')
        if self.train_cfg.get('start', False):
            self.model_start = load_checkpoint(path=self.train_cfg['start'], use_cuda=self.use_cuda) 
            self.model.load_state_dict(self.model_start['model_state'])
            self.logger.info('Model checkpoint loaded from {}.'.format(self.train_cfg['start']))
        if self.train_cfg.get('emb_start', False):
            emb_start = load_checkpoint(path=self.train_cfg['emb_start'], use_cuda=self.use_cuda)                                          
            pretrained_embeddings = {name:param for name,param in emb_start['model_state'].items() if '_embed' in name}                                                 
            self.model.load_state_dict(pretrained_embeddings, strict=False)                     
            self.train_embeddings = False
            self.get_embedding_idxs()        
            self.logger.info('Embeddings loaded from {}.'.format(self.train_cfg['emb_start']))
        for param in self.model.parameters():
            param.requires_grad = False           
        if self.use_cuda:
            self.model.cuda()       
        self.model.eval()
def _prep_model ( self ) : self . model = build_model ( self . model_cfg , src_vocab = self . src_vocab , trg_vocab = self . trg_vocab ) self . logger . info ( 'Model loaded.' ) if self . train_cfg . get ( 'start' , False ) : self . model_start = load_checkpoint ( path = self . train_cfg [ 'start' ] , use_cuda = self . use_cuda ) self . model . load_state_dict ( self . model_start [ 'model_state' ] ) self . logger . info ( 'Model checkpoint loaded from {}.' . format ( self . train_cfg [ 'start' ] ) ) if self . train_cfg . get ( 'emb_start' , False ) : emb_start = load_checkpoint ( path = self . train_cfg [ 'emb_start' ] , use_cuda = self . use_cuda ) pretrained_embeddings = { name : param for name , param in emb_start [ 'model_state' ] . items ( ) if '_embed' in name } self . model . load_state_dict ( pretrained_embeddings , strict = False ) self . train_embeddings = False self . get_embedding_idxs ( ) self . logger . info ( 'Embeddings loaded from {}.' . format ( self . train_cfg [ 'emb_start' ] ) ) for param in self . model . parameters ( ) : param . requires_grad = False if self . use_cuda : self . model . cuda ( ) self . model . eval ( )
Builds and initialized the model as described in the configuration.
Builds and initialized the model as described in the configuration .
"""
        Builds and initialized the model as described in the configuration.
        The model can be initialized randomly or from a checkpoint. In addition, pre-trained embeddings can
        loaded from a different checkpoint. See configs/example.yaml for more info.
        """ # initialize model weights according to model_cfg # load all model weights from a given checkpoint                                                   # load only the embeddings from a given checkpoint # prepare to set all embedding perturbations to 0 # disable gradients for faster computation and lower memory usage # move all the model parameters to CUDA; might be redundant
self