code: def compute_sparsity(
      origin_model: Module,
      compact_model: Module,
      compact_model_masks: Dict[str, Dict[str, Tensor]],
      config_list: List[Dict],
  ) -> Tuple[List[Dict], List[Dict], List[Dict]]:
      """
      This function computes how much the origin model has been compressed in the current state.
      The current state means `compact_model` + `compact_model_masks`
      (i.e., `compact_model_masks` applied on `compact_model`).
      The compact model is the origin model after pruning,
      and it may have different structure with origin_model cause of speedup.
  
      Parameters
      ----------
      origin_model : torch.nn.Module
          The original un-pruned model.
      compact_model : torch.nn.Module
          The model after speedup or original model.
      compact_model_masks: Dict[str, Dict[str, Tensor]]
          The masks applied on the compact model, if the original model have been speedup, this should be {}.
      config_list : List[Dict]
          The config_list used by pruning the original model.
  
      Returns
      -------
      Tuple[List[Dict], List[Dict], List[Dict]]
          (current2origin_sparsity, compact2origin_sparsity, mask2compact_sparsity).
          current2origin_sparsity is how much the origin model has been compressed in the current state.
          compact2origin_sparsity is the sparsity obtained by comparing the structure of origin model and compact model.
          mask2compact_sparsity is the sparsity computed by count the zero value in the mask.
      """
      compact2origin_sparsity = compute_sparsity_compact2origin(
          origin_model, compact_model, config_list
      )
      mask2compact_sparsity = compute_sparsity_mask2compact(
          compact_model, compact_model_masks, config_list
      )
      assert len(compact2origin_sparsity) == len(
          mask2compact_sparsity
      ), "Length mismatch."
      current2origin_sparsity = []
      for c2o_sparsity, m2c_sparsity, config in zip(
          compact2origin_sparsity, mask2compact_sparsity, config_list
      ):
          current2origin_sparsity.append(deepcopy(config))
          current2origin_sparsity[-1]["total_sparsity"] = 1 - (
              1 - c2o_sparsity["total_sparsity"]
          ) * (1 - m2c_sparsity["total_sparsity"])
      return (
          current2origin_sparsity,
          compact2origin_sparsity,
          mask2compact_sparsity,
      )
  
file_path: nni/nni/compression/utils/mask_counter.py
imports: from copy import deepcopy
  import math
  from typing import Dict, List, Tuple
  import torch
  from torch import Tensor
  from torch.nn import Module
label_desc: Use image node_id 3 for calling a global function with example usage: compute_sparsity(origin_model, compact_model, compact_model_masks, config_list) and returns: current2origin_sparsity,  compact2origin_sparsity,  mask2compact_sparsity