|
|
| """Ensure user-defined pretraining & rl configs inherit from base configs.""" |
|
|
|
|
| from ml_collections import ConfigDict |
|
|
| from .pretrain import get_config as get_pretrain_config |
| from .rl import get_config as get_rl_config |
|
|
| |
| def __validate_keys( |
| base_config, |
| config, |
| base_filename, |
| ): |
| """Validate keys.""" |
| for key in base_config.keys(): |
| if key not in config: |
| raise ValueError( |
| f"Key {key} missing from config. This config is required to have " |
| f"keys: {list(base_config.keys())}. See base_configs/{base_filename} " |
| "for more details.") |
| if (isinstance(base_config[key], ConfigDict) and config[key] is not None): |
| __validate_keys(base_config[key], config[key], base_filename) |
| |
| def validate_config(config, mode): |
| """Ensures a config inherits from a base config. |
| |
| Args: |
| config: The child config to validate. |
| mode: Can be one of 'pretraining' or 'rl'. |
| |
| Raises: |
| ValueError: if the base config contains keys that are not present in config. |
| """ |
| assert mode in ["pretrain", "rl"] |
| base_config = get_rl_config() if mode == "rl" else get_pretrain_config() |
| base_filename = "rl.py" if mode == "rl" else "pretrain.py" |
| __validate_keys(base_config, config, base_filename) |