mit-ll-responsible-ai/hydra-zen

Move `OmegaConf.resolve(cfg)` after `pre_call`

petosa opened this issue · 6 comments

petosa commented

Hello,

I am using the @zen decorator in my project, and using its pre_call arg to modify my config. I am trying to modify the unresolved config, but pre_call gets the config after OmegaConf.resolve(cfg) has been run.

Can OmegaConf.resolve(cfg) please be moved to be after self.pre_call(cfg) to allow for more flexibility?

jgbos commented

@petosa I'll think about it (and I'm sure @rsokl will have more insight) but I don't think this is possible in hydra-zen as the resolver is handled by Hydra. You might want to look into Hydra callbacks: https://hydra.cc/docs/experimental/callbacks/

petosa commented

Thanks for your reply. Couldn't the requested change be achieved by moving line 336 in the linked code to line 340?

jgbos commented

Yeah, I can try and look at it. @rsokl might have a better understanding of the dynamics at play between hydra-zen and Hydra here though, but we may not want to mess with that behavior. It still might be better to use callbacks (which can be configured with hydra-zen). I'm not sure when the resolver is called for callbacks though. Do you have a simple example of what you are trying to do? Maybe there's another solution?

rsokl commented

I like the idea of being able to use pre_call to do stuff to the cfg before it gets resolved. Moving resolve is no good because it could easily break people's existing code.

Off the top of my head, I think Zen/zen should have a resolve_cfg: bool = True param. For your desired case, you would pass resolve_cfg=False then have your pre_call function be responsible for calling OmegaConf.resolve at the end. This would permit maximum flexibility.

I would happily accept a PR for this. Our CI seems to need some tending to due to breaking changes in pydantic and some other flakiness, so be warned that it might be a little noisy. I hope to fix it this weekend.

rsokl commented

(CI is back in good health)

rsokl commented

@petosa v0.11.0rc4 added zen(resolve_pre_call=False) to address this limitation. Try it out with pip install --pre hydra-zen