Closed aRI0U closed 7 months ago
I'm wondering why not do it outside of my_hydra_main
? it doesn't seem like you are using any of the Hydra API to register new resolver, so you could have something like
def register_my_resolver():
for name, resolver in extra_resolvers.items():
OmegaConf.register_new_resolver(name, resolver)
@hydra_main(...)
def main(cfg):
...
register_my_resolver()
Note that the position of the call to register_my_resolver()
doesn't actually matter, and could be before main()
. I would tend to favor this option as this makes it clear from the code, that the registration of the resolvers will leak to any other call to OmegaConf, and I would tend to think a PR is not needed for that use case. Potentially an update to the README to show this pattern.
Regarding question 1., get_xp()
needs to resolve the config because this is how the signature is actually derived. It will resolve the full config, compare it with the base config and build a delta. The hash of the delta is then the signature.
Indeed your solution works.
I initially tried something similar but since I put register_new_resolver()
inside my if __name__ == '__main__':
block it wasn't executed, which made me (wrongly) think that when using the dora
command, only the piece of code inside hydra_main
was executed.
Maybe mentioning this point in the README could be helpful, insisting on the fact that the register_new_resolver
should be outside of the if __name__ == '__main__'
, which is a bit unusual.
Thanks a lot!
❓ Questions
Hi, With
hydra
and more generallyomegaconf
, it is possible to register new resolvers to apply custom functions directly within the YAML configuration. I can for example do the following:which enables me to put directly in my yaml file:
However, when using Dora's
hydra_main
, this doesn't work anymore. Indeed when I use e.g.dora run
, the first thing executed ismain.get_xp
and for some reason this function under the hood resolves the whole config, thus raising anInterpolationError
since the custom resolver hasn't been registered yet.The only workaround I found to resolve this issue consists in directly overriding
hydra_main
:This works quite well, however I'd have 3 questions:
main.get_xp()
in Dora, since anyway thecfg
arg of theDecoratedMain
is not resolved? If yes, why?hydra_main
bymy_hydra_main
in next version? Since it only adds an optional arg that is not used by the originalhydra_main
, hopefully it shouldn't break anything.Thanks a lot!