parse_config_flags
Logic for parsing command line flags into a ConfigDict.
parse_flags(flag_values)
Parse command line flags into ConfigDicts.
Supports two cases. In the first, a global default ConfigDict is used as a
starting point, and changed only where the user overrides it via command line
flags such as --config.vmc.nburn=100
.
In the second, the default ConfigDict is loaded from a previous run by specifying
the log directory for that run, as well as several other options. These options are
provided using --reload..
, for example --reload.logdir=./logs
.
The user can still override settings from the previous run by providing regular
command-line flags via --config..
, as described above. However, to override
model-related flags, some care must be taken since the structure of the ConfigDict
loaded from the json snapshot is not identical to the structure of the default
ConfigDict. The difference is due to
:func:~vmcnet.train.choose_model_type_in_model_config
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flag_values |
FlagValues |
a FlagValues object used to manage the command line flags. Should generally use the global flags.FLAGS, but it's useful to be able to override this for testing, since an error will be thrown if multiple tests define configs for the same FlagValues object. |
required |
Returns:
Type | Description |
---|---|
(reload_config, config) |
Two ConfigDicts. The first holds settings for the case where configurations or checkpoints are reloaded from a previous run. The second holds all other settings. |
Source code in vmcnet/train/parse_config_flags.py
def parse_flags(flag_values: flags.FlagValues) -> Tuple[ConfigDict, ConfigDict]:
"""Parse command line flags into ConfigDicts.
Supports two cases. In the first, a global default ConfigDict is used as a
starting point, and changed only where the user overrides it via command line
flags such as `--config.vmc.nburn=100`.
In the second, the default ConfigDict is loaded from a previous run by specifying
the log directory for that run, as well as several other options. These options are
provided using `--reload..`, for example `--reload.logdir=./logs`.
The user can still override settings from the previous run by providing regular
command-line flags via `--config..`, as described above. However, to override
model-related flags, some care must be taken since the structure of the ConfigDict
loaded from the json snapshot is not identical to the structure of the default
ConfigDict. The difference is due to
:func:`~vmcnet.train.choose_model_type_in_model_config`.
Args:
flag_values (FlagValues): a FlagValues object used to manage the command line
flags. Should generally use the global flags.FLAGS, but it's useful to be
able to override this for testing, since an error will be thrown if multiple
tests define configs for the same FlagValues object.
Returns:
(reload_config, config): Two ConfigDicts. The first holds settings for the
case where configurations or checkpoints are reloaded from a previous run.
The second holds all other settings.
"""
config_flags.DEFINE_config_dict(
"reload",
train.default_config.get_default_reload_config(),
lock_config=True,
flag_values=flag_values,
)
flag_values(sys.argv, True)
reload_config = flag_values.reload
if (
reload_config.logdir != train.default_config.NO_RELOAD_LOG_DIR
and reload_config.use_config_file
):
config = _get_config_from_reload(reload_config, flag_values)
else:
config = _get_config_from_default_config(flag_values)
if config.debug_nans:
config.distribute = False
jax.config.update("jax_debug_nans", True)
return reload_config, config