LarsKue / lightning-trainable

A default trainable module for pytorch lightning.
MIT License
10 stars 1 forks source link

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

Closed fdraxler closed 10 months ago

fdraxler commented 10 months ago

See test case test_trainable/test_load_hparams

LarsKue commented 10 months ago

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.

fdraxler commented 10 months ago

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.

LarsKue commented 10 months ago

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

ModelClass.hparams_type.from_yaml(f)