Skip to content

[Bug] Cannot use target kwarg when instantiating with hydra.utils.instantiate() #1669

@fabiocarrara

Description

@fabiocarrara

🐛 Bug

Description

hydra.utils.instantiate() seems to fail when trying to instantiate a class with a keyword argument called target.
It seems like the two keys _target_ and target are clashing, and this raises a
TypeError: _call_target() got multiple values for argument 'target'.

Checklist

  • I checked on the latest version of Hydra
  • I created a minimal repro (See this for tips).

To reproduce

Minimal Code/Config snippet to reproduce
Available as a Colab Gists:
https://colab.research.google.com/gist/fabiocarrara/6bf5abaecf3f84c1e83239f8af3b8219/hydra_instantiate_bug.ipynb

Stack trace/error message

TypeError                                 Traceback (most recent call last)
<ipython-input-4-616e52dc8a9b> in <module>()
----> 1 foo = hydra.utils.instantiate(cfg.bar)
      2 foo.target

/usr/local/lib/python3.7/dist-packages/hydra/_internal/instantiate/_instantiate2.py in instantiate(config, *args, **kwargs)
    178         _convert_ = config.pop(_Keys.CONVERT, ConvertMode.NONE)
    179 
--> 180         return instantiate_node(config, *args, recursive=_recursive_, convert=_convert_)
    181     else:
    182         raise InstantiationException(

/usr/local/lib/python3.7/dist-packages/hydra/_internal/instantiate/_instantiate2.py in instantiate_node(node, convert, recursive, *args)
    247                         )
    248                     kwargs[key] = _convert_node(value, convert)
--> 249             return _call_target(target, *args, **kwargs)
    250         else:
    251             # If ALL or PARTIAL non structured, instantiate in dict and resolve interpolations eagerly.

TypeError: _call_target() got multiple values for argument 'target'

Expected Behavior

target should be a permitted key name for callable/constructor's kwargs.

System information

  • Hydra Version : 1.1
  • Python version : 3.7.10 (Colab)
  • Virtual environment type and version : none
  • Operating system : Colab

Metadata

Metadata

Assignees

Labels

In progressWork in progressbugSomething isn't working

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions