| 508 | self.tmp_parser.add_argument(config_arg, type=str, help="Path to YAML config file") |
| 509 | |
| 510 | def parse_args(self, args=None, namespace=None): |
| 511 | tmp_ns, remaining_args = self.tmp_parser.parse_known_args(args=args) |
| 512 | config_path = tmp_ns.config |
| 513 | |
| 514 | config = {} |
| 515 | if config_path: |
| 516 | with open(config_path, "r") as f: |
| 517 | loaded_config = yaml.safe_load(f) |
| 518 | config = loaded_config |
| 519 | |
| 520 | # Get declared parameters |
| 521 | defined_actions = {action.dest: action for action in self._actions} |
| 522 | filtered_config = {k: v for k, v in config.items() if k in defined_actions} |
| 523 | |
| 524 | # Set parameters |
| 525 | if namespace is None: |
| 526 | namespace = argparse.Namespace() |
| 527 | for key, value in filtered_config.items(): |
| 528 | action = defined_actions[key] |
| 529 | if action.type is not None and isinstance(value, (str, int, float)): |
| 530 | try: |
| 531 | str_value = str(value).strip() |
| 532 | if str_value == "": |
| 533 | converted = None |
| 534 | else: |
| 535 | converted = action.type(str_value) |
| 536 | value = converted |
| 537 | except Exception as e: |
| 538 | llm_logger.error(f"Error converting '{key}' with value '{value}': {e}") |
| 539 | setattr(namespace, key, value) |
| 540 | args = super().parse_args(args=remaining_args, namespace=namespace) |
| 541 | |
| 542 | # Args correction |
| 543 | for config_name, flag_name in ARGS_CORRECTION_LIST: |
| 544 | if hasattr(args, config_name) and hasattr(args, flag_name): |
| 545 | # config is a dict |
| 546 | config = getattr(args, config_name, None) |
| 547 | if config is not None and flag_name in config.keys(): |
| 548 | setattr(args, flag_name, config[flag_name]) |
| 549 | return args |
| 550 | |
| 551 | |
| 552 | def resolve_obj_from_strname(strname: str): |