class_docstr: Configuration class to store `Variable` sparsity configuration.
  This layout is an extension of FixedSparsityConfig in which:
    - user can set random layout; default value is zero means no random block
    - user can provide a list of local block sizes
    - user can provide a list of global block indices.
  For more details about `Fixed` sparsity config, please see `Generative Modeling with
  Sparse Transformers`: https://arxiv.org/abs/1904.10509; this has been customized.
  This class extends parent class of `SparsityConfig` and customizes it for `Fixed` sparsity.
class_docstr_tok: ["Configuration","class","to","store","`","Variable","`","sparsity","configuration",".","This","layout","is","an","extension","of","FixedSparsityConfig","in","which",":","-","user","can","set","random","layout",";","default","value","is","zero","means","no","random","block","-","user","can","provide","a","list","of","local","block","sizes","-","user","can","provide","a","list","of","global","block","indices",".","For","more","details","about","`","Fixed","`","sparsity","config",",","please","see","`","Generative","Modeling","with","Sparse","Transformers","`",":","https",":","\/\/arxiv.org\/abs\/1904.10509",";","this","has","been","customized",".","This","class","extends","parent","class","of","`","SparsityConfig","`","and","customizes","it","for","`","Fixed","`","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
                  if self.horizontal_global_attention:
                      layout[h, idx, :] = 1
  
                  # global columns
                  first_row = (
                      0 if self.attention == "bidirectional" else idx
                  )
                  layout[h, first_row:, 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
                  if self.horizontal_global_attention:
                      layout[h, start_idx:end_idx, :] = 1
  
                  # global columns
                  first_row = (
                      0
                      if self.attention == "bidirectional"
                      else start_idx
                  )
                  layout[h, first_row:, start_idx:end_idx] = 1
      return layout
  
imports: import random
  import torch
label_desc: Use image node_id 4 for calling the VariableSparsityConfig obj's underlying member method code with example usage: obj.set_global_layout(h, layout) and returns: layout