def run(config_path, config_string, name): runs = RetrieverTrainingRuns(check_commit=False) config = Config.from_file(config_path) if config_string: config = Config.merge([config, Config.from_str(config_string)]) run = runs.new(config, name) run.train()
if len(config_paths) == 1 and config_paths[0].isdigit(): # Get configs from a run run_dirname = IntegerDirectories(data.workspace.experiments)[int( config_paths[0])] with open(join(run_dirname, 'config.txt')) as fin: config_strings.append(fin.read()) else: # Merge strings to allow object overwites run_dirname = None for filename in config_paths: with open(filename) as fin: config_strings.append(fin.read()) for config_string in args.config_strings: config_strings.append(config_string) config = Config.from_str('\n'.join(config_strings)) eval_run = PhraseNodeEvalRun(config) # load model if args.model_file and exists(args.model_file): # Load model from a file eval_run.load_model(args.model_file) elif run_dirname is not None and args.model_file.isdigit(): # Load a specific checkpoint model_file = join(run_dirname, 'checkpoints', args.model_file + '.checkpoint', 'model') eval_run.load_model(model_file) else: raise ValueError('Cannot load model from "{}"'.format(args.model_file)) ################################################
run = runs[int(config_paths[0])] else: # new run according to configs configs = [Config.from_file(p) for p in config_paths] # add task config repo_dir = abspath(dirname(__file__)) config_dir = join(repo_dir, 'configs') task_config_path = join(config_dir, 'task-mixins', '{}.txt'.format(args.task)) if os.path.exists(task_config_path): # use existing config if it exists task_config = Config.from_file(task_config_path) else: # otherwise, create a very basic config task_config = Config.from_str('env.subdomain = {}'.format(args.task)) configs.append(task_config) # add string configs configs.extend([Config.from_str(cfg_str) for cfg_str in args.config_strings]) # validate all configs reference_config = Config.from_file(join(config_dir, 'default-base.txt')) for config in configs: config.validate(reference_config) # merge all configs together config = Config.merge(configs) # later configs overwrite earlier configs run = runs.new(config, name=args.name) # new run from config infer = config.infer