(args, path)
| 470 | |
| 471 | |
| 472 | def update_args_with_file(args, path): |
| 473 | with open(path, 'r', encoding='utf-8') as f: |
| 474 | config = json.load(f) |
| 475 | # expand relative path |
| 476 | folder = os.path.dirname(path) |
| 477 | for k in config: |
| 478 | # all the relative paths in config are based on the folder |
| 479 | if k.endswith('_path'): |
| 480 | config[k] = os.path.join(folder, config[k]) |
| 481 | print_rank0(f'> parsing relative path {k} in model_config as {config[k]}.') |
| 482 | args = vars(args) |
| 483 | for k in list(args.keys()): |
| 484 | if k in config: |
| 485 | del args[k] |
| 486 | args = argparse.Namespace(**config, **args) |
| 487 | return args |
| 488 | |
| 489 | |
| 490 | def overwrite_args_by_dict(args, overwrite_args={}): |
no test coverage detected