code: def test_attention_outputs(self):
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      config.return_dict = True
  
      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)
          )
          attentions = outputs.attentions
          expected_num_attentions = len(self.model_tester.depths)
          self.assertEqual(len(attentions), expected_num_attentions)
  
          # check that output_attentions also work using config
          del inputs_dict["output_attentions"]
          config.output_attentions = True
          window_size_squared = config.window_size**2
          model = model_class(config)
          outputs = model(
              **self._prepare_for_class(inputs_dict, model_class)
          )
          attentions = outputs.attentions
          self.assertEqual(len(attentions), expected_num_attentions)
  
          self.assertListEqual(
              list(attentions[0].shape[-3:]),
              [
                  self.model_tester.num_heads[0],
                  window_size_squared,
                  window_size_squared,
              ],
          )
          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)
          )
  
          if hasattr(self.model_tester, "num_hidden_states_types"):
              added_hidden_states = (
                  self.model_tester.num_hidden_states_types
              )
          else:
              # also another +1 for reshaped_hidden_states
              added_hidden_states = 2
          self.assertEqual(out_len + added_hidden_states, len(outputs))
  
          self_attentions = outputs.attentions
  
          self.assertEqual(
              len(self_attentions), expected_num_attentions
          )
  
          self.assertListEqual(
              list(self_attentions[0].shape[-3:]),
              [
                  self.model_tester.num_heads[0],
                  window_size_squared,
                  window_size_squared,
              ],
          )
  
imports: import inspect
  import unittest
  import numpy
  from transformers import SwinConfig
  from transformers.testing_utils import require_tf, require_vision, slow, to_2tuple, tooslow
  from transformers.utils import cached_property, is_tf_available, is_vision_available
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
label_desc: Use image node_id 11 for calling the TFSwinModelTest obj's underlying member method code with example usage: obj.test_attention_outputs() without return types