Best practices: CLI and Loading DataModule from config.yaml #10956
-
Hey, I've been using both, PyTorch Lightning/CLI and jsonargparse for quite a while. Yet, I haven't found a simple method to instantiate a specific DataModule whose parameters are set in a config.yaml that was used during training. I have 2 workarounds which are both unsatisfying: Workaround 1 - Reuse CLIDefine an instantiate-only CLI and use
Downsides
Workaround 2 - Load Yaml directlyWhen the actual datamodule is known then
Downsides
Does anyone have a better solution? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
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 |
Beta Was this translation helpful? Give feedback.
-
@mauvilsa thanks for the reply. In the end, to load from a PyTorch-Lightning config you need to
For now :) I believe jsonargparse does not support |
Beta Was this translation helpful? Give feedback.
This is similar to #10363. You can use jsonargparse directly to create a parser and instantiate. You can do the following:
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…