code: def test_invertible_adapter_with_head(self):
      if hasattr(
          ADAPTER_MODEL_MAPPING[self.config_class], "add_masked_lm_head"
      ):
          lm_head = "masked_lm"
      elif hasattr(
          ADAPTER_MODEL_MAPPING[self.config_class], "add_causal_lm_head"
      ):
          lm_head = "casual_lm"
      elif hasattr(
          ADAPTER_MODEL_MAPPING[self.config_class],
          "add_seq2seq_lm_head",
      ):
          lm_head = "seq2seq_lm"
      else:
          self.skipTest("No masked or causel language model head")
  
      model = AutoAdapterModel.from_config(self.config())
      model.add_adapter("test", config="seq_bn_inv")
      if lm_head == "casual_lm":
          model.add_causal_lm_head("test")
      elif lm_head == "masked_lm":
          model.add_masked_lm_head("test")
      elif lm_head == "seq2seq_lm":
          model.add_seq2seq_lm_head("test")
      else:
          raise RuntimeError(
              "{} is not a valid lm head".format(lm_head)
          )
      model.set_active_adapters("test")
  
      # Set a hook before the invertible adapter to make sure it's actually called twice:
      # Once after the embedding layer and once in the prediction head.
      calls = 0
  
      def forward_pre_hook(module, input):
          nonlocal calls
          calls += 1
  
      inv_adapter = model.base_model.get_invertible_adapter()
      self.assertIsNotNone(inv_adapter)
      inv_adapter.register_forward_pre_hook(forward_pre_hook)
  
      in_data = self.get_input_samples(
          (self.batch_size, self.seq_length), config=model.config
      )
      model.to(torch_device)
      out = model(**in_data)
  
      self.assertEqual(
          (self.batch_size, self.seq_length, model.config.vocab_size),
          out[0].shape,
      )
      self.assertEqual(2, calls)
  
imports: import os
  import tempfile
  import torch
  import adapters
  from adapters import ADAPTER_MODEL_MAPPING, AdapterSetup, AutoAdapterModel
  from adapters.composition import BatchSplit, Stack
  from transformers import AutoModelForSequenceClassification
  from transformers.testing_utils import require_torch, torch_device
  from .methods import create_twin_models
label_desc: Use image node_id 19 for calling the PredictionHeadModelTestMixin obj's underlying member method code with example usage: obj.test_invertible_adapter_with_head() without return types