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 random attention layout used by the given head in the sparse attention.
  Note) By default, it assumes there will be a unique random block layout for all heads; unless
  `different_layout_per_head` parameter is set in which each head can have a different random
  layout.
  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 random layout is set
docstr_tok: ["Sets","random","attention","layout","used","by","the","given","head","in","the","sparse","attention",".","Note",")","By","default",",","it","assumes","there","will","be","a","unique","random","block","layout","for","all","heads",";","unless","`","different_layout_per_head","`","parameter","is","set","in","which","each","head","can","have","a","different","random","layout",".","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","random","layout","is","set"]
code: def set_random_layout(self, h, layout):
      """Sets random attention layout used by the given head in the sparse attention.
      Note) By default, it assumes there will be a unique random block layout for all heads; unless
      `different_layout_per_head` parameter is set in which each head can have a different random
      layout.
      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 random layout is set
      """
  
      num_blocks = layout.shape[1]
      if num_blocks < self.num_random_blocks:
          raise ValueError(
              f"""Number of random blocks, {self.num_random_blocks}, must be smaller than overall number
                  of blocks in a row, {num_blocks}!"""
          )
      for row in range(0, num_blocks):
          rnd_cols = random.sample(
              range(0, num_blocks), self.num_random_blocks
          )
          layout[h, row, rnd_cols] = 1
      return layout
  
imports: import random
  import torch
label_desc: Use image node_id 2 for calling the VariableSparsityConfig obj's underlying member method code with example usage: obj.set_random_layout(h, layout) and returns: layout