コード例 #1
0
ファイル: checkpoints.py プロジェクト: sonoisa/phrasenode
 def initialize(cls, model, optimizer):
     train_steps = 0
     max_grad_norm = 0
     random_state = RandomState()
     return TrainState(model=model,
                       optimizer=optimizer,
                       train_steps=train_steps,
                       random_state=random_state,
                       max_grad_norm=max_grad_norm)
コード例 #2
0
    def save(self, path):
        gtd.io.makedirs(path)

        # Store the latest random state
        self.random_state = RandomState()

        # save model
        torch.save(self.model.state_dict(), join(path, 'model'))
        torch.save(self.optimizer.state_dict(), join(path, 'optimizer'))

        # pickle remaining attributes
        d = {attr: getattr(self, attr) for attr in ['train_steps', 'random_state', 'max_grad_norm']}
        with open(join(path, 'metadata.p'), 'wb') as f:
            pickle.dump(d, f)
コード例 #3
0
ファイル: checkpoints.py プロジェクト: SAGNIKMJR/wge
    def save(self, path):
        gtd.io.makedirs(path)

        # Store the latest random state
        self.random_state = RandomState()

        # save model
        chkpt_dct = {'model': self.model.state_dict(),
                     'optimizer': self.optimizer.state_dict(),
                     }
        torch.save(chkpt_dct, join(path, 'checkpoint.pth.tar'))
        # torch.save(self.model.state_dict(), join(path, 'model'))
        # torch.save(self.optimizer.state_dict(), join(path, 'optimizer'))

        # pickle remaining attributes
        d = {attr: getattr(self, attr) for attr in ['train_steps', 'random_state', 'max_grad_norm']}
        import json