Shortcuts

argparse_utils

Functions

add_argparse_args

Extends existing argparse by default Trainer attributes.

from_argparse_args

Create an instance from CLI arguments.

get_init_arguments_and_types

Scans the Trainer signature and returns argument names, types and default values.

parse_argparser

Parse CLI arguments, required for custom bool types.

parse_args_from_docstring

rtype

Dict[str, str]

parse_env_variables

Parse environment arguments if they are defined.

pytorch_lightning.utilities.argparse_utils.add_argparse_args(cls, parent_parser)[source]

Extends existing argparse by default Trainer attributes.

Parameters

parent_parser (ArgumentParser) – The custom cli arguments parser, which will be extended by the Trainer default arguments.

Only arguments of the allowed types (str, float, int, bool) will extend the parent_parser.

Examples

>>> import argparse
>>> import pprint
>>> from pytorch_lightning import Trainer
>>> parser = argparse.ArgumentParser()
>>> parser = Trainer.add_argparse_args(parser)
>>> args = parser.parse_args([])
Return type

ArgumentParser

pytorch_lightning.utilities.argparse_utils.from_argparse_args(cls, args, **kwargs)[source]

Create an instance from CLI arguments. Eventually use varibles from OS environement which are defined as “PL_<CLASS-NAME>_<CLASS_ARUMENT_NAME>”

Parameters
  • args (Union[Namespace, ArgumentParser]) – The parser or namespace to take arguments from. Only known arguments will be parsed and passed to the Trainer.

  • **kwargs – Additional keyword arguments that may override ones in the parser or namespace. These must be valid Trainer arguments.

Example

>>> from pytorch_lightning import Trainer
>>> parser = ArgumentParser(add_help=False)
>>> parser = Trainer.add_argparse_args(parser)
>>> parser.add_argument('--my_custom_arg', default='something')  
>>> args = Trainer.parse_argparser(parser.parse_args(""))
>>> trainer = Trainer.from_argparse_args(args, logger=False)
pytorch_lightning.utilities.argparse_utils.get_init_arguments_and_types(cls)[source]

Scans the Trainer signature and returns argument names, types and default values.

Returns

(argument name, set with argument types, argument default value).

Return type

List with tuples of 3 values

Examples

>>> from pytorch_lightning import Trainer
>>> args = get_init_arguments_and_types(Trainer)
pytorch_lightning.utilities.argparse_utils.parse_argparser(cls, arg_parser)[source]

Parse CLI arguments, required for custom bool types.

Return type

Namespace

pytorch_lightning.utilities.argparse_utils.parse_env_variables(cls, template='PL_%(cls_name)s_%(cls_argument)s')[source]

Parse environment arguments if they are defined.

Example

>>> from pytorch_lightning import Trainer
>>> parse_env_variables(Trainer)
Namespace()
>>> import os
>>> os.environ["PL_TRAINER_GPUS"] = '42'
>>> os.environ["PL_TRAINER_BLABLABLA"] = '1.23'
>>> parse_env_variables(Trainer)
Namespace(gpus=42)
>>> del os.environ["PL_TRAINER_GPUS"]
Return type

Namespace

Read the Docs v: 1.0.7
Versions
latest
stable
1.0.7
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
0.10.0
0.9.0
0.8.5
0.8.4
0.8.3
0.8.2
0.8.1
0.8.0
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.1
0.7.0
0.6.0
0.5.3.2
0.5.3
0.4.9
release-1.0.x
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.