class_docstr: Creates AdaLoRA (Adaptive LoRA) model from a pretrained transformers model. Paper:
  https://openreview.net/forum?id=lq62uWRJjiY
  
  Args:
      model ([`transformers.PreTrainedModel`]): The model to be adapted.
      config ([`AdaLoraConfig`]): The configuration of the AdaLora model.
      adapter_name (`str`): The name of the adapter, defaults to `"default"`.
  
  Returns:
      `torch.nn.Module`: The AdaLora model.
  
  Example::
  
      >>> from transformers import AutoModelForSeq2SeqLM, LoraConfig >>> from peft import AdaLoraModel, AdaLoraConfig
      >>> config = AdaLoraConfig(
              peft_type="ADALORA", task_type="SEQ_2_SEQ_LM", r=8, lora_alpha=32, target_modules=["q", "v"],
              lora_dropout=0.01,
          )
      >>> model = AutoModelForSeq2SeqLM.from_pretrained("t5-base") >>> model = AdaLoraModel(model, config, "default")
  
  **Attributes**:
      - **model** ([`transformers.PreTrainedModel`]) -- The model to be adapted.
      - **peft_config** ([`AdaLoraConfig`]): The configuration of the AdaLora model.
class_docstr_tok: ["Creates","AdaLoRA","(","Adaptive","LoRA",")","model","from","a","pretrained","transformers","model",".","Paper",":","https",":","\/\/openreview.net\/forum","?","id=lq62uWRJjiY","Args",":","model","(","[","`","transformers.PreTrainedModel","`","]",")",":","The","model","to","be","adapted",".","config","(","[","`","AdaLoraConfig","`","]",")",":","The","configuration","of","the","AdaLora","model",".","adapter_name","(","`","str","`",")",":","The","name","of","the","adapter",",","defaults","to","`","``","default","''","`",".","Returns",":","`","torch.nn.Module","`",":","The","AdaLora","model",".","Example",":",":",">",">",">","from","transformers","import","AutoModelForSeq2SeqLM",",","LoraConfig",">",">",">","from","peft","import","AdaLoraModel",",","AdaLoraConfig",">",">",">","config","=","AdaLoraConfig","(","peft_type=","''","ADALORA","''",",","task_type=","''","SEQ_2_SEQ_LM","''",",","r=8",",","lora_alpha=32",",","target_modules=","[","``","q","''",",","``","v","''","]",",","lora_dropout=0.01",",",")",">",">",">","model","=","AutoModelForSeq2SeqLM.from_pretrained","(","``","t5-base","''",")",">",">",">","model","=","AdaLoraModel","(","model",",","config",",","``","default","''",")","*","*","Attributes","*","*",":","-","*","*","model","*","*","(","[","`","transformers.PreTrainedModel","`","]",")","--","The","model","to","be","adapted",".","-","*","*","peft_config","*","*","(","[","`","AdaLoraConfig","`","]",")",":","The","configuration","of","the","AdaLora","model","."]
code: def _create_and_replace(
      self,
      lora_config,
      adapter_name,
      target,
      target_name,
      parent,
      current_key,
  ):
      kwargs = {
          "r": lora_config.init_r,
          "lora_alpha": lora_config.lora_alpha,
          "lora_dropout": lora_config.lora_dropout,
          "fan_in_fan_out": lora_config.fan_in_fan_out,
          "init_lora_weights": lora_config.init_lora_weights,
          "loaded_in_8bit": getattr(
              self.model, "is_loaded_in_8bit", False
          ),
          "loaded_in_4bit": getattr(
              self.model, "is_loaded_in_4bit", False
          ),
      }
      if (
          kwargs["loaded_in_8bit"] or kwargs["loaded_in_4bit"]
      ) and not is_bnb_available():
          raise ImportError(
              "To use AdaLora with 8-bit quantization, please install the `bitsandbytes` package. "
              "You can install it with `pip install bitsandbytes`."
          )
  
      quantization_config = get_quantization_config(
          self.model, method="gptq"
      )
      if quantization_config is not None:
          kwargs["gptq_quantization_config"] = quantization_config
  
      # If it is not an AdaLoraLayer, create a new module, else update it with new adapters
      if not isinstance(target, AdaLoraLayer):
          new_module = self._create_new_module(
              lora_config, adapter_name, target, **kwargs
          )
          if adapter_name != self.active_adapter:
              # adding an additional adapter: it is not automatically trainable
              new_module.requires_grad_(False)
          self._replace_module(parent, target_name, new_module, target)
      else:
          target.update_layer(
              adapter_name,
              lora_config.init_r,
              lora_config.lora_alpha,
              lora_config.lora_dropout,
              lora_config.init_lora_weights,
          )
  
imports: import warnings
  import torch
  from transformers.pytorch_utils import Conv1D
  from peft.import_utils import is_bnb_4bit_available, is_bnb_available
  from peft.tuners.lora import LoraConfig, LoraModel
  from peft.tuners.tuners_utils import BaseTunerLayer
  from peft.utils import TRANSFORMERS_MODELS_TO_ADALORA_TARGET_MODULES_MAPPING, _freeze_adapter, _get_submodules, get_auto_gptq_quant_linear, get_quantization_config
  from .gptq import SVDQuantLinear
  from .layer import AdaLoraLayer, RankAllocator, SVDLinear
label_desc: Use image node_id 3 for calling the AdaLoraModel obj's underlying member method code with example usage: obj._create_and_replace(lora_config, adapter_name, target, target_name, parent, current_key) without return types