Beispiel #1
0
        def get_tl(tmpdir):
            final_opt = Opt({
                'task': 'integration_tests',
                'datatype': 'valid',
                'validation_max_exs': 30,
                'short_final_eval': True,
            })
            final_opt.save(os.path.join(tmpdir, "final_opt.opt"))

            opt = Opt({
                'task':
                'integration_tests',
                'validation_max_exs':
                10,
                'model':
                'repeat_label',
                'model_file':
                os.path.join(tmpdir, 'model'),
                'short_final_eval':
                True,
                'num_epochs':
                1.0,
                'final_extra_opt':
                str(os.path.join(tmpdir, "final_opt.opt")),
            })
            parser = tms.setup_args()
            parser.set_params(**opt)
            popt = parser.parse_args([])
            for k, v in opt.items():
                popt[k] = v
            return tms.TrainLoop(popt)
Beispiel #2
0
    def test_allow_missing_init_opts(self):
        """
        Test --allow-missing-init-opts.
        """

        with testing_utils.tempdir() as temp_dir:

            init_opt_path = os.path.join(temp_dir, 'init_opt.opt')

            # Save a test opt file with an argument that doesn't exist
            init_opt = Opt({'made_up_arg': 'foo'})
            init_opt.save(init_opt_path)

            # Assert that the opt file normally can't be loaded in
            with self.assertRaises(RuntimeError):
                _ = ParlaiParser(True,
                                 True).parse_kwargs(init_opt=init_opt_path)

            # Assert that the opt file *can* be loaded in if we set
            # --allow-missing-init-opts, and assert that the made-up arg does not exist
            # in the opt
            opt = ParlaiParser(True,
                               True).parse_kwargs(init_opt=init_opt_path,
                                                  allow_missing_init_opts=True)
            self.assertFalse(hasattr(opt, 'made_up_arg'))
Beispiel #3
0
 def test_save_load(self):
     o = Opt({'a': 3, 'b': 'foo'})
     with testing_utils.tempdir() as tmpdir:
         fn = os.path.join(tmpdir, "opt")
         o.save(fn)
         o2 = Opt.load(fn)
         assert o == o2
Beispiel #4
0
 def test_save_withignore(self):
     o = Opt({'a': 3, 'b': 'foo', 'override': {'a': 3}})
     with testing_utils.tempdir() as tmpdir:
         fn = os.path.join(tmpdir, "opt")
         o.save(fn)
         o2 = Opt.load(fn)
         assert o != o2
         assert 'override' not in o2
Beispiel #5
0
    def test_init_opt(self):
        """
        Test --init-opt.
        """

        with testing_utils.tempdir() as temp_dir:

            init_opt_path = os.path.join(temp_dir, 'init_opt.opt')
            test_model_file = '/test_model_path/model'

            # Save a test opt file
            init_opt = Opt({'model_file': test_model_file})
            init_opt.save(init_opt_path)

            # Load the opt back in with --init-opt and make sure it's been set
            # correctly
            opt = ParlaiParser(True, True).parse_kwargs(init_opt=init_opt_path)
            self.assertEqual(opt['model_file'], test_model_file)