简体   繁体   中英

Call hydra.utils.instantiate inside configuration

The following works:

trainer = pl.Trainer(early_stop_callback=hydra.utils.instantiate(cfg.callbacks.early_stopping),
                     **cfg.trainer)

But it makes early_stopping a required parameter. Is there a better way or a way to specify all this in the configuration with something similar to the following?

$ cat trainer.yaml
trainer:
  cls: pytorch_lightning.Trainer
  params:
    early_stop_callback: instantiate(cfg.callbacks.early_stopping)

So that I can do:

trainer = hydra.utils.instantiate(cfg.trainer)

Hydra does not currently support recursive instantiation. This is planned for the next major version though, follow this issue .

Hydra 1.1.0 (2021-06-09) now supports recursive instantiation, see the CHANGELOG , and in particular this issue .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM