code: def rand_sparse_semi_structured_mask(
      r, c, dtype=torch.float16, device="cuda", choice=None
  ):
      """
      This function returns a 1:2 sparse matrix of size (r, c).
      Note that this means this matrix will also be 2:4 and 4:8 sparse as well.
      """
  
      choices = [[0, 1], [1, 0]]
      mask_entries = [
          choice or random.choice(choices) for i in range(r * c // 2)
      ]
  
      return (
          torch.tensor(mask_entries, dtype=dtype, device=device)
          .reshape(r, c)
          .contiguous()
      )
  
file_path: pytorch/benchmarks/sparse/benchmark_semi_structured_sparsity.py
imports: import argparse
  import random
  import pandas
  import torch
  import torch.utils.benchmark
  from torch import nn
  from torch.sparse import SparseSemiStructuredTensor, to_sparse_semi_structured
  from tqdm import tqdm
label_desc: Use image node_id 1 for calling a global function with example usage: rand_sparse_semi_structured_mask(r, c, dtype, device, choice) and returns: torch