code: def sparsity_stats(mask: Dict[str, torch.Tensor]) -> str:
      """
      Calculate the sparsity of a mask.
  
      Parameters
      ----------
      mask
          The mask tensor.
  
      Returns
      -------
      str
          The sparsity of the mask.
      """
      ret = ""
      for k, v in mask.items():
          if isinstance(v, torch.Tensor):
              ret += f"{k}: {1 - v.nonzero().size(0) / v.numel(): .4f} "
      return ret
  
imports: from __future__ import annotations
  import inspect
  import logging
  from pathlib import Path
  import tempfile
  from typing import Any, Dict, List
  import torch
  import torch.fx
  from torch.fx import GraphModule
  from torch.fx._compatibility import compatibility
  from torch.fx.node import Node, Target
  from torch.fx.passes.shape_prop import ShapeProp
  from nni.common.concrete_trace_utils import concrete_trace
  from nni.compression.utils import set_nested_attr
  from nni.compression.speedup.replacement import replace_module
  from .container import NodeInfo
  from .mask_conflict import fix_channel_mask_conflict, fix_group_mask_conflict, fix_weight_sharing_mask_conflict
  from .mask_updater import MaskUpdater, DefaultMaskUpdater, LeafModuleMaskUpdater, NoMaskUpdater, NoChangeMaskUpdater
  from .replacement import replace_module
  from .replacer import Replacer, DefaultReplacer
  from .utils import tree_map_zip, poss_deepcopy, randomize_like_with_shape, torch_integer_dtype
  from ..utils import set_nested_attr
label_desc: Use image node_id 2 for calling a global function with example usage: sparsity_stats(mask) and returns: ret