Skip to content

Best practices: CLI and Loading DataModule from config.yaml #10956

Discussion options

You must be logged in to vote

This is similar to #10363. You can use jsonargparse directly to create a parser and instantiate. You can do the following:

from jsonargparse import ArgumentParser

parser = ArgumentParser()
parser.add_argument('--model', type=dict) # to ignore model
parser.add_argument('--data', type=pl.LightningDataModule)
config = parser.parse_path('config.yaml')
config_init = parser.instantiate_classes(config)

The instantiated data module will be in config_init.data. In the pytorch-lightning source code the add of arguments is done slightly different but this argparse style should be more familiar to more people. Just for reference in lightning for subclass mode it is https://github.com/PyTorchLightnin…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@adosar
Comment options

@mauvilsa
Comment options

@mauvilsa
Comment options

@adosar
Comment options

@mauvilsa
Comment options

Answer selected by cheind
Comment options

You must be logged in to vote
3 replies
@mauvilsa
Comment options

@adosar
Comment options

@mauvilsa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment