class_docstr: Configuration class to store edited `Longformer` sparsity configuration.
  Note) this is a block-sparse version of the Longformer which is slightly different than original
  Longformer; which is element-wise sparsity.
  For more details about this sparsity config, please see `Longformer:
  The Long-Document Transformer`: https://arxiv.org/pdf/2004.05150.pdf
  This class extends parent class of `SparsityConfig` and customizes it for `Longformer` sparsity.
class_docstr_tok: ["Configuration","class","to","store","edited","`","Longformer","`","sparsity","configuration",".","Note",")","this","is","a","block-sparse","version","of","the","Longformer","which","is","slightly","different","than","original","Longformer",";","which","is","element-wise","sparsity",".","For","more","details","about","this","sparsity","config",",","please","see","`","Longformer",":","The","Long-Document","Transformer","`",":","https",":","\/\/arxiv.org\/pdf\/2004.05150.pdf","This","class","extends","parent","class","of","`","SparsityConfig","`","and","customizes","it","for","`","Longformer","`","sparsity","."]
docstr: Sets global attention layout used by the given head in the sparse attention.
  Arguments:
       h: required: an integer determining head index
       layout: required: a tensor of dimension (num_heads, num_blocks, num_blocks) containing
          sparsity layout of all head; may not be completely set at this step
  Return:
       layout: a tensor of dimension (num_heads, num_blocks, num_blocks) containing sparsity
          layout of all head in which global layout is set
docstr_tok: ["Sets","global","attention","layout","used","by","the","given","head","in","the","sparse","attention",".","Arguments",":","h",":","required",":","an","integer","determining","head","index","layout",":","required",":","a","tensor","of","dimension","(","num_heads",",","num_blocks",",","num_blocks",")","containing","sparsity","layout","of","all","head",";","may","not","be","completely","set","at","this","step","Return",":","layout",":","a","tensor","of","dimension","(","num_heads",",","num_blocks",",","num_blocks",")","containing","sparsity","layout","of","all","head","in","which","global","layout","is","set"]
code: def set_global_layout(self, h, layout):
      """Sets global attention layout used by the given head in the sparse attention.
      Arguments:
           h: required: an integer determining head index
           layout: required: a tensor of dimension (num_heads, num_blocks, num_blocks) containing
              sparsity layout of all head; may not be completely set at this step
      Return:
           layout: a tensor of dimension (num_heads, num_blocks, num_blocks) containing sparsity
              layout of all head in which global layout is set
      """
  
      num_blocks = layout.shape[1]
      if self.global_block_end_indices is None:
          for idx in self.global_block_indices:
              # if global block idx is in the range of the sequence blocks
              if idx < num_blocks:
                  # global rows
                  layout[h, idx, :] = 1
  
                  # global columns
                  layout[h, :, idx] = 1
      else:
          for _, (start_idx, end_idx) in enumerate(
              zip(
                  self.global_block_indices,
                  self.global_block_end_indices,
              )
          ):
              # if global block idx is in the range of the sequence blocks
              if start_idx < num_blocks:
                  end_idx = min(end_idx, num_blocks)
                  # global rows
                  layout[h, start_idx:end_idx, :] = 1
  
                  # global columns
                  layout[h, :, start_idx:end_idx] = 1
      if self.attention == "unidirectional":
          layout = torch.tril(layout)
      return layout
  
imports: import random
  import torch
label_desc: Use image node_id 3 for calling the BSLongformerSparsityConfig obj's underlying member method code with example usage: obj.set_global_layout(h, layout) and returns: layout