code: def run_test(self, static_model, input_shape=None, label_dict=None):
      flex_model = AutoAdapterModel.from_pretrained(
          None,
          config=self.config(),
          state_dict=static_model.state_dict(),
      )
      static_model.eval()
      flex_model.eval()
      if (
          static_model.base_model.__class__.__name__
          != flex_model.base_model.__class__.__name__
          and not static_model.base_model == static_model
      ):
          self.skipTest("Skipping as base model classes are different.")
  
      with tempfile.TemporaryDirectory() as temp_dir:
          static_model.save_head(temp_dir)
  
          loading_info = {}
          flex_model.load_head(
              temp_dir, load_as="test", loading_info=loading_info
          )
  
      self.assertEqual(
          0,
          len(loading_info["missing_keys"]),
          "Missing keys: {}".format(
              ", ".join(loading_info["missing_keys"])
          ),
      )
      # We don't need to convert some of the weights, so remove them for the check
      unexpected_keys = loading_info["unexpected_keys"]
      if static_model._keys_to_ignore_on_load_missing is not None:
          for pat in static_model._keys_to_ignore_on_load_missing:
              unexpected_keys = [
                  k
                  for k in unexpected_keys
                  if re.search(pat, k) is None
              ]
      # HACK for bert-based models
      if isinstance(static_model, BertPreTrainedModel):
          unexpected_keys = [
              k
              for k in unexpected_keys
              if "cls.predictions.bias" not in k
          ]
      elif (
          isinstance(static_model, RobertaPreTrainedModel)
          or isinstance(static_model, XLMRobertaPreTrainedModel)
          or isinstance(static_model, XmodPreTrainedModel)
      ):
          unexpected_keys = [
              k for k in unexpected_keys if "lm_head.bias" not in k
          ]
      elif isinstance(static_model, AlbertPreTrainedModel):
          unexpected_keys = [
              k for k in unexpected_keys if "predictions.bias" not in k
          ]
      self.assertEqual(
          0,
          len(unexpected_keys),
          "Unexpected keys: {}".format(", ".join(unexpected_keys)),
      )
  
      # adapter and head were loaded
      self.assertIn("test", flex_model.heads)
  
      # check equal output
      input_shape = input_shape or (self.batch_size, self.seq_length)
      in_data = self.get_input_samples(
          input_shape, config=flex_model.config
      )
      if label_dict:
          for k, v in label_dict.items():
              in_data[k] = v
      static_model.to(torch_device)
      flex_model.to(torch_device)
      output1 = static_model(**in_data)
      output2 = flex_model(**in_data)
      self.assertTrue(torch.allclose(output1.loss, output2.loss))
      self.assertTrue(torch.allclose(output1[1], output2[1]))
  
file_path: adapters/tests/test_adapter_conversion.py
imports: import inspect
  import re
  import tempfile
  import torch
  import adapters
  from adapters import AutoAdapterModel
  from transformers import MODEL_FOR_CAUSAL_LM_MAPPING, MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING, MODEL_FOR_MASKED_LM_MAPPING, MODEL_FOR_MULTIPLE_CHOICE_MAPPING, MODEL_FOR_QUESTION_ANSWERING_MAPPING, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING, MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING, AlbertPreTrainedModel, BertPreTrainedModel, RobertaPreTrainedModel, XLMRobertaPreTrainedModel, XmodPreTrainedModel
  from transformers.testing_utils import require_torch, torch_device
label_desc: Use image node_id 1 for calling the ModelClassConversionTestMixin obj's underlying member method code with example usage: obj.run_test(static_model, input_shape, label_dict) without return types