def load_config(args): """ Given the arguemnts, load and initialize the configs. Args: args (argument): arguments includes `shard_id`, `num_shards`, `init_method`, `cfg_file`, and `opts`. """ # Setup cfg. cfg = get_cfg() # Load config from cfg. if args.cfg_file is not None: cfg.merge_from_file(args.cfg_file) # Load config from command line, overwrite config from opts. if args.opts is not None: cfg.merge_from_list(args.opts) # Inherit parameters from args. if hasattr(args, "num_shards") and hasattr(args, "shard_id"): cfg.NUM_SHARDS = args.num_shards cfg.SHARD_ID = args.shard_id if hasattr(args, "rng_seed"): cfg.RNG_SEED = args.rng_seed if hasattr(args, "output_dir"): cfg.OUTPUT_DIR = args.output_dir cu.make_checkpoint_dir(cfg.OUTPUT_DIR) return cfg
def load_config_from_file(cfg_file=None): """ Given the arguemnts, load and initialize the configs. Args: args (argument): arguments includes `shard_id`, `num_shards`, `init_method`, `cfg_file`, and `opts`. """ # Setup cfg. cfg = get_cfg() # Load config from cfg. if cfg_file is not None: cfg.merge_from_file(cfg_file) # Create the checkpoint dir. cu.make_checkpoint_dir(cfg.OUTPUT_DIR) return cfg