def test_get_all_params(): # not enough args args = [ '--data_config', 'data.json', '--model_config', 'model.json', '--training_config', 'training.json'] with pytest.raises(ValueError): utils.get_all_params(search_type='grid_search', args=args) # too many args args = [ '--data_config', 'data.json', '--model_config', 'model.json', '--training_config', 'training.json', '--compute_config', 'compute.json', '--model_class', 'ae'] with pytest.raises(ValueError): utils.get_all_params(search_type='grid_search', args=args) # correct args, substituted into sys.argv data_config = os.path.join( os.getcwd(), 'configs', 'data_default.json') model_config = os.path.join( os.getcwd(), 'configs', 'arhmm_jsons', 'arhmm_model.json') training_config = os.path.join( os.getcwd(), 'configs', 'arhmm_jsons', 'arhmm_training.json') compute_config = os.path.join( os.getcwd(), 'configs', 'arhmm_jsons', 'arhmm_compute.json') args = [ '--data_config', data_config, '--model_config', model_config, '--training_config', training_config, '--compute_config', compute_config] old_sys_argv = sys.argv sys.argv = [old_sys_argv[0]] + args parser = utils.get_all_params(search_type='grid_search') # test a couple args assert parser.data_config == data_config assert parser.model_config == model_config assert parser.training_config == training_config assert parser.compute_config == compute_config
save_file = os.path.join(version_dir, 'loss_training') export_train_plots(hparams, 'train', loss_type='ll', save_file=save_file) save_file = os.path.join(version_dir, 'loss_validation') export_train_plots(hparams, 'val', loss_type='ll', save_file=save_file) print('done') # update hparams upon successful training hparams['training_completed'] = True export_hparams(hparams, exp) # get rid of unneeded logging info _clean_tt_dir(hparams) if __name__ == '__main__': hyperparams = get_all_params('grid_search') if hyperparams.device == 'cuda' or hyperparams.device == 'gpu': if hyperparams.device == 'gpu': hyperparams.device = 'cuda' gpu_ids = hyperparams.gpus_viz.split(';') hyperparams.optimize_parallel_gpu(main, gpu_ids=gpu_ids) elif hyperparams.device == 'cpu': hyperparams.optimize_parallel_cpu( main, nb_trials=hyperparams.tt_n_cpu_trials, nb_workers=hyperparams.tt_n_cpu_workers)