code: def _get_rand_mask(self, shape: torch.Size) -> torch.Tensor:
      sparsity = 1 - self.r
      mask = random_pattern(shape[1], sparsity=sparsity)
  
      if self.causal:
          mask &= causal_1d_pattern(shape[1])
  
      mask = (
          sparsify(mask)
          if self.force_sparsity
          else maybe_sparsify(mask)
      )
  
      return mask
  
file_path: xformers/xformers/components/attention/random.py
imports: from dataclasses import dataclass
  from typing import Optional, Union
  import torch
  import torch.nn
  from xformers.components.attention import Attention, AttentionConfig, AttentionMask, maybe_sparsify, register_attention, sparsify
  from xformers.components.attention.attention_patterns import causal_1d_pattern, random_pattern
  from xformers.components.attention.core import scaled_dot_product_attention
label_desc: Use image node_id 2 for calling the RandomAttention obj's underlying member method code with example usage: obj._get_rand_mask(shape) and returns: mask