docstr: Randomly initialize the peft params and add them to the appropriate modules.
docstr_tok: ["Randomly","initialize","the","peft","params","and","add","them","to","the","appropriate","modules","."]
code: def init_peft_modules(self):
      """
      Randomly initialize the peft params and add them to the appropriate modules.
      """
      assert (
          len(self.peft_name_keys) > 0
      ), "peft_name_keys have not been set no PEFT modules will be added"
      assert not self.mcore_gpt or hasattr(
          self, "name_key_to_mcore_mixins"
      ), f"{self.__class__.__name__} is not supported in megatron core mode yet."
      assert (
          len(self.name_key_to_cfg) > 0
      ), "name_key_to_cfg has not been set no PEFT modules will be added"
      logging.info(f"Before adding PEFT params:\n{self.summarize()}")
      if self.mcore_gpt:
          if self.cfg.megatron_amp_O2:
              layers = self.model.module.decoder.layers
          else:
              layers = self.model.decoder.layers
      else:
          if self.cfg.megatron_amp_O2:
              layers = self.model.module.language_model.encoder.layers
          else:
              layers = self.model.language_model.encoder.layers
      for layer in layers:
          if layer.layer_number in self.layer_selection:
              for name, module in layer.named_modules():
                  if self.mcore_gpt:
                      for peft_key in self.peft_name_keys:
                          for (
                              mcore_target,
                              mcore_mixin,
                          ) in self.name_key_to_mcore_mixins[peft_key]:
                              if name == mcore_target:
                                  swap_mcore_mixin(module, mcore_mixin)
                                  peft_cfg = self.name_key_to_cfg[
                                      peft_key
                                  ]
                                  if (
                                      model_utils.import_class_by_path(
                                          peft_cfg._target_
                                      )
                                      in module.get_accepted_adapter_types()
                                  ):
                                      module.add_adapter(
                                          name=peft_key,
                                          cfg=peft_cfg,
                                          model_parallel_config=self.model_parallel_config,
                                      )
                  else:
                      if isinstance(
                          module, adapter_mixins.AdapterModuleMixin
                      ):
                          for peft_key in self.peft_name_keys:
                              peft_cfg = self.name_key_to_cfg[peft_key]
                              if (
                                  model_utils.import_class_by_path(
                                      peft_cfg._target_
                                  )
                                  in module.get_accepted_adapter_types()
                              ):
                                  module.add_adapter(
                                      name=peft_key,
                                      cfg=peft_cfg,
                                      base_model_cfg=self.cfg,
                                      model_parallel_config=self.model_parallel_config,
                                  )
      logging.info(f"After adding PEFT params:\n{self.summarize()}")
      return True
  
imports: from omegaconf.dictconfig import DictConfig
  from pytorch_lightning.trainer.trainer import Trainer
  from nemo.collections.nlp.models.language_modeling.megatron_gpt_sft_model import MegatronGPTSFTModel
  from nemo.collections.nlp.modules.common.megatron.adapters.mcore_mixins import MCoreGPTEmbeddingMixin, MCoreSelfAttentionMixin, MCoreTransformerLayerMixin, swap_mcore_mixin
  from nemo.collections.nlp.modules.common.megatron.adapters.parallel_adapters import AdapterName, InfusedAdapterConfig, LoraKQVAdapterConfig, LoraKQVAdapterWeightTyingConfig, MLPInfusedAdapterConfig, ParallelLinearAdapterConfig, ParallelLinearAdapterWeightTyingConfig, PromptEncoderAdapterConfig
  from nemo.core.classes.mixins import adapter_mixins
  from nemo.utils import logging, model_utils
  from nemo.utils.decorators import deprecated
label_desc: Use image node_id 2 for calling the MegatronGPTLayerwisePEFTModel obj's underlying member method code with example usage: obj.init_peft_modules() and returns: True