Main entry point for training. :param cfg: DictConfig configuration composed by Hydra. :return: Optional[float] with optimized metric value.
(cfg: DictConfig)
| 170 | |
| 171 | @hydra.main(version_base="1.3", config_path="../configs", config_name="train.yaml") |
| 172 | def main(cfg: DictConfig) -> Optional[float]: |
| 173 | """Main entry point for training. |
| 174 | |
| 175 | :param cfg: DictConfig configuration composed by Hydra. |
| 176 | :return: Optional[float] with optimized metric value. |
| 177 | """ |
| 178 | # apply extra utilities |
| 179 | # (e.g. ask for tags if none are provided in cfg, print cfg tree, etc.) |
| 180 | extras(cfg) |
| 181 | |
| 182 | # train the model |
| 183 | metric_dict, _ = train(cfg) |
| 184 | |
| 185 | # safely retrieve metric value for hydra-based hyperparameter optimization |
| 186 | metric_value = get_metric_value( |
| 187 | metric_dict=metric_dict, metric_name=cfg.get("optimized_metric") |
| 188 | ) |
| 189 | |
| 190 | # return optimized metric |
| 191 | return metric_value |
| 192 | |
| 193 | |
| 194 | if __name__ == "__main__": |
no test coverage detected