Exemple #1
0
    def test_resume_from_multiple_of_epoches(self, mock_evaluator, mock_checkpoint, mock_func):
        mock_model = mock.Mock()
        mock_optim = mock.Mock()

        trainer = SupervisedTrainer(batch_size=16)
        trainer.optimizer = mock_optim
        n_epoches = 1
        start_epoch = 1
        step = 7
        trainer._train_epoches(self.dataset, mock_model, n_epoches, start_epoch, step, dev_data=self.dataset)
Exemple #2
0
    def test_batch_num_when_resuming(self, mock_evaluator, mock_checkpoint, mock_func):
        mock_model = mock.Mock()
        mock_optim = mock.Mock()

        trainer = SupervisedTrainer(batch_size=16)
        trainer.optimizer = mock_optim
        n_epoches = 1
        start_epoch = 1
        steps_per_epoch = 7
        step = 3
        trainer._train_epoches(self.dataset, mock_model, n_epoches, start_epoch, step)
        self.assertEqual(steps_per_epoch - step, mock_func.call_count)
Exemple #3
0
    def test_resume_from_multiple_of_epoches(self, mock_evaluator, mock_checkpoint, mock_func):
        mock_optim = mock.Mock()

        trainer = SupervisedTrainer()
        trainer.model = mock.Mock()
        trainer.optimizer = mock.Mock()

        callbacks = CallbackContainer(trainer)

        n_epoches = 1
        start_epoch = 1
        step = 7
        trainer.set_local_parameters(123, [], [], [], 1, 1)
        trainer._train_epoches(
            self.data_iterator, n_epoches, start_epoch, step, callbacks, self.data_iterator)
Exemple #4
0
    def test_batch_num_when_resuming(self, mock_evaluator, mock_checkpoint, mock_func):

        trainer = SupervisedTrainer()
        trainer.model = mock.Mock()
        trainer.optimizer = mock.Mock()

        callbacks = CallbackContainer(trainer)

        n_epoches = 1
        start_epoch = 1
        steps_per_epoch = len(self.data_iterator)
        step = 3
        trainer.set_local_parameters(123, [], [], [], 1, 1)
        trainer._train_epoches(self.data_iterator, n_epoches,
                               start_epoch, step, callbacks, self.data_iterator)

        self.assertEqual(steps_per_epoch - step, mock_func.call_count)
Exemple #5
0
    @mock.patch('seq2seq.util.checkpoint.Checkpoint.save')
    @mock.patch('seq2seq.evaluator.Evaluator.evaluate', return_value=([],[]))
    def test_batch_num_when_resuming(self, mock_evaluator, mock_checkpoint, mock_func):
=======
    @mock.patch('machine.trainer.SupervisedTrainer._train_batch',
                return_value=[])
    @mock.patch('machine.util.checkpoint.Checkpoint.save')
    @mock.patch('machine.evaluator.Evaluator.evaluate', return_value=([], []))
    def test_batch_num_when_resuming(
            self, mock_evaluator, mock_checkpoint, mock_func):
>>>>>>> upstream/master
        mock_model = mock.Mock()
        mock_optim = mock.Mock()

        trainer = SupervisedTrainer(batch_size=16)
        trainer.optimizer = mock_optim
        n_epoches = 1
        start_epoch = 1
        steps_per_epoch = 7
        step = 3
        trainer._train_epoches(self.dataset, mock_model,
                               n_epoches, start_epoch, step)
        self.assertEqual(steps_per_epoch - step, mock_func.call_count)

    @mock.patch('machine.trainer.SupervisedTrainer._train_batch',
                return_value=0)
    @mock.patch('machine.util.checkpoint.Checkpoint.save')
    @mock.patch('machine.evaluator.Evaluator.evaluate', return_value=([], []))
    def test_resume_from_multiple_of_epoches(
            self, mock_evaluator, mock_checkpoint, mock_func):
        mock_model = mock.Mock()