Evaluate or change type from argument in configuration yaml file. Fix Jsonargparse error "'cannot represent an object'" #19797
Replies: 2 comments 2 replies
-
|
Using python-specific yaml syntax such as |
Beta Was this translation helpful? Give feedback.
-
|
@mauvilsa Thank you very much for your quick reply. At the moment, it is a little complicated for me to provide a reasonable reproducible example at the moment since the code is full of nested classes and I am still trying to wrap my head around it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi!
I am new to the Pytorch Lighning CLI and I am struggling modifying an existing pipeline to be able to load checkpoints into the model.
At the moment, in the set up we are using
pl.LightningModule,pl.LightningDataModuleand aconfig.yamlfile.So far, I have been able to correctly initialize/instantiate the
LighningModuleby adding aCheckPointLoaderconstructor to theYaml SafeLoaderclass.The CheckpointLoader uses the
load_from_checkpointfunction to retrieve the parameter bias from the checkpointed model (or whichever parameter of choice). This means that it returns a list with thetorch.Tensor(Side note:I am not sure yet at which point the torch.Tensor returned by theconvert_fnis wrapped into a list and I would also like to avoid that).After the instantiation of pytorch LighningModule class, then the cli proceeds to parse the command line arguments
cli(args=args). Then it struggles because the CheckPointLoader returned a list(torch.Tensor) which cannot be interpreted or evaluated by the parser.That is my intuition about the meaning of the error, perhaps there is something else going on.
Questions:
i) Is this the correct approach to load parameters from a checkpoint into a new model instantiation? We tried different approaches that were more problematic than this one (error-wise)
ii) If so, how can I manipulate the parser so that it would evaluate literally the
torch.Tensor? Something similar to theCheckPointLoaderconstructor or equivalent to the flagtypeused in the.add_argumentfunction in the classicalArgumentParser?I tried to look for possible approaches within the attributes from the
LightningArgumentParserandArgumentParserclasses, however it did not make much sense to me.Thank you in advance for your time!
Beta Was this translation helpful? Give feedback.
All reactions