Пример #1
0
def download_config(run_id: str = '',
                    run_path: str = '',
                    replace: bool = False,
                    run_name=''):
    if run_name == '':
        run_name = fetch_run_name(run_id, run_path)

    for file in fetch_run(run_id, run_path).files():
        if file.name == 'config.json':
            file.download(replace=replace, root=get_run_folder_path(run_name))
            load_config(run_name)
Пример #2
0
def load_simple_config(config_path: str,
                       wandb_resume_run_fn,
                       wandb_new_run_fn,
                       ngpus: Optional[int] = None,
                       use_wandb_override=True):
    """
    Used for loading a normal run that is not part of a batch run. Therefore it is much more simple than loading a batch
    config

    Steps:
    * Read config to get run name and wandb related info
    * Read saved config if it is a saved run
    * Load wandb if wandb is requested
    * Read original config again for overwrites
    * Overwrite n_gpus option if required
    * Save config to run folder

    @param config_path: path to the config, can be relative to configuration/configs
    @param wandb_resume_run_fn: function that allows wandb to resume
    @param wandb_new_run_fn: function that creates a new wandb run
    @param ngpus: number of gpus if config option should be overridden
    :param use_wandb_override: determines whether wandb actions should be taken in the config loading
    """
    config.read(config_path)
    run_name = config.run_name
    print(f'Run name: {run_name}')

    if run_man.run_folder_exists(run_name):
        print('Run folder already exists, reading its config')
        run_man.load_config(run_name)  # load saved config
        if config.use_wandb and use_wandb_override:
            wandb_resume_run_fn()
    else:
        print(f'No runs folder detected with name {run_name}. Creating one')
        if config.use_wandb and use_wandb_override:
            wandb_new_run_fn()

        run_man.set_up_run_folder(config.run_name, use_wandb_override)

    config.read(
        config_path
    )  # overwrite saved/wandb config with provided config (only values present in this config)

    if ngpus is not None:  # n_gpu override
        config.n_gpus = ngpus

    run_man.save_config(run_name, use_wandb_override=use_wandb_override)
    print(f'config: {config.__dict__}')
Пример #3
0
def load_saved_config(effective_run_name, cli_cfg_file_name):
    wandb_run_path = config.read_option(cli_cfg_file_name, 'wandb_run_path')

    if wandb_run_path:
        # wandb downloaded runs are not used by the batch scheduler.
        # this must be a standalone run
        print(f'downloading run from wandb with path: {wandb_run_path}')
        # if a wandb run path is specified - the cli configs run name is ignored, instead the run name
        # is determined by the saved config
        effective_run_name = download_run(run_path=wandb_run_path,
                                          replace=True)

    print('Run name', effective_run_name)
    if run_man.run_folder_exists(effective_run_name):
        print('Run folder already exists, reading its config')
        run_man.load_config(effective_run_name)

    return effective_run_name
Пример #4
0
def get_run(run_name, config_name="config"):
    last_gen = runs_manager.get_latest_generation(run_name)
    generations: List[Generation] = []
    for i in range(last_gen + 1):
        generation: Generation = runs_manager.load_generation(i, run_name)
        generations.append(generation)

    configuration: configuration = runs_manager.load_config(
        run_name=run_name, config_name=config_name)

    return Run(generations, configuration)
Пример #5
0
def init_process(generation, run_name: str, proc_counter: SyncedCounter):
    """Because of how python spawns processes config and singleton need to be re-initialized on each new process"""
    singleton.instance = generation
    load_config(run_name)
    mp.current_process().name = str(proc_counter.incr())
    print(f'Process {mp.current_process().name}\nConfig: {config.__dict__}')