class_docstr: Tests for the AdaptionPrompt model.
  
  Some of these tests were adapted from `test_peft_model.py` (which has been refactored since), but since we haven't
  checked in the test checkpoints for Llama into `hf-internal-testing`, we separate them for now.
class_docstr_tok: ["Tests","for","the","AdaptionPrompt","model",".","Some","of","these","tests","were","adapted","from","`","test_peft_model.py","`","(","which","has","been","refactored","since",")",",","but","since","we","haven't","checked","in","the","test","checkpoints","for","Llama","into","`","hf-internal-testing","`",",","we","separate","them","for","now","."]
docstr: Test that adding and setting adapters while disabled works as intended.
docstr_tok: ["Test","that","adding","and","setting","adapters","while","disabled","works","as","intended","."]
code: def test_add_and_set_while_disabled(self):
      """Test that adding and setting adapters while disabled works as intended."""
      # Test input data.
      input_ids = torch.LongTensor([[1, 1, 1], [2, 1, 2]]).to(
          self.torch_device
      )
      target_ids = torch.LongTensor([[0, 0, 0], [0, 0, 0]]).to(
          self.torch_device
      )
      attention_mask = torch.LongTensor([[1, 1, 1], [1, 0, 1]]).to(
          self.torch_device
      )
  
      # Create original llama model.
      original = LlamaForCausalLM(self._create_test_llama_config())
      original = original.to(self.torch_device)
      original_before = original(
          input_ids=input_ids, attention_mask=attention_mask
      )
  
      # Get AdaptionPrompt model.
      adapted = get_peft_model(
          original,
          AdaptionPromptConfig(
              adapter_layers=2, adapter_len=4, task_type="CAUSAL_LM"
          ),
      )
      adapted = adapted.to(self.torch_device)
  
      with adapted.disable_adapter():
          adapted.add_adapter(
              "adapter 1",
              AdaptionPromptConfig(
                  adapter_layers=3, adapter_len=8, task_type="CAUSAL_LM"
              ),
          )
  
      # Test that the output is the same as the original output.
      adapter_1_before = adapted(
          input_ids=input_ids,
          attention_mask=attention_mask,
          labels=target_ids,
      )
      assert_close(
          original_before.logits,
          adapter_1_before.logits,
          rtol=0,
          atol=0,
      )
  
      # Single fine-tuning step on adapter 1.
      optimizer = torch.optim.SGD(adapted.parameters(), lr=1)
      optimizer.zero_grad()
      adapter_1_before.loss.backward()
      optimizer.step()
  
      # Test that adapter 1 output changed.
      adapter_1_after = adapted(
          input_ids=input_ids,
          attention_mask=attention_mask,
          labels=target_ids,
      )
      self.assertFalse(
          torch.allclose(original_before.logits, adapter_1_after.logits)
      )
  
      adapted.set_adapter("default")
      with adapted.disable_adapter():
          adapted.set_adapter("adapter 1")
  
      # Test that adapter 1 is active again.
      adapter_1_after_set = adapted(
          input_ids=input_ids,
          attention_mask=attention_mask,
          labels=target_ids,
      )
      assert_close(
          adapter_1_after.logits,
          adapter_1_after_set.logits,
          rtol=0,
          atol=0,
      )
  
imports: import importlib
  import os
  import tempfile
  import unittest
  from unittest import TestCase
  import torch
  from torch.testing import assert_close
  from peft.mapping import get_peft_model
  from peft.peft_model import PeftModel
  from peft.tuners.adaption_prompt import AdaptionPromptConfig
  from peft.utils.other import prepare_model_for_int8_training
  from peft.utils.save_and_load import get_peft_model_state_dict
  from tests.testing_common import PeftCommonTester
label_desc: Use image node_id 11 for calling the AdaptionPromptTester obj's underlying member method code with example usage: obj.test_add_and_set_while_disabled() without return types