docstr: Merge the active adapter weights into the base weights
  
  Args:
      safe_merge (`bool`, *optional*):
          If True, the merge operation will be performed in a copy of the original weights and check for NaNs
          before merging the weights. This is useful if you want to check if the merge operation will produce
          NaNs. Defaults to `False`.
      adapter_names (`List[str]`, *optional*):
          The list of adapter names that should be merged. If None, all active adapters will be merged. Defaults
          to `None`.
docstr_tok: ["Merge","the","active","adapter","weights","into","the","base","weights","Args",":","safe_merge","(","`","bool","`",",","*","optional","*",")",":","If","True",",","the","merge","operation","will","be","performed","in","a","copy","of","the","original","weights","and","check","for","NaNs","before","merging","the","weights",".","This","is","useful","if","you","want","to","check","if","the","merge","operation","will","produce","NaNs",".","Defaults","to","`","False","`",".","adapter_names","(","`","List","[","str","]","`",",","*","optional","*",")",":","The","list","of","adapter","names","that","should","be","merged",".","If","None",",","all","active","adapters","will","be","merged",".","Defaults","to","`","None","`","."]
code: def merge(
      self,
      safe_merge: bool = False,
      adapter_names: Optional[List[str]] = None,
  ) -> None:
      """
      Merge the active adapter weights into the base weights
  
      Args:
          safe_merge (`bool`, *optional*):
              If True, the merge operation will be performed in a copy of the original weights and check for NaNs
              before merging the weights. This is useful if you want to check if the merge operation will produce
              NaNs. Defaults to `False`.
          adapter_names (`List[str]`, *optional*):
              The list of adapter names that should be merged. If None, all active adapters will be merged. Defaults
              to `None`.
      """
      if self.merged:
          warnings.warn(
              f"Already following adapters were merged {','.join(self.merged_adapters)}. "
              f"You are now additionally merging {','.join(self.active_adapters)}."
          )
  
      if adapter_names is None:
          adapter_names = self.active_adapters
  
      for active_adapter in adapter_names:
          if active_adapter in self.ia3_l.keys():
              base_layer = self.get_base_layer()
              ia3_l = transpose(
                  self.ia3_l[active_adapter].data, self.fan_in_fan_out
              )
              if safe_merge:
                  orig_weights = base_layer.weight.data
                  orig_weights = torch.mul(orig_weights, ia3_l)
  
                  if not torch.isfinite(orig_weights).all():
                      raise ValueError(
                          f"NaNs detected in the merged weights. The adapter {active_adapter} seems to be broken"
                      )
                  base_layer.weight.data = orig_weights
              else:
                  base_layer.weight.data = torch.mul(
                      base_layer.weight.data, ia3_l
                  )
  
              if not self.is_feedforward and (
                  base_layer.bias is not None
              ):
                  scaling = self.ia3_l[active_adapter].reshape(
                      base_layer.bias.shape
                  )
                  base_layer.bias.data = torch.mul(
                      base_layer.bias.data, scaling.data
                  )
  
              self.merged_adapters.append(active_adapter)
  
imports: import warnings
  from typing import Any, List, Optional
  import torch
  import torch.nn
  from transformers.pytorch_utils import Conv1D
  from peft.tuners.tuners_utils import BaseTunerLayer
  from peft.utils import transpose
label_desc: Use image node_id 2 for calling the Linear obj's underlying member method code with example usage: obj.merge(safe_merge, adapter_names) without return types