Repository: facebookresearch/hydra

Issue:
[Bug] Cannot use `target` kwarg when instantiating with `hydra.utils.instantiate()`
# 🐛 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
- [x] I checked on the latest version of Hydra
- [x] I created a minimal repro (See [this](https://stackoverflow.com/help/minimal-reproducible-example) 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



Discussion:
Thanks for reporting, we will take a look.
Here is a minimal repro:
```python
# repro.py
from hydra.utils import instantiate
from omegaconf import OmegaConf
from pytest import raises

class Foo:
    def __init__(self, target):
        self.arget = target

cfg = OmegaConf.create({"_target_": "repro.Foo", "target": "asd"})

with raises(TypeError):
    instantiate(cfg)
```
No error is raised if the 'target' parameter is renamed.

Resolving patch:
diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py
--- a/hydra/_internal/instantiate/_instantiate2.py
+++ b/hydra/_internal/instantiate/_instantiate2.py
@@ -45,7 +45,7 @@ def _extract_pos_args(*input_args: Any, **kwargs: Any) -> Tuple[Any, Any]:
     return output_args, kwargs
 
 
-def _call_target(target: Callable, *args, **kwargs) -> Any:  # type: ignore
+def _call_target(_target_: Callable, *args, **kwargs) -> Any:  # type: ignore
     """Call target (type) with args and kwargs."""
     try:
         args, kwargs = _extract_pos_args(*args, **kwargs)
@@ -59,10 +59,10 @@ def _call_target(target: Callable, *args, **kwargs) -> Any:  # type: ignore
             if OmegaConf.is_config(v):
                 v._set_parent(None)
 
-        return target(*args, **kwargs)
+        return _target_(*args, **kwargs)
     except Exception as e:
         raise type(e)(
-            f"Error instantiating '{_convert_target_to_string(target)}' : {e}"
+            f"Error instantiating '{_convert_target_to_string(_target_)}' : {e}"
         ).with_traceback(sys.exc_info()[2])
 
 
@@ -237,7 +237,7 @@ def instantiate_node(
     elif OmegaConf.is_dict(node):
         exclude_keys = set({"_target_", "_convert_", "_recursive_"})
         if _is_target(node):
-            target = _resolve_target(node.get(_Keys.TARGET))
+            _target_ = _resolve_target(node.get(_Keys.TARGET))
             kwargs = {}
             for key, value in node.items():
                 if key not in exclude_keys:
@@ -246,7 +246,7 @@ def instantiate_node(
                             value, convert=convert, recursive=recursive
                         )
                     kwargs[key] = _convert_node(value, convert)
-            return _call_target(target, *args, **kwargs)
+            return _call_target(_target_, *args, **kwargs)
         else:
             # If ALL or PARTIAL non structured, instantiate in dict and resolve interpolations eagerly.
             if convert == ConvertMode.ALL or (


Test patch:
diff --git a/tests/instantiate/__init__.py b/tests/instantiate/__init__.py
--- a/tests/instantiate/__init__.py
+++ b/tests/instantiate/__init__.py
@@ -54,6 +54,11 @@ class BClass:
     d: Any = "d"
 
 
+@dataclass
+class TargetInParamsClass:
+    target: Any
+
+
 @dataclass
 class UntypedPassthroughConf:
     _target_: str = "tests.instantiate.UntypedPassthroughClass"
diff --git a/tests/instantiate/test_instantiate.py b/tests/instantiate/test_instantiate.py
--- a/tests/instantiate/test_instantiate.py
+++ b/tests/instantiate/test_instantiate.py
@@ -37,6 +37,7 @@
     SimpleClassNonPrimitiveConf,
     SimpleClassPrimitiveConf,
     SimpleDataClass,
+    TargetInParamsClass,
     Tree,
     TreeConf,
     UntypedPassthroughClass,
@@ -188,6 +189,12 @@ def config(request: Any, src: Any) -> Any:
             UntypedPassthroughClass(a=IllegalType()),
             id="untyped_passthrough",
         ),
+        param(
+            TargetInParamsClass,
+            {"target": "test"},
+            TargetInParamsClass(target="test"),
+            id="target_in_params",
+        ),
     ],
 )
 def test_class_instantiate(