Shortcuts

LightningCLI

class pytorch_lightning.cli.LightningCLI(model_class=None, datamodule_class=None, save_config_callback=<class 'pytorch_lightning.cli.SaveConfigCallback'>, save_config_kwargs=None, trainer_class=<class 'pytorch_lightning.trainer.trainer.Trainer'>, trainer_defaults=None, seed_everything_default=True, parser_kwargs=None, subclass_mode_model=False, subclass_mode_data=False, args=None, run=True, auto_configure_optimizers=True, **kwargs)[source]

Bases: object

Implementation of a configurable command line tool for pytorch-lightning.

Receives as input pytorch-lightning classes (or callables which return pytorch-lightning classes), which are called / instantiated using a parsed configuration file and / or command line args.

Parsing of configuration from environment variables can be enabled by setting parser_kwargs={"default_env": True}. A full configuration yaml would be parsed from PL_CONFIG if set. Individual settings are so parsed from variables named for example PL_TRAINER__MAX_EPOCHS.

For more info, read the CLI docs.

Warning

LightningCLI is in beta and subject to change.

Parameters
add_arguments_to_parser(parser)[source]

Implement to add extra arguments to the parser or link arguments.

Parameters

parser (LightningArgumentParser) – The parser object to which arguments can be added

Return type

None

add_core_arguments_to_parser(parser)[source]

Adds arguments from the core classes to the parser.

Return type

None

add_default_arguments_to_parser(parser)[source]

Adds default arguments to the parser.

Return type

None

before_instantiate_classes()[source]

Implement to run some code before instantiating the classes.

Return type

None

static configure_optimizers(lightning_module, optimizer, lr_scheduler=None)[source]

Override to customize the configure_optimizers() method.

Parameters
  • lightning_module (LightningModule) – A reference to the model.

  • optimizer (Optimizer) – The optimizer.

  • lr_scheduler (Union[_LRScheduler, ReduceLROnPlateau, None]) – The learning rate scheduler (if used).

Return type

Any

init_parser(**kwargs)[source]

Method that instantiates the argument parser.

Return type

LightningArgumentParser

instantiate_classes()[source]

Instantiates the classes and sets their attributes.

Return type

None

instantiate_trainer(**kwargs)[source]

Instantiates the trainer.

Parameters

kwargs (Any) – Any custom trainer arguments.

Return type

Trainer

Creates argument links for optimizers and learning rate schedulers that specified a link_to.

Return type

None

parse_arguments(parser, args)[source]

Parses command line arguments and stores it in self.config.

Return type

None

setup_parser(add_subcommands, main_kwargs, subparser_kwargs)[source]

Initialize and setup the parser, subcommands, and arguments.

Return type

None

static subcommands()[source]

Defines the list of available subcommands and the arguments to skip.

Return type

Dict[str, Set[str]]