class_docstr: A large testing suite for testing common functionality of the PEFT models.
  
  Attributes:
      torch_device (`torch.device`):
          The device on which the tests will be run.
      transformers_class (`transformers.PreTrainedModel`):
          The transformers class that is being tested.
class_docstr_tok: ["A","large","testing","suite","for","testing","common","functionality","of","the","PEFT","models",".","Attributes",":","torch_device","(","`","torch.device","`",")",":","The","device","on","which","the","tests","will","be","run",".","transformers_class","(","`","transformers.PreTrainedModel","`",")",":","The","transformers","class","that","is","being","tested","."]
code: def _test_weighted_combination_of_adapters(
      self, model_id, config_cls, config_kwargs
  ):
      if issubclass(config_cls, AdaLoraConfig):
          # AdaLora does not support adding more than 1 adapter
          return
  
      adapter_list = ["adapter1", "adapter_2", "adapter_3"]
      weight_list = [0.5, 1.5, 1.5]
      config = config_cls(
          base_model_name_or_path=model_id,
          **config_kwargs,
      )
      if not isinstance(config, (LoraConfig)):
          return
  
      model = self.transformers_class.from_pretrained(model_id)
      model = get_peft_model(model, config, adapter_list[0])
      model.add_adapter(adapter_list[1], config)
      model.add_adapter(adapter_list[2], replace(config, r=20))
      model = model.to(self.torch_device)
  
      # test re-weighting single adapter
      model.add_weighted_adapter(
          [adapter_list[0]],
          [weight_list[0]],
          "single_adapter_reweighting",
      )
  
      # test svd re-weighting with multiple adapters
      model.add_weighted_adapter(
          adapter_list[1:],
          weight_list[1:],
          "multi_adapter_svd_reweighting",
      )
  
      # test cat re-weighting with multiple adapters
      model.add_weighted_adapter(
          adapter_list[1:],
          weight_list[1:],
          "multi_adapter_cat_reweighting",
          combination_type="cat",
      )
  
      # test linear re-weighting with multiple adapters
      model.add_weighted_adapter(
          adapter_list[:2],
          weight_list[:2],
          "multi_adapter_linear_reweighting",
          combination_type="linear",
      )
  
      # test linear re-weighting with multiple adapters with only first adapter having non zero weight
      model.add_weighted_adapter(
          adapter_list[:2],
          [weight_list[0], 0],
          "multi_adapter_linear_reweighting_single_enabled",
          combination_type="linear",
      )
  
      with self.assertRaises(ValueError):
          model.add_weighted_adapter(
              adapter_list[1:],
              weight_list[1:],
              "multi_adapter_linear_reweighting_uneven_r",
              combination_type="linear",
          )
  
      new_adapters = [
          "single_adapter_reweighting",
          "multi_adapter_svd_reweighting",
          "multi_adapter_cat_reweighting",
          "multi_adapter_linear_reweighting",
          "multi_adapter_linear_reweighting_single_enabled",
      ]
      for new_adapter in new_adapters:
          self.assertTrue(new_adapter in model.peft_config)
  
      key_list = [key for key, _ in model.named_modules()]
      for key in key_list:
          _, target, _ = _get_submodules(model, key)
          if isinstance(target, LoraLayer):
              for adapter_name in new_adapters:
                  if "single" in adapter_name:
                      new_delta_weight = target.get_delta_weight(
                          adapter_name
                      )
                      weighted_original_delta_weights = (
                          target.get_delta_weight(adapter_list[0])
                          * weight_list[0]
                      )
                      self.assertTrue(
                          torch.allclose(
                              new_delta_weight,
                              weighted_original_delta_weights,
                              atol=1e-4,
                              rtol=1e-4,
                          )
                      )
                  elif "svd" in adapter_name:
                      self.assertTrue(target.r[adapter_name] == 20)
                  elif "linear" in adapter_name:
                      self.assertTrue(target.r[adapter_name] == 8)
                  elif "cat" in adapter_name:
                      self.assertTrue(target.r[adapter_name] == 28)
  
      dummy_input = self.prepare_inputs_for_testing()
      model.eval()
      for adapter_name in new_adapters:
          # ensuring new adapters pass the forward loop
          model.set_adapter(adapter_name)
          self.assertTrue(model.active_adapter == adapter_name)
          self.assertTrue(model.active_adapters == [adapter_name])
          model(**dummy_input)[0]
  
imports: import copy
  import json
  import os
  import pickle
  import re
  import tempfile
  from collections import OrderedDict
  from dataclasses import replace
  import torch
  import yaml
  from diffusers import StableDiffusionPipeline
  from peft import AdaLoraConfig, IA3Config, LoraConfig, PeftModel, PeftType, PrefixTuningConfig, PromptEncoderConfig, PromptLearningConfig, PromptTuningConfig, get_peft_model, get_peft_model_state_dict, prepare_model_for_int8_training
  from peft.tuners.lora import LoraLayer
  from peft.utils import _get_submodules, infer_device
  from .testing_utils import get_state_dict
label_desc: Use image node_id 26 for calling the PeftCommonTester obj's underlying member method code with example usage: obj._test_weighted_combination_of_adapters(model_id, config_cls, config_kwargs) without return types