-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] resolve individual resolver arguments #100
Comments
Interesting, do you have a concrete use case where this would be useful? |
For example when I run a test a machine learning model using hydra I usually increment the seed k times to get confidence intervals on my results. To do so I have This would be totally fine if I had only one value to update but there are multiple values I update at the begining of the
And in case I want to run a specific seed I can still use |
Gotcha.
I will consider supporting it though. I don't want to push it too far (for example, nesting resolvers is definitely out of scope : |
Here is an other example which is more complex: I'm running K-shot (few) learning tasks. So I can run MNIST with 10 examples or 100 examples. One way of doing it with hydra would be to have a config file for all K (MNIST10,MNIST100). This is neither scalable nor clean. So what I end up doing is having a single config file for MNIST and can change K from the command line. This all sounds good until you know that usually the K in K-shot learning is a multiple of the number of classes. In MNIST there are 10 labels, meaning that I would usually do K=10,50,100,1000. But what happens when I have mutliple datasets (e.g. CIFAR100 and MNIST with 100 and 10 labels respectively). What I'm currently doing is :
# update_args_
if args.k is not None:
args.k = args.factor * args.dataset.n_labels Then from the CLI I can either fix |
I completely agree, that's why I was saying that allowing depth 2 without nesting resolvers is, I think, already enough to allow the user to do whatever they like (by definining temporary variables if they really need to, although I don't even think this should be done). |
There is another feature under consideration (#91) that will also help with this use case. |
Yes the other one would cover all the usecases I actually have. Although this one is more general (but harder to read). |
Feel free to send a PR attempting this (with tests). |
conditionally for 2.0 if @apsdehal implements on time. |
Hi, from functools import reduce
import numpy as np
from omegaconf import OmegaConf
cfg = OmegaConf.create(
"""
env:
obs_shape: [1, 2, 3]
obs_flat: '${flatten:env.obs_shape}'
"""
)
OmegaConf.register_resolver(
"flatten",
lambda arg: np.prod(
reduce(lambda container, name: container[name], arg.split("."), cfg)
),
)
print(OmegaConf.to_container(cfg, resolve=True,))
# {'env': {'obs_shape': [1, 2, 3]}, 'obs_flat': 6} This can obviously be extended if you want to allow literals as well as variable names, or to call other resolvers, etc. |
Nice. |
Thanks 🙂 👍 , I didn't see that before |
I'm not sure it's that difficult given how simple the grammar is (at least if we don't aim for maximal speed). I actually played around a bit with it and feel like I may have something worth a shot. I'll try and put up a draft PR for you to check later today. |
Awesome. |
I noticed an issue with the nested interpolation. When calling
The nested interpolation fields are surrounded with " ' ", thus when latter reloaded, the resulting value shows as a |
@charleswilmot , open a new issue. include your OmegaConf version and a minimal repo, along with what you are expecting to see. |
Yes, forgot about it. |
@charleswilmot I tried to repro but failed -- the new version from #321 may have fixed it, could you please check? Thanks! |
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes omry#100 and omry#318
* Add a grammar to parse interpolations * Add support for nested interpolations * Deprecate register_resolver() and introduce new_register_resolver() (that allows resolvers to use non-string arguments, and to decide whether or not to use the cache) * The `env` resolver now parses environment variables in a way that is consistent with the new interpolation grammar Fixes #100 #230 #266 #318
Hi, I'm having the same issue, trying to resolve an interpolation in a custom resolver. |
This should work with dev setup on the current master branch, but there is no publicly available package yet with this new feature. |
Thank you, it works ! |
It would be nice to enable recursive interpolation.
Example :
But one would hope to get
3.0
outNote that 2 recursion would be enough to enable the user to create deeper interpolation if they need it (by calling an other key which had already been interpolated).
The text was updated successfully, but these errors were encountered: