code: def create_lora_adapter(
      model: torch.nn.Module,
      rank: int = 8,
      alpha: int = 8,
      dropout_rate: float = 0.0,
      target_modules: List[str] = ["query"],
      bias_type: str = "none",
  ):
      """Create LoRA adapter for the base model.
  
      See: https://arxiv.org/pdf/2106.09685.pdf
  
      Args:
          model (torch.nn.Module): Base model to be adapted.
          rank (int): Rank of LoRA matrices. Defaults to 8.
          alpha (int): Constant number for LoRA scaling. Defaults to 8.
          dropout_rate (float): Dropout probability for LoRA layers. Defaults to 0.0.
          target_modules (List[str]): List of module(s) to apply LoRA adaptation.
              e.g. ["query", "key", "value"] for all layers,
              while ["encoder.encoders.blocks.0.attn.key"] for a specific layer.
          bias_type (str): Bias training type for LoRA adaptaion, can be
              one of ["none", "all", "lora_only"].
              "none" means not training any bias vectors;
              "all" means training all bias vectors, include LayerNorm biases;
              "lora_only" means only training bias vectors in LoRA adapted modules.
  
      Returns:
          torch.nn.Module: The LoRA adapted model.
      """
      assert check_argument_types()
  
      if lora is None:
          raise RuntimeError(
              "Requiring loralib. Install loralib following: "
              "https://github.com/microsoft/LoRA"
          )
  
      is_traget_module_exists = False
      key_list = [key for key, _ in model.named_modules()]
  
      for key in key_list:
          if not check_target_module_exists(key, target_modules):
              continue
  
          is_traget_module_exists = True
  
          parent_module, target_name, target_module = get_submodules(
              model, key
          )
          if not isinstance(target_module, lora.LoRALayer):
              new_module = create_new_module(
                  target_module, rank, alpha, dropout_rate
              )
              replace_module(
                  parent_module, target_name, target_module, new_module
              )
          else:
              continue
  
      if not is_traget_module_exists:
          raise ValueError(
              f"Target modules {target_modules} not found in the base model."
          )
  
      lora.mark_only_lora_as_trainable(model, bias_type)
  
imports: from typing import List
  import torch
  from typeguard import check_argument_types
label_desc: Use image node_id 1 for calling a global function with example usage: create_lora_adapter(model, rank, alpha, dropout_rate, target_modules, bias_type) without return types