LarsKue/lightning-trainable

HParams with dicts (i.e. almost all) store dicts as special AttributeDict type in `hparams.yaml`

Closed this issue · 3 comments

See test case test_trainable/test_load_hparams

I don't particularly mind this. The subdicts are converted to AttributeDict when HParams is created, so this is a natural consequence of that. The hparams.yaml is still clearly readable because it contains the dictitems in clear text.

I agree, but this causes HParams.from_yaml not to work with the hparams.yaml that is stored with the run. This is what is demonstrated in the test case (it does not check for types). The problem is that yaml.safe_load and yaml.full_load do not work as you need to whitelist supported tags (the !!contents). While this could be done in HParams.from_yaml, I think it is useful to just open a hparams.yaml file from arbitrary code.

Fixed by saving hparams as a regular dict. The appropriate HParams class can still be restored by calling

ModelClass.hparams_type.from_yaml(f)