docstr: Internal function to create lokr adapter
  
  Args:
      adapter_name (`str`): Name for the adapter to add.
      r (`int`): Rank for the added adapter.
      alpha (`float`): Alpha for the added adapter.
      rank_dropout (`float`): The dropout probability for rank dimension during training
      module_dropout (`float`): The dropout probability for disabling adapter during training.
      init_weights (`bool`): Whether to initialize adapter weights.
      use_effective_conv2d (`bool`): Use parameter effective decomposition for Conv2d with ksize > 1.
      decompose_both (`bool`): Perform rank decomposition of left kronecker product matrix.
      decompose_factor (`int`): Kronecker product decomposition factor.
docstr_tok: ["Internal","function","to","create","lokr","adapter","Args",":","adapter_name","(","`","str","`",")",":","Name","for","the","adapter","to","add",".","r","(","`","int","`",")",":","Rank","for","the","added","adapter",".","alpha","(","`","float","`",")",":","Alpha","for","the","added","adapter",".","rank_dropout","(","`","float","`",")",":","The","dropout","probability","for","rank","dimension","during","training","module_dropout","(","`","float","`",")",":","The","dropout","probability","for","disabling","adapter","during","training",".","init_weights","(","`","bool","`",")",":","Whether","to","initialize","adapter","weights",".","use_effective_conv2d","(","`","bool","`",")",":","Use","parameter","effective","decomposition","for","Conv2d","with","ksize",">","1.","decompose_both","(","`","bool","`",")",":","Perform","rank","decomposition","of","left","kronecker","product","matrix",".","decompose_factor","(","`","int","`",")",":","Kronecker","product","decomposition","factor","."]
code: def update_layer(
      self,
      adapter_name: str,
      r: int,
      alpha: float,
      rank_dropout: float,
      module_dropout: float,
      init_weights: bool,
      use_effective_conv2d: bool,
      decompose_both: bool,
      decompose_factor: int,
      **kwargs,
  ) -> None:
      """Internal function to create lokr adapter
  
      Args:
          adapter_name (`str`): Name for the adapter to add.
          r (`int`): Rank for the added adapter.
          alpha (`float`): Alpha for the added adapter.
          rank_dropout (`float`): The dropout probability for rank dimension during training
          module_dropout (`float`): The dropout probability for disabling adapter during training.
          init_weights (`bool`): Whether to initialize adapter weights.
          use_effective_conv2d (`bool`): Use parameter effective decomposition for Conv2d with ksize > 1.
          decompose_both (`bool`): Perform rank decomposition of left kronecker product matrix.
          decompose_factor (`int`): Kronecker product decomposition factor.
      """
      if r <= 0:
          raise ValueError(
              f"`r` should be a positive integer value but the value passed is {r}"
          )
  
      self.r[adapter_name] = r
      self.alpha[adapter_name] = alpha
      self.scaling[adapter_name] = alpha / r
      self.rank_dropout[adapter_name] = rank_dropout
      self.module_dropout[adapter_name] = module_dropout
      base_layer = self.get_base_layer()
  
      # Determine shape of LoKr weights
      if isinstance(base_layer, nn.Linear):
          in_dim, out_dim = (
              base_layer.in_features,
              base_layer.out_features,
          )
  
          in_m, in_n = factorization(in_dim, decompose_factor)
          out_l, out_k = factorization(out_dim, decompose_factor)
          shape = (
              (out_l, out_k),
              (in_m, in_n),
          )  # ((a, b), (c, d)), out_dim = a*c, in_dim = b*d
  
          use_w1 = not (
              decompose_both and r < max(shape[0][0], shape[1][0]) / 2
          )
          use_w2 = not (r < max(shape[0][1], shape[1][1]) / 2)
          use_effective_conv2d = False
      elif isinstance(base_layer, nn.Conv2d):
          in_dim, out_dim = (
              base_layer.in_channels,
              base_layer.out_channels,
          )
          k_size = base_layer.kernel_size
  
          in_m, in_n = factorization(in_dim, decompose_factor)
          out_l, out_k = factorization(out_dim, decompose_factor)
          shape = (
              (out_l, out_k),
              (in_m, in_n),
              *k_size,
          )  # ((a, b), (c, d), *k_size)
  
          use_w1 = not (
              decompose_both and r < max(shape[0][0], shape[1][0]) / 2
          )
          use_w2 = r >= max(shape[0][1], shape[1][1]) / 2
          use_effective_conv2d = (
              use_effective_conv2d and base_layer.kernel_size != (1, 1)
          )
      else:
          raise TypeError(
              f"LoKr is not implemented for base layers of type {type(base_layer).__name__}"
          )
  
      # Create weights with provided shape
      self.create_adapter_parameters(
          adapter_name, r, shape, use_w1, use_w2, use_effective_conv2d
      )
  
      # Initialize weights
      if init_weights:
          self.reset_adapter_parameters(adapter_name)
      else:
          self.reset_adapter_parameters_random(adapter_name)
  
      # Move new weights to device
      weight = getattr(self.get_base_layer(), "weight", None)
      if weight is not None:
          # the layer is already completely initialized, this is an update
          if weight.dtype.is_floating_point or weight.dtype.is_complex:
              self.to(weight.device, dtype=weight.dtype)
          else:
              self.to(weight.device)
      self.set_adapter(self.active_adapters)
  
imports: import math
  from typing import Any, Optional, Set, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from peft.tuners.lycoris_utils import LycorisLayer
label_desc: Use image node_id 6 for calling the LoKrLayer obj's underlying member method code with example usage: obj.update_layer(adapter_name, r, alpha, rank_dropout, module_dropout, init_weights, use_effective_conv2d, decompose_both, decompose_factor) without return types