code: def test_attention_outputs(self):
      (
          config,
          inputs_dict,
      ) = self.model_tester.prepare_config_and_inputs_for_common()
      inputs_dict["global_attention_mask"] = tf.zeros_like(
          inputs_dict["attention_mask"]
      )
      num_global_attn_indices = 2
      inputs_dict["global_attention_mask"] = tf.where(
          tf.range(self.model_tester.seq_length)[None, :]
          < num_global_attn_indices,
          1,
          inputs_dict["global_attention_mask"],
      )
  
      config.return_dict = True
      seq_length = self.model_tester.seq_length
      encoder_seq_length = self.model_tester.encoder_seq_length
  
      def check_decoder_attentions_output(outputs):
          decoder_attentions = outputs.decoder_attentions
          self.assertEqual(
              len(decoder_attentions),
              self.model_tester.num_hidden_layers,
          )
          self.assertListEqual(
              list(decoder_attentions[0].shape[-3:]),
              [
                  self.model_tester.num_attention_heads,
                  seq_length,
                  seq_length,
              ],
          )
  
      def check_encoder_attentions_output(outputs):
          attentions = [t.numpy() for t in outputs.encoder_attentions]
          global_attentions = [
              t.numpy() for t in outputs.encoder_global_attentions
          ]
          self.assertEqual(
              len(attentions), self.model_tester.num_hidden_layers
          )
          self.assertEqual(
              len(global_attentions),
              self.model_tester.num_hidden_layers,
          )
          self.assertListEqual(
              list(attentions[0].shape[-3:]),
              [
                  self.model_tester.num_attention_heads,
                  seq_length,
                  seq_length,
              ],
          )
          self.assertListEqual(
              list(global_attentions[0].shape[-3:]),
              [
                  self.model_tester.num_attention_heads,
                  encoder_seq_length,
                  num_global_attn_indices,
              ],
          )
  
      for model_class in self.all_model_classes:
          inputs_dict["output_attentions"] = True
          inputs_dict["use_cache"] = False
          config.output_hidden_states = False
          model = model_class(config)
          outputs = model(
              self._prepare_for_class(inputs_dict, model_class)
          )
          out_len = len(outputs)
          self.assertEqual(config.output_hidden_states, False)
          check_encoder_attentions_output(outputs)
  
          if self.is_encoder_decoder:
              model = model_class(config)
              outputs = model(
                  self._prepare_for_class(inputs_dict, model_class)
              )
              self.assertEqual(config.output_hidden_states, False)
              check_decoder_attentions_output(outputs)
  
          # Check that output attentions can also be changed via the config
          del inputs_dict["output_attentions"]
          config.output_attentions = True
          model = model_class(config)
          outputs = model(
              self._prepare_for_class(inputs_dict, model_class)
          )
          self.assertEqual(config.output_hidden_states, False)
          check_encoder_attentions_output(outputs)
  
          # Check attention is always last and order is fine
          inputs_dict["output_attentions"] = True
          config.output_hidden_states = True
          model = model_class(config)
          outputs = model(
              self._prepare_for_class(inputs_dict, model_class)
          )
  
          self.assertEqual(
              out_len + (2 if self.is_encoder_decoder else 1),
              len(outputs),
          )
          self.assertEqual(model.config.output_hidden_states, True)
          check_encoder_attentions_output(outputs)
  
imports: import unittest
  from transformers import LEDConfig, is_tf_available
  from transformers.testing_utils import require_tf, slow, tooslow
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor
label_desc: Use image node_id 5 for calling the TFLEDModelTest obj's underlying member method code with example usage: obj.test_attention_outputs() without return types