LightningCLI - instantiate model from config #10363
-
So lets say i have a model and i'm using the newest CLI API to train it: The config uses sub modules and can look something like:
Now i want to run some scripts or notebooks using the model i trained with this config and i would like to instantiate the model using this config file. I was digging how this happens in LightningCLI and jsonargsparse but gave up after a while.. and started trying to hack this around with importlib, which works but feels like reinventing the wheel - i mean this logic has to be somewhere already :) i just cant find it. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 12 replies
-
If you want to use that exact config (not stripping out everything except the model) you can do the following: from jsonargparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--model', type=ModelClass)
parser.add_argument('--data', type=dict) # to ignore data
config = parser.parse_path('config.yaml')
config_init = parser.instantiate_classes(config) The instantiated model will be in |
Beta Was this translation helpful? Give feedback.
-
@cifkao @mauvilsa
but load_from_checkpoint not working
it raise
|
Beta Was this translation helpful? Give feedback.
If you want to use that exact config (not stripping out everything except the model) you can do the following:
The instantiated model will be in
config_init.model
.