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_merge_layers_nan(self, model_id, config_cls, config_kwargs):
      if config_cls not in (LoraConfig, IA3Config, AdaLoraConfig):
          # Merge layers only supported for LoRA and IA³
          return
      if ("gpt2" in model_id.lower()) and (config_cls != LoraConfig):
          self.skipTest(
              "Merging GPT2 adapters not supported for IA³ (yet)"
          )
  
      model = self.transformers_class.from_pretrained(model_id)
      config = config_cls(
          base_model_name_or_path=model_id,
          **config_kwargs,
      )
      model = get_peft_model(model, config)
      model = model.to(self.torch_device)
  
      dummy_input = self.prepare_inputs_for_testing()
  
      model.eval()
  
      # This should work
      logits_unmerged = model(**dummy_input)[0]
  
      model = model.merge_and_unload()
      logits_merged = model(**dummy_input)[0]
  
      self.assertTrue(
          torch.allclose(
              logits_unmerged, logits_merged, atol=1e-3, rtol=1e-3
          )
      )
  
      model = self.transformers_class.from_pretrained(model_id)
      config = config_cls(
          base_model_name_or_path=model_id,
          **config_kwargs,
      )
      model = get_peft_model(model, config)
      model = model.to(self.torch_device)
  
      for name, module in model.named_parameters():
          if (
              "lora_A" in name
              or "ia3" in name
              or "lora_E" in name
              or "lora_B" in name
          ):
              module.data[0] = torch.nan
  
      with self.assertRaises(ValueError) as error_context:
          model = model.merge_and_unload(safe_merge=True)
  
      self.assertEqual(
          str(error_context.exception),
          "NaNs detected in the merged weights. The adapter default seems to be broken",
      )
  
      for name, module in model.named_parameters():
          if (
              "lora_A" in name
              or "ia3" in name
              or "lora_E" in name
              or "lora_B" in name
          ):
              module.data[0] = torch.inf
  
      with self.assertRaises(ValueError) as error_context:
          model = model.merge_and_unload(safe_merge=True)
  
      self.assertEqual(
          str(error_context.exception),
          "NaNs detected in the merged weights. The adapter default seems to be broken",
      )
  
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 11 for calling the PeftCommonTester obj's underlying member method code with example usage: obj._test_merge_layers_nan(model_id, config_cls, config_kwargs) without return types