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: Generate a configuration dictionary by a given configuration dictionary `cfg` with
  the configuration dictionary obtained from restoring a MegatronGPTSFTModel or MegatronT5SFTModel
  at the specified `path` and modify `cfg` for inference
  
  Args:
      path (str): The path to the SFT model checkpoint to be restored.
      cfg (DictConfig): The configuration dictionary to modify for inference.
  
  Returns:
      DictConfig: The configuration dictionary for inference.
  
  Examples:
      >>> path = "/path/to/model/checkpoint"
      >>> cfg = DictConfig({"model": {"key": "value"}, "trainer": {"precision": 16}})
      >>> merged_cfg = merge_inference_cfg(path, cfg)
  
  Notes:
      - "precision" and "test_ds" from `cfg` will override the corresponding keys in the output dictionary
      - "activations_checkpoint" will be ovrrided to None in the output dictionary
      - "use_flash_attention" will be True if in one of the configuration dictionarys is True
      - "seq_len_interpolation_factor" will be overrided from `cfg` if it's not None from checkpoint
docstr_tok: ["Generate","a","configuration","dictionary","by","a","given","configuration","dictionary","`","cfg","`","with","the","configuration","dictionary","obtained","from","restoring","a","MegatronGPTSFTModel","or","MegatronT5SFTModel","at","the","specified","`","path","`","and","modify","`","cfg","`","for","inference","Args",":","path","(","str",")",":","The","path","to","the","SFT","model","checkpoint","to","be","restored",".","cfg","(","DictConfig",")",":","The","configuration","dictionary","to","modify","for","inference",".","Returns",":","DictConfig",":","The","configuration","dictionary","for","inference",".","Examples",":",">",">",">","path","=","``","\/path\/to\/model\/checkpoint","''",">",">",">","cfg","=","DictConfig","(","{","``","model","''",":","{","``","key","''",":","``","value","''","}",",","``","trainer","''",":","{","``","precision","''",":","16","}","}",")",">",">",">","merged_cfg","=","merge_inference_cfg","(","path",",","cfg",")","Notes",":","-","``","precision","''","and","``","test_ds","''","from","`","cfg","`","will","override","the","corresponding","keys","in","the","output","dictionary","-","``","activations_checkpoint","''","will","be","ovrrided","to","None","in","the","output","dictionary","-","``","use_flash_attention","''","will","be","True","if","in","one","of","the","configuration","dictionarys","is","True","-","``","seq_len_interpolation_factor","''","will","be","overrided","from","`","cfg","`","if","it","'s","not","None","from","checkpoint"]
code: def merge_inference_cfg(
      cls, path: str, cfg: DictConfig
  ) -> DictConfig:
      """
      Generate a configuration dictionary by a given configuration dictionary `cfg` with
      the configuration dictionary obtained from restoring a MegatronGPTSFTModel or MegatronT5SFTModel
      at the specified `path` and modify `cfg` for inference
  
      Args:
          path (str): The path to the SFT model checkpoint to be restored.
          cfg (DictConfig): The configuration dictionary to modify for inference.
  
      Returns:
          DictConfig: The configuration dictionary for inference.
  
      Examples:
          >>> path = "/path/to/model/checkpoint"
          >>> cfg = DictConfig({"model": {"key": "value"}, "trainer": {"precision": 16}})
          >>> merged_cfg = merge_inference_cfg(path, cfg)
  
      Notes:
          - "precision" and "test_ds" from `cfg` will override the corresponding keys in the output dictionary
          - "activations_checkpoint" will be ovrrided to None in the output dictionary
          - "use_flash_attention" will be True if in one of the configuration dictionarys is True
          - "seq_len_interpolation_factor" will be overrided from `cfg` if it's not None from checkpoint
      """
  
      peft_cfg = cls.restore_from(path, return_config=True)
      with open_dict(peft_cfg):
          # update the model config of the trained model with params we want to set at inference time.
          peft_cfg.precision = cfg.trainer.precision
          for key, val in cfg.model.items():
              if key != "data":
                  peft_cfg[key] = val
          peft_cfg.data.test_ds = cfg.model.data.test_ds
  
      with open_dict(cfg):
          cfg.inference.add_BOS = peft_cfg.data.test_ds.add_bos
          cfg.inference.tokens_to_generate = (
              peft_cfg.data.test_ds.tokens_to_generate
          )
  
      return peft_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 18 for calling the NLPAdapterModelMixin obj's underlying member method code with example usage: obj.merge_inference_cfg(cls, path, cfg) and returns: peft_cfg