geowatch.utils.lightning_ext.lightning_cli_ext module¶
This module is an exension of jsonargparse and lightning CLI that will respect scriptconfig style arguments
References
https://github.com/Lightning-AI/lightning/issues/15038
- class geowatch.utils.lightning_ext.lightning_cli_ext.LightningCLI_Extension(model_class: type[~pytorch_lightning.core.module.LightningModule] | ~typing.Callable[[...], ~pytorch_lightning.core.module.LightningModule] | None = None, datamodule_class: type[~pytorch_lightning.core.datamodule.LightningDataModule] | ~typing.Callable[[...], ~pytorch_lightning.core.datamodule.LightningDataModule] | None = None, save_config_callback: type[~pytorch_lightning.cli.SaveConfigCallback] | None = <class 'pytorch_lightning.cli.SaveConfigCallback'>, save_config_kwargs: dict[str, ~typing.Any] | None = None, trainer_class: type[~pytorch_lightning.trainer.trainer.Trainer] | ~typing.Callable[[...], ~pytorch_lightning.trainer.trainer.Trainer] = <class 'pytorch_lightning.trainer.trainer.Trainer'>, trainer_defaults: dict[str, ~typing.Any] | None = None, seed_everything_default: bool | int = True, parser_kwargs: dict[str, ~typing.Any] | dict[str, dict[str, ~typing.Any]] | None = None, parser_class: type[~pytorch_lightning.cli.LightningArgumentParser] = <class 'pytorch_lightning.cli.LightningArgumentParser'>, subclass_mode_model: bool = False, subclass_mode_data: bool = False, args: list[str] | dict[str, ~typing.Any] | ~jsonargparse_fork._namespace.Namespace | None = None, run: bool = True, auto_configure_optimizers: bool = True, load_from_checkpoint_support: bool = True)[source]¶
Bases:
LightningCLIOur customized
LightningCLIextension.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 fromPL_CONFIGif set. Individual settings are so parsed from variables named for examplePL_TRAINER__MAX_EPOCHS.For more info, read the CLI docs.
- Parameters:
model_class – An optional
LightningModuleclass to train on or a callable which returns aLightningModuleinstance when called. IfNone, you can pass a registered model with--model=MyModel.datamodule_class – An optional
LightningDataModuleclass or a callable which returns aLightningDataModuleinstance when called. IfNone, you can pass a registered datamodule with--data=MyDataModule.save_config_callback – A callback class to save the config.
save_config_kwargs – Parameters that will be used to instantiate the save_config_callback.
trainer_class – An optional subclass of the
Trainerclass or a callable which returns aTrainerinstance when called.trainer_defaults – Set to override Trainer defaults or add persistent callbacks. The callbacks added through this argument will not be configurable from a configuration file and will always be present for this particular CLI. Alternatively, configurable callbacks can be added as explained in the CLI docs.
seed_everything_default – Number for the
seed_everything()seed value. Set to True to automatically choose a seed value. Setting it to False will avoid callingseed_everything.parser_kwargs – Additional arguments to instantiate each
LightningArgumentParser.subclass_mode_model – Whether model can be any subclass of the given class.
subclass_mode_data – Whether datamodule can be any subclass of the given class.
args – Arguments to parse. If
Nonethe arguments are taken fromsys.argv. Command line style arguments can be given in alist. Alternatively, structured config options can be given in adictorjsonargparse.Namespace.run – Whether subcommands should be added to run a
Trainermethod. If set toFalse, the trainer and model classes will be instantiated only.auto_configure_optimizers – Whether to automatically add default optimizer and lr_scheduler arguments.
load_from_checkpoint_support – Whether
save_hyperparametersshould save the original parsed hyperparameters (instead of what__init__receives), such that it is possible forload_from_checkpointto correctly instantiate classes even when using complex nesting and dependency injection.