class_docstr: NLP Adapter Mixin that can augment any transformer-based model with Adapter module support.
  This mixin class should be used only with a top level ModelPT subclass, that includes either a `model` or an `enc_dec_model` submodule.
  This mixin class adds several utility methods to add, load and save adapters.
  
  An Adapter module is any Pytorch nn.Module that possess a few properties :
  
  - It's input and output dimension are the same, while the hidden dimension need not be the same.
  - The final layer of the Adapter module is zero-initialized, so that the residual connection to the adapter yields the original output.
  
  This mixin class aims to integrate with PEFT, which is one or more adapters modules.
  The two features of PEFT, layer selection and weight tying, are also supported in this mixin class.
class_docstr_tok: ["NLP","Adapter","Mixin","that","can","augment","any","transformer-based","model","with","Adapter","module","support",".","This","mixin","class","should","be","used","only","with","a","top","level","ModelPT","subclass",",","that","includes","either","a","`","model","`","or","an","`","enc_dec_model","`","submodule",".","This","mixin","class","adds","several","utility","methods","to","add",",","load","and","save","adapters",".","An","Adapter","module","is","any","Pytorch","nn.Module","that","possess","a","few","properties",":","-","It","'s","input","and","output","dimension","are","the","same",",","while","the","hidden","dimension","need","not","be","the","same",".","-","The","final","layer","of","the","Adapter","module","is","zero-initialized",",","so","that","the","residual","connection","to","the","adapter","yields","the","original","output",".","This","mixin","class","aims","to","integrate","with","PEFT",",","which","is","one","or","more","adapters","modules",".","The","two","features","of","PEFT",",","layer","selection","and","weight","tying",",","are","also","supported","in","this","mixin","class","."]
docstr: Merge a given configuration dictionary `cfg` with the configuration dictionary
  obtained from restoring a MegatronGPTSFTModel or MegatronT5SFTModel at the specified `path`.
  
  Args:
      path (str): The path to the SFT model checkpoint to be restored.
      cfg (DictConfig): The configuration dictionary to merge.
  
  Returns:
      DictConfig: The merged configuration dictionary.
  
  Examples:
      >>> path = "/path/to/model/checkpoint"
      >>> cfg = DictConfig({"model": {"key": "value"}, "trainer": {"precision": 16}})
      >>> merged_cfg = merge_cfg_with(path, cfg)
  
  Notes:
      - The function resolves variables within the `cfg` dictionary using `OmegaConf.resolve`.
      - Keys in `cfg.model` will override the corresponding keys in the output dictionary.
      - If "train_ds" exists in `cfg.model.data`, it updates `micro_batch_size` and `global_batch_size`.
      - If `cfg.trainer` contains a "precision" key, it updates `output.precision`.
docstr_tok: ["Merge","a","given","configuration","dictionary","`","cfg","`","with","the","configuration","dictionary","obtained","from","restoring","a","MegatronGPTSFTModel","or","MegatronT5SFTModel","at","the","specified","`","path","`",".","Args",":","path","(","str",")",":","The","path","to","the","SFT","model","checkpoint","to","be","restored",".","cfg","(","DictConfig",")",":","The","configuration","dictionary","to","merge",".","Returns",":","DictConfig",":","The","merged","configuration","dictionary",".","Examples",":",">",">",">","path","=","``","\/path\/to\/model\/checkpoint","''",">",">",">","cfg","=","DictConfig","(","{","``","model","''",":","{","``","key","''",":","``","value","''","}",",","``","trainer","''",":","{","``","precision","''",":","16","}","}",")",">",">",">","merged_cfg","=","merge_cfg_with","(","path",",","cfg",")","Notes",":","-","The","function","resolves","variables","within","the","`","cfg","`","dictionary","using","`","OmegaConf.resolve","`",".","-","Keys","in","`","cfg.model","`","will","override","the","corresponding","keys","in","the","output","dictionary",".","-","If","``","train_ds","''","exists","in","`","cfg.model.data","`",",","it","updates","`","micro_batch_size","`","and","`","global_batch_size","`",".","-","If","`","cfg.trainer","`","contains","a","``","precision","''","key",",","it","updates","`","output.precision","`","."]
code: def merge_cfg_with(cls, path: str, cfg: DictConfig) -> DictConfig:
      """
      Merge a given configuration dictionary `cfg` with the configuration dictionary
      obtained from restoring a MegatronGPTSFTModel or MegatronT5SFTModel at the specified `path`.
  
      Args:
          path (str): The path to the SFT model checkpoint to be restored.
          cfg (DictConfig): The configuration dictionary to merge.
  
      Returns:
          DictConfig: The merged configuration dictionary.
  
      Examples:
          >>> path = "/path/to/model/checkpoint"
          >>> cfg = DictConfig({"model": {"key": "value"}, "trainer": {"precision": 16}})
          >>> merged_cfg = merge_cfg_with(path, cfg)
  
      Notes:
          - The function resolves variables within the `cfg` dictionary using `OmegaConf.resolve`.
          - Keys in `cfg.model` will override the corresponding keys in the output dictionary.
          - If "train_ds" exists in `cfg.model.data`, it updates `micro_batch_size` and `global_batch_size`.
          - If `cfg.trainer` contains a "precision" key, it updates `output.precision`.
  
      """
  
      base_cfg = cls.restore_from(path, return_config=True)
  
      OmegaConf.resolve(cfg)
      with open_dict(base_cfg):
          for key, val in cfg.model.items():
              base_cfg[key] = val
          if "train_ds" in cfg.model.data:
              base_cfg.micro_batch_size = (
                  cfg.model.data.train_ds.micro_batch_size
              )
              base_cfg.global_batch_size = (
                  cfg.model.data.train_ds.global_batch_size
              )
          if cfg.get("trainer", None) and cfg.trainer.get("precision"):
              base_cfg.precision = cfg.trainer.precision
  
      return base_cfg
  
imports: import os
  import tempfile
  from typing import List, Optional, Union
  import torch
  from omegaconf import DictConfig, OmegaConf, open_dict
  from nemo.utils.model_utils import inject_model_parallel_rank
  from nemo.collections.nlp.modules.common.megatron.adapters.parallel_adapters import PromptEncoderAdapterConfig
  from nemo.collections.nlp.parts.peft_config import PEFT_CONFIG_MAP, CanonicalAdaptersPEFTConfig, LoraPEFTConfig, PEFTConfig, PtuningPEFTConfig
  from nemo.core.classes.mixins.adapter_mixins import AdapterModuleMixin
  from nemo.core.connectors.save_restore_connector import SaveRestoreConnector
  from nemo.utils import logging, model_utils
label_desc: Use image node_id 17 for calling the NLPAdapterModelMixin obj's underlying member method code with example usage: obj.merge_cfg_with(cls, path, cfg) and returns: base_cfg