Facilitate configuration file loading outside training script
See original GitHub issue🚀 Feature
I’d like to request a feature that would allow to use the LightningCLI configuration more easily in Jupyter notebooks, or in general, outside the main training script (e.g. for serving). This could be done by implementing a mode for LightningCLI that exposes the correctly configured parser without actually trying to parse any arguments.
Motivation
After training a model on the command line, I often want to load it in a Jupyter notebook, e.g. to run it on some toy examples. Often I need to create not just the model itself, but also the data module and maybe even the trainer, optimizers etc. Sometimes I even want to modify the configuration (e.g. the maximum sequence length in a Transformer) before creating the model.
With LightningCLI, this is not currently straightforward (see #10363, #12302).
Pitch
Probably the most flexible solution would be to implement a mode for LightningCLI that sets up and exposes the parser without actually trying to parse anything (e.g. parse=False). Then one could, for example, feed custom configuration (modified on the fly) via parser.parse_object(). Then one could call instantiate_classes(), ideally with the possibility to choose which top-level objects (model, data module, trainer) to instantiate.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
@cifkao in the current version of jsonargparse in master there is now a way to capture the parser from a cli function. You can see the documentation for this feature at https://jsonargparse.readthedocs.io/en/latest/#capturing-parsers.
A workaround would not be advisable. I have thought a bit about this and right now I am not sure about a change in LightningCLI. I know of one more use case in which there is a need to get the parser of a CLI. Thus, it might make sense to add a feature to jsonargparse for this. Basically a way to capture the parser from a CLI without any need to modify the CLI.