code: def init_instance_by_config(
      config: InstConf,
      default_module=None,
      accept_types: Union[type, Tuple[type]] = (),
      try_kwargs: Dict = {},
      **kwargs,
  ) -> Any:
      """
      get initialized instance with config
  
      Parameters
      ----------
      config : InstConf
  
      default_module : Python module
          Optional. It should be a python module.
          NOTE: the "module_path" will be override by `module` arguments
  
          This function will load class from the config['module_path'] first.
          If config['module_path'] doesn't exists, it will load the class from default_module.
  
      accept_types: Union[type, Tuple[type]]
          Optional. If the config is a instance of specific type, return the config directly.
          This will be passed into the second parameter of isinstance.
  
      try_kwargs: Dict
          Try to pass in kwargs in `try_kwargs` when initialized the instance
          If error occurred, it will fail back to initialization without try_kwargs.
  
      Returns
      -------
      object:
          An initialized object based on the config info
      """
      if isinstance(config, accept_types):
          return config
  
      if isinstance(config, (str, Path)):
          if isinstance(config, str):
              # path like 'file:///<path to pickle file>/obj.pkl'
              pr = urlparse(config)
              if pr.scheme == "file":
                  pr_path = (
                      os.path.join(pr.netloc, pr.path)
                      if bool(pr.path)
                      else pr.netloc
                  )
                  with open(os.path.normpath(pr_path), "rb") as f:
                      return pickle.load(f)
          else:
              with config.open("rb") as f:
                  return pickle.load(f)
  
      klass, cls_kwargs = get_callable_kwargs(
          config, default_module=default_module
      )
  
      try:
          return klass(**cls_kwargs, **try_kwargs, **kwargs)
      except (TypeError,):
          # TypeError for handling errors like
          # 1: `XXX() got multiple values for keyword argument 'YYY'`
          # 2: `XXX() got an unexpected keyword argument 'YYY'
          return klass(**cls_kwargs, **kwargs)
  
file_path: qlib/qlib/utils/mod.py
imports: import contextlib
  import importlib
  import os
  from pathlib import Path
  import pickle
  import pkgutil
  import re
  import sys
  from types import ModuleType
  from typing import Any, Dict, List, Tuple, Union
  from urllib.parse import urlparse
  from qlib.typehint import InstConf
label_desc: Use image node_id 4 for calling a global function with example usage: init_instance_by_config(config, default_module, accept_types, try_kwargs) and returns: config, klass, klass, pickle, pickle