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: A test that checks if `enable_adapters` and `disable_adapters` methods work as expected.
docstr_tok: ["A","test","that","checks","if","`","enable_adapters","`","and","`","disable_adapters","`","methods","work","as","expected","."]
code: def test_peft_enable_disable_adapters(self):
      """
      A test that checks if `enable_adapters` and `disable_adapters` methods work as expected.
      """
      from peft import LoraConfig
  
      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:
              peft_model = transformers_class.from_pretrained(
                  model_id
              ).to(torch_device)
  
              peft_config = LoraConfig(init_lora_weights=False)
  
              peft_model.add_adapter(peft_config)
  
              peft_logits = peft_model(dummy_input).logits
  
              peft_model.disable_adapters()
  
              peft_logits_disabled = peft_model(dummy_input).logits
  
              peft_model.enable_adapters()
  
              peft_logits_enabled = peft_model(dummy_input).logits
  
              self.assertTrue(
                  torch.allclose(
                      peft_logits,
                      peft_logits_enabled,
                      atol=1e-12,
                      rtol=1e-12,
                  )
              )
              self.assertFalse(
                  torch.allclose(
                      peft_logits_enabled,
                      peft_logits_disabled,
                      atol=1e-12,
                      rtol=1e-12,
                  )
              )
  
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 5 for calling the PeftIntegrationTester obj's underlying member method code with example usage: obj.test_peft_enable_disable_adapters() without return types