ModelArguments.add_arguments#

ModelArguments.add_arguments(parser)[source]#

Add arguments to command-line parser and adds dataclass_parse_func.

This method will add arguments to the parser with the same names as the class attributes. It will fill in the following: - default values, if defined in the attribute field function - help text, if defined in the field metadata dictionary with

the “help” key

  • type if the attribute has a type annotation, only basic Python types are handled, any others will just be left as strings.

  • optional flag, if the field type annotation is optional or the field has a default value.

For more complex argument requirements these should be added manually.

Returns:

Argument parser with arguments added and a default function set as the ‘dataclass_parse_func’ parameter which will parse the argparse.Namespace and output the given dataclass.

Return type:

argparse.ArgumentParser

Parameters:

parser (ArgumentParser)