Given module and config, returns a dictionary of read_per_param_settings debug strings. If no register_per_param_settings is called, an assertion error is raised.
(
module: str,
config_name: str,
trainer_config: TrainerConfigFn,
*,
kv_separator=": ",
field_separator="\n",
)
| 103 | |
| 104 | |
| 105 | def per_param_setting_debug_string( |
| 106 | module: str, |
| 107 | config_name: str, |
| 108 | trainer_config: TrainerConfigFn, |
| 109 | *, |
| 110 | kv_separator=": ", |
| 111 | field_separator="\n", |
| 112 | ) -> dict[str, str]: |
| 113 | """Given module and config, returns a dictionary of read_per_param_settings debug strings. |
| 114 | |
| 115 | If no register_per_param_settings is called, an assertion error is raised. |
| 116 | """ |
| 117 | all_param_settings = read_per_param_settings( |
| 118 | module=module, config_name=config_name, trainer_config=trainer_config |
| 119 | ) |
| 120 | if not all_param_settings: |
| 121 | raise AssertionError( |
| 122 | f"{module}.{config_name} does not use per_param_setting_by_path." |
| 123 | "It is safe to remove this test." |
| 124 | ) |
| 125 | |
| 126 | def sep_line(name: str): |
| 127 | return "=" * 20 + name + "=" * 20 |
| 128 | |
| 129 | def _settings_to_string(description: str, settings: dict[str, NestedTree]) -> str: |
| 130 | lines = [] |
| 131 | |
| 132 | for setting_key, setting_value in settings.items(): |
| 133 | # If there are multiple settings under the same description key, |
| 134 | # separate settings generated by different optimizers/learners by sep_line. |
| 135 | lines.append(sep_line(name=f"{description} {setting_key}")) |
| 136 | for param_name, param_setting in flatten_items(setting_value): |
| 137 | lines.append(f"{param_name}{kv_separator}{param_setting}") |
| 138 | return field_separator.join(lines) |
| 139 | |
| 140 | return { |
| 141 | description: _settings_to_string(description, settings) |
| 142 | for description, settings in all_param_settings.items() |
| 143 | } |
| 144 | |
| 145 | |
| 146 | @enum.unique |
no test coverage detected