class_docstr: A base tuner model that provides the common methods and attributes for all tuners that are injectable into a
  torch.nn.Module
  
  For adding a new Tuner class, one needs to overwrite the following methods:
  
  - **_prepare_adapter_config**:
      A private method to eventually prepare the adapter config, for example in case the field `target_modules` is
      missing.
  - **_create_and_replace**:
      A private method to create and replace the target module with the adapter module.
  - **_check_target_module_exists**:
      A private helper method to check if the passed module's key name matches any of the target modules in the
      adatper_config.
  
  The easiest is to check what is done in the `peft.tuners.lora.LoraModel` class.
  
  Attributes:
      model (`torch.nn.Module`):
          The model to which the adapter tuner layers will be attached.
      forward (`Callable`):
          The forward method of the model.
      peft_config (`Union[`PeftConfig`, dict[str, PeftConfig]]`):
          The adapter configuration object, it should be a dictionary of `str` to `PeftConfig` objects. One can also
          pass a PeftConfig object and a new adapter will be created with the default name `adapter` or create a new
          dictionary with a key `adapter_name` and a value of that peft config.
      config (`dict[str, Any]`):
          The model configuration object, it should be a dictionary of `str` to `Any` objects.
      targeted_module_names (`list[str]`):
          The list of module names that were actually adapted. Can be useful to inspect if you want to quickly
          double-check that the `config.target_modules` where specified correctly.
class_docstr_tok: ["A","base","tuner","model","that","provides","the","common","methods","and","attributes","for","all","tuners","that","are","injectable","into","a","torch.nn.Module","For","adding","a","new","Tuner","class",",","one","needs","to","overwrite","the","following","methods",":","-","*","*","_prepare_adapter_config","*","*",":","A","private","method","to","eventually","prepare","the","adapter","config",",","for","example","in","case","the","field","`","target_modules","`","is","missing",".","-","*","*","_create_and_replace","*","*",":","A","private","method","to","create","and","replace","the","target","module","with","the","adapter","module",".","-","*","*","_check_target_module_exists","*","*",":","A","private","helper","method","to","check","if","the","passed","module","'s","key","name","matches","any","of","the","target","modules","in","the","adatper_config",".","The","easiest","is","to","check","what","is","done","in","the","`","peft.tuners.lora.LoraModel","`","class",".","Attributes",":","model","(","`","torch.nn.Module","`",")",":","The","model","to","which","the","adapter","tuner","layers","will","be","attached",".","forward","(","`","Callable","`",")",":","The","forward","method","of","the","model",".","peft_config","(","`","Union","[","`","PeftConfig","`",",","dict","[","str",",","PeftConfig","]","]","`",")",":","The","adapter","configuration","object",",","it","should","be","a","dictionary","of","`","str","`","to","`","PeftConfig","`","objects",".","One","can","also","pass","a","PeftConfig","object","and","a","new","adapter","will","be","created","with","the","default","name","`","adapter","`","or","create","a","new","dictionary","with","a","key","`","adapter_name","`","and","a","value","of","that","peft","config",".","config","(","`","dict","[","str",",","Any","]","`",")",":","The","model","configuration","object",",","it","should","be","a","dictionary","of","`","str","`","to","`","Any","`","objects",".","targeted_module_names","(","`","list","[","str","]","`",")",":","The","list","of","module","names","that","were","actually","adapted",".","Can","be","useful","to","inspect","if","you","want","to","quickly","double-check","that","the","`","config.target_modules","`","where","specified","correctly","."]
docstr: Inplace replacement of the target module with the adapter layer. This method needs to be overriden by all the
  tuner classes.
  
  Check `peft.tuners.lora.LoraModel._create_and_replace` for an example.
  
  Args:
      peft_config (`PeftConfig`):
          The adapter config.
      adapter_name (`str`):
          The adapter name.
      target (`nn.Module`):
          The target module.
      target_name (`str`):
          The target module's name.
      parent (`nn.Module`):
          The parent module.
      current_key (`str`):
          The key of the current target being adapted.
docstr_tok: ["Inplace","replacement","of","the","target","module","with","the","adapter","layer",".","This","method","needs","to","be","overriden","by","all","the","tuner","classes",".","Check","`","peft.tuners.lora.LoraModel._create_and_replace","`","for","an","example",".","Args",":","peft_config","(","`","PeftConfig","`",")",":","The","adapter","config",".","adapter_name","(","`","str","`",")",":","The","adapter","name",".","target","(","`","nn.Module","`",")",":","The","target","module",".","target_name","(","`","str","`",")",":","The","target","module","'s","name",".","parent","(","`","nn.Module","`",")",":","The","parent","module",".","current_key","(","`","str","`",")",":","The","key","of","the","current","target","being","adapted","."]
code: def _create_and_replace(
      self,
      peft_config: PeftConfig,
      adapter_name: str,
      target: nn.Module,
      target_name: str,
      parent: nn.Module,
      current_key: str,
  ) -> None:
      r"""
      Inplace replacement of the target module with the adapter layer. This method needs to be overriden by all the
      tuner classes.
  
      Check `peft.tuners.lora.LoraModel._create_and_replace` for an example.
  
      Args:
          peft_config (`PeftConfig`):
              The adapter config.
          adapter_name (`str`):
              The adapter name.
          target (`nn.Module`):
              The target module.
          target_name (`str`):
              The target module's name.
          parent (`nn.Module`):
              The parent module.
          current_key (`str`):
              The key of the current target being adapted.
      """
      ...
  
imports: from __future__ import annotations
  import logging
  import re
  import warnings
  from abc import ABC, abstractmethod
  from contextlib import contextmanager
  from typing import Any, List, Optional, Union
  import torch
  from accelerate.hooks import AlignDevicesHook
  from accelerate.utils import named_module_tensors, offload_state_dict
  from torch import nn
  from transformers import PreTrainedModel
  from transformers.pytorch_utils import Conv1D
  from peft.utils import INCLUDE_LINEAR_LAYERS_SHORTHAND
  from ..config import PeftConfig
  from ..utils import ModulesToSaveWrapper, _get_submodules
label_desc: Use image node_id 6 for calling the BaseTuner obj's underlying member method code with example usage: obj._create_and_replace(peft_config, adapter_name, target, target_name, parent, current_key) without return types