code: def block2_sparsity(weight: _torch.Tensor) -> _torch.Tensor:
      n = weight.size(0)
      assert n % 2 == 0
      return (
          weight.flatten(1)
          .view(n // 2, 2, -1)
          .sum(1)
          .eq(0.0)
          .float()
          .mean()
          .item()
      )
  
file_path: coremltools/coremltools/optimize/torch/pruning/_utils.py
imports: import logging
  from typing import List
  from typing import Optional
  from typing import Tuple
  from typing import cast
  import numpy
  import torch
label_desc: Use image node_id 5 for calling a global function with example usage: block2_sparsity(weight) and returns: weight