code: def update_model_config(
      model_cls: "nemo.core.config.modelPT.NemoConfig",
      update_cfg: "DictConfig",
      drop_missing_subconfigs: bool = True,
  ):
      """
      Helper class that updates the default values of a ModelPT config class with the values
      in a DictConfig that mirrors the structure of the config class.
  
      Assumes the `update_cfg` is a DictConfig (either generated manually, via hydra or instantiated via yaml/model.cfg).
      This update_cfg is then used to override the default values preset inside the ModelPT config class.
  
      If `drop_missing_subconfigs` is set, the certain sub-configs of the ModelPT config class will be removed, if
      they are not found in the mirrored `update_cfg`. The following sub-configs are subject to potential removal:
          -   `train_ds`
          -   `validation_ds`
          -   `test_ds`
          -   `optim` + nested `sched`.
  
      Args:
          model_cls: A subclass of NemoConfig, that details in entirety all of the parameters that constitute
              the NeMo Model.
  
          update_cfg: A DictConfig that mirrors the structure of the NemoConfig data class. Used to update the
              default values of the config class.
  
          drop_missing_subconfigs: Bool which determins whether to drop certain sub-configs from the NemoConfig
              class, if the corresponding sub-config is missing from `update_cfg`.
  
      Returns:
          A DictConfig with updated values that can be used to instantiate the NeMo Model along with supporting
          infrastructure.
      """
      if not _HAS_HYDRA:
          logging.error(
              "This function requires Hydra/Omegaconf and it was not installed."
          )
          exit(1)
      if not (
          is_dataclass(model_cls) or isinstance(model_cls, DictConfig)
      ):
          raise ValueError(
              "`model_cfg` must be a dataclass or a structured OmegaConf object"
          )
  
      if not isinstance(update_cfg, DictConfig):
          update_cfg = OmegaConf.create(update_cfg)
  
      if is_dataclass(model_cls):
          model_cls = OmegaConf.structured(model_cls)
  
      # Update optional configs
      model_cls = _update_subconfig(
          model_cls,
          update_cfg,
          subconfig_key="train_ds",
          drop_missing_subconfigs=drop_missing_subconfigs,
      )
      model_cls = _update_subconfig(
          model_cls,
          update_cfg,
          subconfig_key="validation_ds",
          drop_missing_subconfigs=drop_missing_subconfigs,
      )
      model_cls = _update_subconfig(
          model_cls,
          update_cfg,
          subconfig_key="test_ds",
          drop_missing_subconfigs=drop_missing_subconfigs,
      )
      model_cls = _update_subconfig(
          model_cls,
          update_cfg,
          subconfig_key="optim",
          drop_missing_subconfigs=drop_missing_subconfigs,
      )
  
      # Add optim and sched additional keys to model cls
      model_cls = _add_subconfig_keys(
          model_cls, update_cfg, subconfig_key="optim"
      )
  
      # Perform full merge of model config class and update config
      # Remove ModelPT artifact `target`
      if "target" in update_cfg.model:
          # Assume artifact from ModelPT and pop
          if "target" not in model_cls.model:
              with open_dict(update_cfg.model):
                  update_cfg.model.pop("target")
  
      # Remove ModelPT artifact `nemo_version`
      if "nemo_version" in update_cfg.model:
          # Assume artifact from ModelPT and pop
          if "nemo_version" not in model_cls.model:
              with open_dict(update_cfg.model):
                  update_cfg.model.pop("nemo_version")
  
      model_cfg = OmegaConf.merge(model_cls, update_cfg)
  
      return model_cfg
  
file_path: NeMo/nemo/utils/config_utils.py
imports: import copy
  import inspect
  from dataclasses import is_dataclass
  from typing import Dict, List, Optional
  from nemo.utils import logging
label_desc: Use image node_id 1 for calling a global function with example usage: update_model_config(model_cls, update_cfg, drop_missing_subconfigs) and returns: model_cfg