Base Interface

The base interface for all argument groups.

Module: polygraphy.tools.args

class ArgGroups(dct=None)[source]

Bases: Interface

Maps argument group types to argument groups.

class BaseArgs[source]

Bases: object

Adds a arguments to a command-line parser, and provides capabilities to create Polygraphy objects based on the arguments.

Child classes that add options must define a docstring that includes a section header for the argument group, a brief description which should complete the sentence: “Options related to …”, and finally, any dependencies:

Section Header: Description

Depends on:

    - OtherArgs0
    - OtherArgs1: <additional info: condition under which it is needed, or reason for dependency>

<Optional Additional Documentation>

For example:

TensorRT Engine: loading TensorRT engines.

Depends on:

    - ModelArgs
    - TrtLoadPluginsArgs
    - TrtLoadNetworkArgs: if building engines
    - TrtConfigArgs: if building engines
    - TrtSaveEngineBytesArgs: if allow_saving == True

The section header and description will be used to popluate the tool’s help output.

group

The argparse argument group associated with this argument group

arg_groups

Maps argument group types to argument groups

Type:

ArgGroups

allows_abbreviation()[source]

Whether to allow abbreviated options. When this is enabled, a prefix of an option can be used instead of specifying the entire option. For example, an --iterations could be specified with just --iter. This breaks argparse.REMAINDER, so any argument groups using that should disable this. The default implementation returns True.

Returns:

bool

register(arg_groups)[source]

Registers a dictionary of all available argument groups with this argument group.

Parameters:

arg_groups (ArgGroups) – Maps argument group types to argument groups.

add_parser_args(parser)[source]

Add arguments to a command-line parser.

This method is guaranteed to only be called after register.

Parameters:

parser (argparse.ArgumentParser) – The argument parser.

parse(args)[source]

Parses relevant arguments from command-line arguments and populates corresponding attributes of this argument group.

This method is guaranteed to only be called after add_parser_args.

Parameters:

args – Arguments provided by argparse.

add_to_script(script, *args, **kwargs) str[source]

Adds code to the given script that performs the functionality provided by this argument group.

For example, TrtConfigArgs would add a call to CreateConfig.

This method is guaranteed to only be called after parse.

Parameters:

script (polygraphy.tools.script.Script) – A script to which code should be added.

Returns:

The name of the variable that was modified or added in the script.

Return type:

str

class BaseRunnerArgs[source]

Bases: BaseArgs

Similar to BaseArgs, but meant specifically for argument groups dealing with runners.

add_to_script(script) str[source]
Returns:

The name of the list of runners in the script.

Return type:

str

get_name_opt() Tuple[str, str][source]

Returns a tuple containing a human readable name of the runner and the name of the command-line option (without leading dashes) that should be used to select the runner controlled by this argument group.

For example: ("TensorRT", "trt").

get_extra_help_text() str[source]

Returns any extra help text to display in the tool help output for this runner.