docstr: Instantiates object using DictConfig-based configuration
docstr_tok: ["Instantiates","object","using","DictConfig-based","configuration"]
code: def from_config_dict(
      cls, config: "DictConfig", trainer: Optional["Trainer"] = None
  ):
      """Instantiates object using DictConfig-based configuration"""
      # Resolve the config dict
      if _HAS_HYDRA:
          if isinstance(config, DictConfig):
              config = OmegaConf.to_container(config, resolve=True)
              config = OmegaConf.create(config)
              OmegaConf.set_struct(config, True)
  
          config = maybe_update_config_version(config)
  
      # Hydra 0.x API
      if (
          ("cls" in config or "target" in config)
          and "params" in config
          and _HAS_HYDRA
      ):
          # regular hydra-based instantiation
          instance = hydra.utils.instantiate(config=config)
      # Hydra 1.x API
      elif "_target_" in config and _HAS_HYDRA:
          # regular hydra-based instantiation
          instance = hydra.utils.instantiate(config=config)
      else:
          instance = None
          prev_error = ""
          # Attempt class path resolution from config `target` class (if it exists)
          if "target" in config:
              target_cls = config[
                  "target"
              ]  # No guarantee that this is a omegaconf class
              imported_cls = None
              try:
                  # try to import the target class
                  imported_cls = import_class_by_path(target_cls)
                  # if calling class (cls) is subclass of imported class,
                  # use subclass instead
                  if issubclass(cls, imported_cls):
                      imported_cls = cls
                  accepts_trainer = (
                      Serialization._inspect_signature_for_trainer(
                          imported_cls
                      )
                  )
                  if accepts_trainer:
                      instance = imported_cls(
                          cfg=config, trainer=trainer
                      )
                  else:
                      instance = imported_cls(cfg=config)
              except Exception as e:
                  # record previous error
                  tb = traceback.format_exc()
                  prev_error = (
                      f"Model instantiation failed!\nTarget class:\t{target_cls}"
                      f"\nError(s):\t{e}\n{tb}"
                  )
                  logging.debug(prev_error + "\nFalling back to `cls`.")
  
          # target class resolution was unsuccessful, fall back to current `cls`
          if instance is None:
              try:
                  accepts_trainer = (
                      Serialization._inspect_signature_for_trainer(cls)
                  )
                  if accepts_trainer:
                      instance = cls(cfg=config, trainer=trainer)
                  else:
                      instance = cls(cfg=config)
  
              except Exception as e:
                  # report saved errors, if any, and raise
                  if prev_error:
                      logging.error(prev_error)
                  raise e
  
      if not hasattr(instance, "_cfg"):
          instance._cfg = config
      return instance
  
imports: import hashlib
  import inspect
  import traceback
  from abc import ABC, abstractmethod
  from contextlib import contextmanager
  from dataclasses import dataclass, field
  from enum import Enum
  from functools import total_ordering
  from pathlib import Path
  from typing import Dict, Iterable, List, Optional, Tuple, Union
  import hydra
  import torch
  import wrapt
  from huggingface_hub import HfApi, HfFolder, ModelFilter, hf_hub_download
  from huggingface_hub.hf_api import ModelInfo
  from omegaconf import DictConfig, OmegaConf
  import nemo
  from nemo.core.connectors.save_restore_connector import SaveRestoreConnector
  from nemo.core.neural_types import NeuralType, NeuralTypeComparisonResult
  from nemo.utils import logging
  from nemo.utils.cloud import maybe_download_from_cloud
  from nemo.utils.data_utils import resolve_cache_dir
  from nemo.utils.model_utils import import_class_by_path, maybe_update_config_version
label_desc: Use image node_id 1 for calling the Serialization obj's underlying member method code with example usage: obj.from_config_dict(cls, config, trainer) and returns: instance