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._available_adapters:
              base_layer = self.get_base_layer()
  
              orig_weights = base_layer.weight.data
              if isinstance(base_layer, nn.Linear):
                  orig_weights = torch.transpose(orig_weights, 0, 1)
              elif isinstance(base_layer, nn.Conv2d):
                  orig_weights = orig_weights.view(
                      [
                          base_layer.out_channels,
                          base_layer.in_channels
                          * base_layer.kernel_size[0]
                          * base_layer.kernel_size[1],
                      ]
                  )
                  orig_weights = torch.transpose(orig_weights, 0, 1)
              delta_weight = self.get_delta_weight(active_adapter)
              if orig_weights.shape[1] != delta_weight.shape[1]:
                  # when in channels is not divisible by r
                  delta_weight = delta_weight[
                      : orig_weights.shape[1], : orig_weights.shape[1]
                  ]
              new_weights = torch.mm(orig_weights, delta_weight)
              if isinstance(base_layer, nn.Linear):
                  new_weights = torch.transpose(new_weights, 0, 1)
              elif isinstance(base_layer, nn.Conv2d):
                  new_weights = torch.transpose(new_weights, 0, 1)
                  new_weights = new_weights.view(
                      [
                          base_layer.out_channels,
                          base_layer.in_channels,
                          base_layer.kernel_size[0],
                          base_layer.kernel_size[1],
                      ]
                  )
  
              if safe_merge and not torch.isfinite(new_weights).all():
                  raise ValueError(
                      f"NaNs detected in the merged weights. The adapter {active_adapter} seems to be broken"
                  )
  
              base_layer.weight.data = new_weights
              self.merged_adapters.append(active_adapter)
  
imports: import math
  import warnings
  from typing import Any, List, Optional, Set, Tuple
  import torch
  import torch.nn
  from peft.tuners.lycoris_utils import LycorisLayer
label_desc: Use image node_id 8 for calling the OFTLayer obj's underlying member method code with example usage: obj.merge(safe_merge, adapter_names) without return types