code: def test_layer_global_attn(self):
      model = TFLongformerModel.from_pretrained(
          "patrickvonplaten/longformer-random-tiny"
      )
      layer = model.longformer.encoder.layer[0].attention.self_attention
      hidden_states = self._get_hidden_states()
  
      hidden_states = tf.concat(
          [self._get_hidden_states(), self._get_hidden_states() - 0.5],
          axis=0,
      )
      batch_size, seq_length, hidden_size = hidden_states.shape
  
      # create attn mask
      attention_mask_1 = tf.zeros(
          (1, 1, 1, seq_length), dtype=tf.float32
      )
      attention_mask_2 = tf.zeros(
          (1, 1, 1, seq_length), dtype=tf.float32
      )
  
      attention_mask_1 = tf.where(
          tf.range(4)[None, :, None, None] > 1,
          10000.0,
          attention_mask_1,
      )
      attention_mask_1 = tf.where(
          tf.range(4)[None, :, None, None] > 2,
          -10000.0,
          attention_mask_1,
      )
      attention_mask_2 = tf.where(
          tf.range(4)[None, :, None, None] > 0,
          10000.0,
          attention_mask_2,
      )
      attention_mask = tf.concat(
          [attention_mask_1, attention_mask_2], axis=0
      )
  
      is_index_masked = tf.math.less(attention_mask[:, :, 0, 0], 0)
      is_index_global_attn = tf.math.greater(
          attention_mask[:, :, 0, 0], 0
      )
      is_global_attn = tf.math.reduce_any(is_index_global_attn)
  
      layer_head_mask = None
  
      output_hidden_states = layer(
          [
              hidden_states,
              -tf.math.abs(attention_mask),
              layer_head_mask,
              is_index_masked,
              is_index_global_attn,
              is_global_attn,
          ]
      )[0]
  
      self.assertEqual(output_hidden_states.shape, (2, 4, 8))
      expected_slice_0 = tf.convert_to_tensor(
          [
              -0.06508,
              -0.039306,
              0.030934,
              -0.03417,
              -0.00656,
              -0.01553,
              -0.02088,
              -0.04938,
          ],
          dtype=tf.float32,
      )
  
      expected_slice_1 = tf.convert_to_tensor(
          [
              -0.04055,
              -0.038399,
              0.0396,
              -0.03735,
              -0.03415,
              0.01357,
              0.00145,
              -0.05709,
          ],
          dtype=tf.float32,
      )
  
      tf.debugging.assert_near(
          output_hidden_states[0, 2],
          expected_slice_0,
          rtol=1e-3,
          atol=1e-4,
      )
      tf.debugging.assert_near(
          output_hidden_states[1, -2],
          expected_slice_1,
          rtol=1e-3,
          atol=1e-4,
      )
  
imports: import unittest
  from transformers import is_tf_available
  from transformers.testing_utils import require_sentencepiece, require_tf, require_tokenizers, slow, tooslow
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
label_desc: Use image node_id 7 for calling the TFLongformerModelIntegrationTest obj's underlying member method code with example usage: obj.test_layer_global_attn() without return types