MCPcopy Create free account
hub / github.com/modelscope/modelscope / to_config

Method to_config

modelscope/trainers/training_args.py:465–491  ·  view source on GitHub ↗

Convert the TrainingArgs to the `Config` Returns: The Config, and extra parameters in dict.

(self, ignore_default_config=None)

Source from the content-addressed store, hash-verified

463 return self
464
465 def to_config(self, ignore_default_config=None):
466 """Convert the TrainingArgs to the `Config`
467
468 Returns:
469 The Config, and extra parameters in dict.
470 """
471 cfg = Config()
472 args_dict = addict.Dict()
473
474 if ignore_default_config is None:
475 ignore_default_config = self.use_model_config
476
477 for f in fields(self):
478 cfg_node = f.metadata.get('cfg_node')
479 cfg_setter = f.metadata.get('cfg_setter') or (lambda x: x)
480 if cfg_node is not None:
481 if f.name in self.manual_args or not ignore_default_config:
482 if isinstance(cfg_node, str):
483 cfg_node = [cfg_node]
484 for _node in cfg_node:
485 cfg.merge_from_dict(
486 {_node: cfg_setter(getattr(self, f.name))})
487 else:
488 args_dict[f.name] = getattr(self, f.name)
489
490 cfg.merge_from_dict(self._unknown_args)
491 return cfg, args_dict
492
493 def get_metadata(self, key):
494 _fields = fields(self)

Calls 3

merge_from_dictMethod · 0.95
ConfigClass · 0.90
getMethod · 0.45

Tested by 1

test_flatten_argsMethod · 0.76