Given the arguemnts, load and initialize the configs. Args: args (argument): arguments includes `shard_id`, `num_shards`, `init_method`, `cfg_file`, and `opts`.
(args)
| 65 | |
| 66 | |
| 67 | def load_config(args): |
| 68 | """ |
| 69 | Given the arguemnts, load and initialize the configs. |
| 70 | Args: |
| 71 | args (argument): arguments includes `shard_id`, `num_shards`, |
| 72 | `init_method`, `cfg_file`, and `opts`. |
| 73 | """ |
| 74 | cfg_num = len(args.cfg_file) |
| 75 | cfg_list = [get_cfg() for _ in range(cfg_num)] |
| 76 | for i in range(cfg_num): |
| 77 | cfg_list[i].merge_from_file(args.cfg_file[i]) |
| 78 | # Load config from command line, overwrite config from opts. |
| 79 | if args.opts is not None: |
| 80 | cfg_list[i].merge_from_list(args.opts) |
| 81 | |
| 82 | # Inherit parameters from args. |
| 83 | if hasattr(args, "num_shards") and hasattr(args, "shard_id"): |
| 84 | cfg_list[i].NUM_SHARDS = args.num_shards |
| 85 | cfg_list[i].SHARD_ID = args.shard_id |
| 86 | if hasattr(args, "rng_seed"): |
| 87 | cfg_list[i].RNG_SEED = args.rng_seed |
| 88 | if hasattr(args, "output_dir"): |
| 89 | cfg_list[i].OUTPUT_DIR = args.output_dir |
| 90 | |
| 91 | # Create the checkpoint dir. |
| 92 | cu.make_checkpoint_dir(cfg_list[0].OUTPUT_DIR) |
| 93 | return cfg_list |