Skip to main content

utils.config_parser.custom_arg_parser

Custom Arguments Parser

CustomArgParser Objects#

class CustomArgParser()

This class is part of utils and is provided to load arguments from the provided YAML config file. Further, the default values of arguments from config file can be overridden via commandline or via the special argument --params provided for easy AML experimentation. The class instance takes in the parser object and optional log_level. This class needs to be instantiated in the main method inside the Marlin_Scenario code.

Example for instantiation::

parser = CustomArgParser()
config = parser.parse()

The command line arguments to override default YAML config values are passed by adding a '.' between namespace and the specific argument as shown in example below. If no namespace is present, then just pass the argument name. All command line arguments are optional and need to be prefixed with '--'. All commandline arguments not present in YAML config file will be ignored with a warning message. Example commandline override::

python train.py --tmgr.epochs 4 --chkp.save_dir "tmp\checkpoints"

NOTE: Supported types for CustomArgParser are int, float, str, lists. null is inferred implicitly as str. If you intend to use other types, then please set a dummy default value in YAML file and pass the intended value from commandline. Suggested defaults::

str: null
int: -1
float: -1.0
bool: pick either True or False
list[int]: [-1, -1, -1]
list[float] : [-1.0, -1.0, -1.0]

To make it easy to use with AML pipelines, the parser treats --params as a special argument. The parser treats this as a str format of JSON serialized dictionary and parses this single argument to override the default values from YAML config file of all the arguments present in the dictionary. For example when user provides this str for --param::

'{"--test.test_str":"this is a new test string 2","--test.test_false":"false"}'
NOTE use of single quote and double quotes and use the same format to avoid parsing errors.

The parser parses this and overrides the default values provided for test_str and test_false under test section in the YAML config file.

parse#

def parse() -> Dict

Parse YAML config file, parse commandline arguments and merge the two to get the final merged config dictionary.

Find and return the path of the file with greatest number of completed epochs under dirpath (recursive search) for a given file prefix, and optionally file extension.

Arguments:

self

Returns:

  • self._config Dict - merged config dictionary containing all arguments.