Hydra fails to instantiate when the caller expects an arg called params and the value is not a supported primitive type.
https://colab.research.google.com/drive/16jOM9kKwSpu1DdUcJETMe6LOz0G9Gnqh?usp=sharing
* Stack trace/error message *
UnsupportedValueType: Value 'Parameter' is not a supported primitive type
full_key: params[0]
reference_type=Optional[List[Any]]
object_type=list
No Exception
NA
A similar issue appears when instantiating with additional params:
tr_sys = hydra.utils.instantiate(cfg.system,
hparams=cfg,
logger=wandb_logger,
n_gpus=n_gpus)
omegaconf.errors.ConfigKeyError: Key 'n_gpus' in not in struct
full_key: system.params.n_gpus
reference_type=Optional[Dict[Any, Any]]
object_type=dict
BartekRoszak,
Why is n_gpus not in the cfg.system?
This can be fixed in Hydra, but honestly I think it tells you that your config is wrong.
n_gpus value is computed at the beginning of the script and I am using it in few places so it is comfortable for me to set it in such a way and it worked well in the previous version.
num_gpus: 1
system:
num_gpus: ${num_gpus}
num_gpus: 1
system:
num_gpus: ???
What's the point in allowing extra parameters this way if you're not allowed to use it this way?
I have some shared computation which triggers this exact same problem (and it's not something which can be known before hand to put in the config file...).
The point is that there is a bug.
I did not look dug in yet, but the plan is to fix it.
if you don't like it you have three options:
These are the options.
good luck.
I am sorry my comment appeared more confrontational than it should have - thanks for your clarification (and your great configuration libraries, the concept is very simple yet it is a great improvement in practice).
Apology accepted.
Thanks for clearing the air.
The value this is already providing is it allow you to pass-through objects of types not supported in the config.
You can see the existing unit tests here.
Looks like something fell through the cracks (and is potentially a regression in 1.0).
@shagunsodhani :
in your collab, this works:
optimizer = hydra.utils.instantiate(config, params=net.parameters())
Did you try this? this seems like an obvious way to do it.
If there are additional problems open separate issues with a minimal repro for each.
@shagunsodhani :
in your collab, this works:optimizer = hydra.utils.instantiate(config, params=net.parameters())Did you try this? this seems like an obvious way to do it.
Yes, this is what I end up using :)
This is the correct form to pass-through arguments by name.
Your example on 1.0rc1, with my comments:
https://colab.research.google.com/drive/1AG7PL5hmzW70gWmgZZAbqHdP4oLGDcA6
Your example on 1.0.rc2 (master) , with my comments:
https://colab.research.google.com/drive/1L1lNte8Gk5qeqvqw7J22UckJWQjmzgER
@omry I do not have access to the colab notebooks. I have sent the request for access :)