class_docstr: Here we also overwrite some of the tests of test_modeling_common.py, as CLIP does not use input_ids, inputs_embeds,
  attention_mask and seq_length.
class_docstr_tok: ["Here","we","also","overwrite","some","of","the","tests","of","test_modeling_common.py",",","as","CLIP","does","not","use","input_ids",",","inputs_embeds",",","attention_mask","and","seq_length","."]
code: def test_attention_outputs(self):
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      config.return_dict = True
  
      # in CLIP, the seq_len equals the number of patches + 1 (we add 1 for the [CLS] token)
      image_size = (
          self.model_tester.image_size,
          self.model_tester.image_size,
      )
      patch_size = (
          self.model_tester.patch_size,
          self.model_tester.patch_size,
      )
      num_patches = (image_size[1] // patch_size[1]) * (
          image_size[0] // patch_size[0]
      )
      seq_len = num_patches + 1
  
      for model_class in self.all_model_classes:
          inputs_dict["output_attentions"] = True
          inputs_dict["output_hidden_states"] = False
          config.return_dict = True
          model = model_class(config)
          outputs = model(
              **self._prepare_for_class(inputs_dict, model_class),
              training=False,
          )
          attentions = outputs.attentions
          self.assertEqual(
              len(attentions), self.model_tester.num_hidden_layers
          )
  
          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          config.output_attentions = True
          model = model_class(config)
          outputs = model(
              **self._prepare_for_class(inputs_dict, model_class),
              training=False,
          )
          attentions = outputs.attentions
          self.assertEqual(
              len(attentions), self.model_tester.num_hidden_layers
          )
  
          out_len = len(outputs)
  
          # Check attention is always last and order is fine
          inputs_dict["output_attentions"] = True
          inputs_dict["output_hidden_states"] = True
          model = model_class(config)
          outputs = model(
              **self._prepare_for_class(inputs_dict, model_class),
              training=False,
          )
  
          added_hidden_states = 1
          self.assertEqual(out_len + added_hidden_states, len(outputs))
  
          self_attentions = outputs.attentions
  
          self.assertEqual(
              len(self_attentions), self.model_tester.num_hidden_layers
          )
  
          self.assertListEqual(
              list(self_attentions[0].shape[-3:]),
              [self.model_tester.num_attention_heads, seq_len, seq_len],
          )
  
imports: import inspect
  import os
  import tempfile
  import unittest
  from importlib import import_module
  import requests
  from transformers import CLIPConfig, CLIPTextConfig, CLIPVisionConfig
  from transformers.testing_utils import require_tf, require_vision, slow
  from transformers.utils import is_tf_available, is_vision_available
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
label_desc: Use image node_id 8 for calling the TFCLIPVisionModelTest obj's underlying member method code with example usage: obj.test_attention_outputs() without return types