(config: Any, *args: Any, **kwargs: Any)
:param config: An config object describing what to call and what params to use.
                   In addition to the parameters, the config must contain:
                   _target_ : target class or callable name (str)
                   And may contain:
                   _args_: List-like of positional arguments to pass to the target
                   _recursive_: Construct nested objects as well (bool).
                                True by default.
                                may be overridden via a _recursive_ key in
                                the kwargs
                   _convert_: Conversion strategy
                        none    : Passed objects are DictConfig and ListConfig, default
                        partial : Passed objects are converted to dict and list, with
                                  the exception of Structured Configs (and their fields).
                        all     : Passed objects are dicts, lists and primitives without
                                  a trace of OmegaConf containers
                   _partial_: If True, return functools.partial wrapped method or object
                              False by default. Configure per target.
    :param args: Optional positional parameters pass-through
    :param kwargs: Optional named parameters to override
                   parameters in the config object. Parameters not present
                   in the config objects are being passed as is to the target.
                   IMPORTANT: dataclasses instances in kwargs are interpreted as config
                              and cannot be used as passthrough
    :return: if _target_ is a class name: the instantiated object
             if _target_ is a callable: the return value of the call
:param config: An config object describing what to call and what params to use.
                   In addition to the parameters, the config must contain:
                   _target_ : target class or callable name (str)
                   And may contain:
                   _args_: List-like of positional arguments to pass to the target
                   _recursive_: Construct nested objects as well (bool).
                                True by default.
                                may be overridden via a _recursive_ key in
                                the kwargs
                   _convert_: Conversion strategy
                        none    : Passed objects are DictConfig and ListConfig, default
                        partial : Passed objects are converted to dict and list, with
                                  the exception of Structured Configs (and their fields).
                        all     : Passed objects are dicts, lists and primitives without
                                  a trace of OmegaConf containers
                   _partial_: If True, return functools.partial wrapped method or object
                              False by default. Configure per target.
    :param args: Optional positional parameters pass-through
    :param kwargs: Optional named parameters to override
                   parameters in the config object. Parameters not present
                   in the config objects are being passed as is to the target.
                   IMPORTANT: dataclasses instances in kwargs are interpreted as config
                              and cannot be used as passthrough
    :return: if _target_ is a class name: the instantiated object
             if _target_ is a callable: the return value of the call
: param config : An config object describing what to call and what params to use . In addition to the parameters the config must contain : _target_ : target class or callable name ( str ) And may contain : _args_ : List - like of positional arguments to pass to the target _recursive_ : Construct nested objects as well ( bool ) . True by default . may be overridden via a _recursive_ key in the kwargs _convert_ : Conversion strategy none : Passed objects are DictConfig and ListConfig default partial : Passed objects are converted to dict and list with the exception of Structured Configs ( and their fields ) . all : Passed objects are dicts lists and primitives without a trace of OmegaConf containers _partial_ : If True return functools . partial wrapped method or object False by default . Configure per target . : param args : Optional positional parameters pass - through : param kwargs : Optional named parameters to override parameters in the config object . Parameters not present in the config objects are being passed as is to the target . IMPORTANT : dataclasses instances in kwargs are interpreted as config and cannot be used as passthrough : return : if _target_ is a class name : the instantiated object if _target_ is a callable : the return value of the call
def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any:
    """
    :param config: An config object describing what to call and what params to use.
                   In addition to the parameters, the config must contain:
                   _target_ : target class or callable name (str)
                   And may contain:
                   _args_: List-like of positional arguments to pass to the target
                   _recursive_: Construct nested objects as well (bool).
                                True by default.
                                may be overridden via a _recursive_ key in
                                the kwargs
                   _convert_: Conversion strategy
                        none    : Passed objects are DictConfig and ListConfig, default
                        partial : Passed objects are converted to dict and list, with
                                  the exception of Structured Configs (and their fields).
                        all     : Passed objects are dicts, lists and primitives without
                                  a trace of OmegaConf containers
                   _partial_: If True, return functools.partial wrapped method or object
                              False by default. Configure per target.
    :param args: Optional positional parameters pass-through
    :param kwargs: Optional named parameters to override
                   parameters in the config object. Parameters not present
                   in the config objects are being passed as is to the target.
                   IMPORTANT: dataclasses instances in kwargs are interpreted as config
                              and cannot be used as passthrough
    :return: if _target_ is a class name: the instantiated object
             if _target_ is a callable: the return value of the call
    """

    # Return None if config is None
    if config is None:
        return None

    # TargetConf edge case
    if isinstance(config, TargetConf) and config._target_ == "???":
        # Specific check to give a good warning about failure to annotate _target_ as a string.
        raise InstantiationException(
            f"Missing value for {type(config).__name__}._target_. Check that it's properly annotated and overridden."
            f"\nA common problem is forgetting to annotate _target_ as a string : '_target_: str = ...'"
        )

    if isinstance(config, dict):
        config = _prepare_input_dict(config)

    kwargs = _prepare_input_dict(kwargs)

    # Structured Config always converted first to OmegaConf
    if is_structured_config(config) or isinstance(config, dict):
        config = OmegaConf.structured(config, flags={"allow_objects": True})

    if OmegaConf.is_dict(config):
        # Finalize config (convert targets to strings, merge with kwargs)
        config_copy = copy.deepcopy(config)
        config_copy._set_flag(
            flags=["allow_objects", "struct", "readonly"], values=[True, False, False]
        )
        config_copy._set_parent(config._get_parent())
        config = config_copy

        if kwargs:
            config = OmegaConf.merge(config, kwargs)

        OmegaConf.resolve(config)

        _recursive_ = config.pop(_Keys.RECURSIVE, True)
        _convert_ = config.pop(_Keys.CONVERT, ConvertMode.NONE)
        _partial_ = config.pop(_Keys.PARTIAL, False)

        return instantiate_node(
            config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_
        )
    else:
        raise InstantiationException(
            "Top level config has to be OmegaConf DictConfig, plain dict, or a Structured Config class or instance"
        )
def instantiate ( config : Any , * args : Any , * * kwargs : Any ) -> Any : # Return None if config is None if config is None : return None # TargetConf edge case if isinstance ( config , TargetConf ) and config . _target_ == "???" : # Specific check to give a good warning about failure to annotate _target_ as a string. raise InstantiationException ( f"Missing value for {type(config).__name__}._target_. Check that it's properly annotated and overridden." f"\nA common problem is forgetting to annotate _target_ as a string : '_target_: str = ...'" ) if isinstance ( config , dict ) : config = _prepare_input_dict ( config ) kwargs = _prepare_input_dict ( kwargs ) # Structured Config always converted first to OmegaConf if is_structured_config ( config ) or isinstance ( config , dict ) : config = OmegaConf . structured ( config , flags = { "allow_objects" : True } ) if OmegaConf . is_dict ( config ) : # Finalize config (convert targets to strings, merge with kwargs) config_copy = copy . deepcopy ( config ) config_copy . _set_flag ( flags = [ "allow_objects" , "struct" , "readonly" ] , values = [ True , False , False ] ) config_copy . _set_parent ( config . _get_parent ( ) ) config = config_copy if kwargs : config = OmegaConf . merge ( config , kwargs ) OmegaConf . resolve ( config ) _recursive_ = config . pop ( _Keys . RECURSIVE , True ) _convert_ = config . pop ( _Keys . CONVERT , ConvertMode . NONE ) _partial_ = config . pop ( _Keys . PARTIAL , False ) return instantiate_node ( config , * args , recursive = _recursive_ , convert = _convert_ , partial = _partial_ ) else : raise InstantiationException ( "Top level config has to be OmegaConf DictConfig, plain dict, or a Structured Config class or instance" )