question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] utils.instantiate fails with dict kwarg inputs

See original GitHub issue

🐛 Bug

utils.instantiate fails with dict kwarg inputs

To reproduce

Minimal Code/Config snippet to reproduce

Suppose I have a config group file

model:
  class: models.Net
  params:
    some: 0
    values: 1

Let’s say I want to pass in a dictionary to models.Net as follows: utils.instantiate(cfg.model, some_config_argument={'test': 'dict'})

Stack trace/error message

This will throw KeyError: 'Accessing unknown key in a struct : model.params.test'

from params.merge_with(OmegaConf.create(kwargs)) in the instantiate function.

Expected Behavior

Expected to succeed and pass in the dict kwarg to the class constructor

System information

  • Hydra Version : 0.11.0
  • Python version : 3.7.6
  • Virtual environment type and version : Conda
  • Operating system : OS X

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
omrycommented, Mar 19, 2020

closing as fixed in master. feel free to join the chat if you have questions.

1reaction
omrycommented, Mar 19, 2020
  1. Awesome that it works on master. if you can stick to master to give it some testing as it evolves please do. (generally all tests are passing in master).

  2. If I am understanding your problem correctly, try something like:

config.yaml

defaults:
  - optimizer: adam

foobar:
  cls: FooBar
  params:
    opt_cfg: ???

optimizer/adam.yaml

foobar:
  params:
    opt_cfg:
      cls: torch.Adam
      params:
        alpha: 0.1
        beta: 0.99
Read more comments on GitHub >

github_iconTop Results From Across the Web

Converting Python dict to kwargs? - Stack Overflow
I want to build a query for sunburnt(solr interface) using class inheritance and therefore adding key - value pairs together. The sunburnt ...
Read more >
Utilities — MONAI 1.1.0 Documentation
Create an object instance or partial function from a class or function represented by string. kwargs will be part of the input arguments...
Read more >
Globals - Bazel
It is an error if the implementation function omits any of the types of providers listed here from its return value. However, the...
Read more >
Supported Python features - Numba
Explicit **kwargs are not supported. Function calls to locally defined inner functions are supported as long as they can be fully inlined.
Read more >
Pipelines - Hugging Face
from transformers import pipeline from transformers.pipelines.pt_utils import ... inputs ( np.ndarray or bytes or str or dict ) — The inputs is either...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found