options package
Submodules
options.errors module
options.opts module
- class options.opts.ParseKwargs(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]
Bases:
Action
options.parse_args module
- options.parse_args.parse_validation_metric_names(opts)[source]
This function contains common command-line parsing logic for validation metrics
- class options.parse_args.JsonValidator(expected_type: type)[source]
Bases:
object
- __init__(expected_type: type)[source]
JsonValidator(T) is function (s)->x that parses json string s into python value x, where x is of type T.
Example Usage: >>> from typing import Union, List >>> import argparse >>> parser = argparse.ArgumentParser() >>> parser.add_argument(”–x”, type=JsonValidator(Union[int, List[float]])) >>> assert parser.parse_args([”–x=123”]).x == 123 >>> assert parser.parse_args([”–x=[1, 2]”]).x == [1., 2.]
options.utils module
- options.utils.extend_selected_args_with_prefix(parser: ArgumentParser, match_prefix: str, additional_prefix: str) ArgumentParser [source]
Helper function to select arguments with certain prefix and duplicate them with a replaced prefix. An example use case is distillation, where we want to add –teacher.model.* as a prefix to all –model.* arguments.
In that case, we provide the following arguments: * match_prefix=”–model.” * additional_prefix=”–teacher.model.”
- Parameters:
match_prefix – Prefix to select arguments for duplication. The value should start with “–”, contain no underscores, and with “.”.
additional_prefix – Prefix to replace the @match_prefix in duplicated arguments. The value should start with “–”, contain no underscores, and with “.”.
- options.utils.extract_opts_with_prefix_replacement(opts: Namespace, match_prefix: str, replacement_prefix: str) Namespace [source]
Helper function to extract a copy options with certain prefix and return them with an alternative prefix. An example usage is distillation, when we have used @extend_selected_args_with_prefix to add –teacher.model.*
arguments to argparser, and now we want to re-use the handlers of model.* opts by teacher.model.* opts
- Parameters:
match_prefix – Prefix to select opts for extraction. The value should not contain dashes and should end with “.”
replacement_prefix – Prefix to replace the @match_prefix The value should not contain dashes and should end with “.”