code: def test_block_sparse_context_layer(self):
      model = BigBirdModel.from_pretrained(
          "google/bigbird-roberta-base",
          attention_type="block_sparse",
          num_random_blocks=3,
          block_size=16,
      )
      model.to(torch_device)
      model.eval()
      config = model.config
  
      input_ids = self._get_dummy_input_ids()
      dummy_hidden_states = model.embeddings(input_ids)
  
      attn_mask = torch.ones_like(input_ids, device=torch_device)
      (
          blocked_mask,
          band_mask,
          from_mask,
          to_mask,
      ) = model.create_masks_for_block_sparse_attn(
          attn_mask, config.block_size
      )
  
      targeted_cl = torch.tensor(
          [
              [
                  0.1870,
                  1.5248,
                  0.2333,
                  -0.0483,
                  -0.0952,
                  1.8359,
                  -0.0142,
                  0.1239,
                  0.0083,
                  -0.0045,
              ],
              [
                  -0.0601,
                  0.1243,
                  0.1329,
                  -0.1524,
                  0.2347,
                  0.0894,
                  -0.2248,
                  -0.2461,
                  -0.0645,
                  -0.0109,
              ],
              [
                  -0.0418,
                  0.1463,
                  0.1290,
                  -0.1638,
                  0.2489,
                  0.0799,
                  -0.2341,
                  -0.2406,
                  -0.0524,
                  0.0106,
              ],
              [
                  0.1859,
                  1.5182,
                  0.2324,
                  -0.0473,
                  -0.0952,
                  1.8295,
                  -0.0148,
                  0.1242,
                  0.0080,
                  -0.0045,
              ],
              [
                  0.1879,
                  1.5300,
                  0.2334,
                  -0.0480,
                  -0.0967,
                  1.8428,
                  -0.0137,
                  0.1256,
                  0.0087,
                  -0.0050,
              ],
              [
                  0.1852,
                  1.5149,
                  0.2330,
                  -0.0492,
                  -0.0936,
                  1.8236,
                  -0.0154,
                  0.1210,
                  0.0080,
                  -0.0048,
              ],
              [
                  0.1857,
                  1.5186,
                  0.2331,
                  -0.0484,
                  -0.0940,
                  1.8285,
                  -0.0148,
                  0.1224,
                  0.0077,
                  -0.0045,
              ],
              [
                  0.1884,
                  1.5336,
                  0.2334,
                  -0.0469,
                  -0.0974,
                  1.8477,
                  -0.0132,
                  0.1266,
                  0.0085,
                  -0.0046,
              ],
              [
                  0.1881,
                  1.5308,
                  0.2334,
                  -0.0479,
                  -0.0969,
                  1.8438,
                  -0.0136,
                  0.1258,
                  0.0088,
                  -0.0050,
              ],
              [
                  0.1849,
                  1.5143,
                  0.2329,
                  -0.0491,
                  -0.0930,
                  1.8230,
                  -0.0156,
                  0.1209,
                  0.0074,
                  -0.0047,
              ],
              [
                  0.1878,
                  1.5299,
                  0.2333,
                  -0.0472,
                  -0.0967,
                  1.8434,
                  -0.0137,
                  0.1257,
                  0.0084,
                  -0.0048,
              ],
              [
                  0.1873,
                  1.5260,
                  0.2333,
                  -0.0478,
                  -0.0961,
                  1.8383,
                  -0.0142,
                  0.1245,
                  0.0083,
                  -0.0048,
              ],
              [
                  0.1849,
                  1.5145,
                  0.2327,
                  -0.0491,
                  -0.0935,
                  1.8237,
                  -0.0156,
                  0.1215,
                  0.0083,
                  -0.0046,
              ],
              [
                  0.1866,
                  1.5232,
                  0.2332,
                  -0.0488,
                  -0.0950,
                  1.8342,
                  -0.0143,
                  0.1237,
                  0.0084,
                  -0.0047,
              ],
          ],
          device=torch_device,
      )
  
      context_layer = model.encoder.layer[0].attention.self(
          dummy_hidden_states,
          band_mask=band_mask,
          from_mask=from_mask,
          to_mask=to_mask,
          from_blocked_mask=blocked_mask,
          to_blocked_mask=blocked_mask,
      )
      context_layer = context_layer[0]
  
      self.assertEqual(context_layer.shape, torch.Size((1, 128, 768)))
      self.assertTrue(
          torch.allclose(
              context_layer[0, 64:78, 300:310], targeted_cl, atol=0.0001
          )
      )
  
imports: import unittest
  from transformers import BigBirdConfig, is_torch_available
  from transformers.models.auto import get_values
  from transformers.models.big_bird.tokenization_big_bird import BigBirdTokenizer
  from transformers.testing_utils import require_torch, slow, torch_device
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
  from ...test_pipeline_mixin import PipelineTesterMixin
label_desc: Use image node_id 5 for calling the BigBirdModelIntegrationTest obj's underlying member method code with example usage: obj.test_block_sparse_context_layer() without return types