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.
-
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.LightningDataModule
and aconfig.yaml
file.So far, I have been able to correctly initialize/instantiate the
LighningModule
by adding aCheckPointLoader
constructor to theYaml SafeLoader
class.The CheckpointLoader uses the
load_from_checkpoint
function 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_fn
is 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 theCheckPointLoader
constructor or equivalent to the flagtype
used in the.add_argument
function in the classicalArgumentParser
?I tried to look for possible approaches within the attributes from the
LightningArgumentParser
andArgumentParser
classes, 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