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

Method parse_cli

modelscope/trainers/training_args.py:442–463  ·  view source on GitHub ↗

Construct a TrainingArg class by the parameters of CLI. Returns: Self

(self, parser_args=None)

Source from the content-addressed store, hash-verified

440 self._unknown_args = {}
441
442 def parse_cli(self, parser_args=None):
443 """Construct a TrainingArg class by the parameters of CLI.
444
445 Returns:
446 Self
447 """
448 parser = CliArgumentParser(self)
449 args, unknown = parser.parse_known_args(parser_args)
450 unknown = [
451 item for item in unknown
452 if item not in ('\\', '\n') and '--local-rank=' not in item
453 ]
454 _unknown = {}
455 for i in range(0, len(unknown), 2):
456 _unknown[unknown[i].replace('-', '')] = parse_value(unknown[i + 1])
457 args_dict = vars(args)
458 self.manual_args += parser.manual_args
459 self._unknown_args.update(_unknown)
460 for key, value in deepcopy(args_dict).items():
461 if key is not None and hasattr(self, key):
462 setattr(self, key, value)
463 return self
464
465 def to_config(self, ignore_default_config=None):
466 """Convert the TrainingArgs to the `Config`

Calls 5

CliArgumentParserClass · 0.90
parse_valueFunction · 0.85
replaceMethod · 0.80
updateMethod · 0.45
itemsMethod · 0.45

Tested by 1

test_flatten_argsMethod · 0.76