HyperPyYAML icon indicating copy to clipboard operation
HyperPyYAML copied to clipboard

Apply a method to a class defined in yaml file

Open minniekabra opened this issue 4 months ago • 0 comments

Hi,

I want to use the class defined in yaml file to get a method associated with it.

Intuitively, it's something like -

!apply: !ref <class.method>

But since input to apply is a callable string, this will not work.

In particular I have defined -

mbart_model: !apply:transformers.MBartForConditionalGeneration.from_pretrained
    pretrained_model_name_or_path: facebook/mbart-large-50

And I want to get mbart_decoder, like this mbart_model.get_decoder() This defines it but does not call decoder

mbart_decoder: !ref <mbart_model.get_decoder>

Mbart_decoder needs to be further called when yaml file is loaded -

from hyperpyyaml import load_hyperpyyaml

with open('hparams.yaml') as fin:
    hparams = load_hyperpyyaml(fin)
mbart_decoder=hparams['mbart_decoder']
decoder=mbart_decoder()

Based on my exploration, I don't think mbart_decoder can be directly called through yaml file.

Can it be given a thought, or checked, please?

minniekabra avatar Sep 04 '25 21:09 minniekabra