class_docstr: A testing suite that makes sure that the PeftModel class is correctly integrated into the transformers library.
class_docstr_tok: ["A","testing","suite","that","makes","sure","that","the","PeftModel","class","is","correctly","integrated","into","the","transformers","library","."]
docstr: Simple test that tests the basic usage of PEFT model through `from_pretrained`. This test tests if
  add_adapter works as expected in multi-adapter setting.
docstr_tok: ["Simple","test","that","tests","the","basic","usage","of","PEFT","model","through","`","from_pretrained","`",".","This","test","tests","if","add_adapter","works","as","expected","in","multi-adapter","setting","."]
code: def test_peft_add_multi_adapter(self):
      """
      Simple test that tests the basic usage of PEFT model through `from_pretrained`. This test tests if
      add_adapter works as expected in multi-adapter setting.
      """
      from peft import LoraConfig
      from peft.tuners.tuners_utils import BaseTunerLayer
  
      dummy_input = torch.LongTensor([[0, 1, 2, 3, 4, 5, 6, 7]]).to(
          torch_device
      )
  
      for model_id in self.transformers_test_model_ids:
          for (
              transformers_class
          ) in self.transformers_test_model_classes:
              is_peft_loaded = False
              model = transformers_class.from_pretrained(model_id).to(
                  torch_device
              )
  
              logits_original_model = model(dummy_input).logits
  
              peft_config = LoraConfig(init_lora_weights=False)
  
              model.add_adapter(peft_config)
  
              logits_adapter_1 = model(dummy_input)
  
              model.add_adapter(peft_config, adapter_name="adapter-2")
  
              logits_adapter_2 = model(dummy_input)
  
              for _, m in model.named_modules():
                  if isinstance(m, BaseTunerLayer):
                      is_peft_loaded = True
                      break
  
              self.assertTrue(is_peft_loaded)
  
              # dummy generation
              _ = model.generate(input_ids=dummy_input)
  
              model.set_adapter("default")
              self.assertTrue(model.active_adapters() == ["default"])
              self.assertTrue(model.active_adapter() == "default")
  
              model.set_adapter("adapter-2")
              self.assertTrue(model.active_adapters() == ["adapter-2"])
              self.assertTrue(model.active_adapter() == "adapter-2")
  
              # Logits comparison
              self.assertFalse(
                  torch.allclose(
                      logits_adapter_1.logits,
                      logits_adapter_2.logits,
                      atol=1e-6,
                      rtol=1e-6,
                  )
              )
              self.assertFalse(
                  torch.allclose(
                      logits_original_model,
                      logits_adapter_2.logits,
                      atol=1e-6,
                      rtol=1e-6,
                  )
              )
  
              model.set_adapter(["adapter-2", "default"])
              self.assertTrue(
                  model.active_adapters() == ["adapter-2", "default"]
              )
              self.assertTrue(model.active_adapter() == "adapter-2")
  
              logits_adapter_mixed = model(dummy_input)
              self.assertFalse(
                  torch.allclose(
                      logits_adapter_1.logits,
                      logits_adapter_mixed.logits,
                      atol=1e-6,
                      rtol=1e-6,
                  )
              )
  
              self.assertFalse(
                  torch.allclose(
                      logits_adapter_2.logits,
                      logits_adapter_mixed.logits,
                      atol=1e-6,
                      rtol=1e-6,
                  )
              )
  
              # multi active adapter saving not supported
              with self.assertRaises(
                  ValueError
              ), tempfile.TemporaryDirectory() as tmpdirname:
                  model.save_pretrained(tmpdirname)
  
imports: import os
  import tempfile
  import unittest
  from huggingface_hub import hf_hub_download
  from transformers import AutoModelForCausalLM, OPTForCausalLM
  from transformers.testing_utils import require_peft, require_torch, require_torch_gpu, slow, torch_device
  from transformers.utils import is_torch_available
label_desc: Use image node_id 10 for calling the PeftIntegrationTester obj's underlying member method code with example usage: obj.test_peft_add_multi_adapter() without return types