Patch the loaded bundle config with a new handler logic to enable experiment tracking features. Args: parser: loaded config content to patch the handler. settings: settings for the experiment tracking, should follow the pattern of default settings.
(parser: ConfigParser, settings: dict)
| 627 | |
| 628 | @staticmethod |
| 629 | def patch_bundle_tracking(parser: ConfigParser, settings: dict) -> None: |
| 630 | """ |
| 631 | Patch the loaded bundle config with a new handler logic to enable experiment tracking features. |
| 632 | |
| 633 | Args: |
| 634 | parser: loaded config content to patch the handler. |
| 635 | settings: settings for the experiment tracking, should follow the pattern of default settings. |
| 636 | |
| 637 | """ |
| 638 | for k, v in settings["configs"].items(): |
| 639 | if k in settings["handlers_id"]: |
| 640 | engine = parser.get(settings["handlers_id"][k]["id"]) |
| 641 | if engine is not None: |
| 642 | handlers = parser.get(settings["handlers_id"][k]["handlers"]) |
| 643 | if handlers is None: |
| 644 | engine["train_handlers" if k == "trainer" else "val_handlers"] = [v] |
| 645 | else: |
| 646 | handlers.append(v) |
| 647 | elif k not in parser: |
| 648 | parser[k] = v |
| 649 | # save the executed config into file |
| 650 | default_name = f"config_{time.strftime('%Y%m%d_%H%M%S')}.json" |
| 651 | # Users can set the `save_execute_config` to `False`, `/path/to/artifacts` or `True`. |
| 652 | # If set to False, nothing will be recorded. If set to True, the default path will be logged. |
| 653 | # If set to a file path, the given path will be logged. |
| 654 | filepath = parser.get("save_execute_config", True) |
| 655 | if filepath: |
| 656 | if isinstance(filepath, bool): |
| 657 | if "output_dir" not in parser: |
| 658 | # if no "output_dir" in the bundle config, default to "<bundle root>/eval" |
| 659 | parser["output_dir"] = f"{EXPR_KEY}{ID_REF_KEY}bundle_root + '/eval'" |
| 660 | # experiment management tools can refer to this config item to track the config info |
| 661 | parser["save_execute_config"] = parser["output_dir"] + f" + '/{default_name}'" |
| 662 | filepath = os.path.join(parser.get_parsed_content("output_dir"), default_name) |
| 663 | Path(filepath).parent.mkdir(parents=True, exist_ok=True) |
| 664 | parser.export_config_file(parser.get(), filepath) |
| 665 | else: |
| 666 | parser["save_execute_config"] = None |
no test coverage detected