code: def convert_to_coarse_mask(t_mask, dim):
      """
      Convert the mask tensor to the coarse-grained mask tensor.
  
      Parameters
      ---------
      t_mask: torch.Tensor
          The tensor only have 1s and 0s, 0 indicates this value is masked
          and 1 indicates the corresponding value is not masked.
      dim: int
          Try to reduce the mask tensor on this dimension.
  
      Returns
      -------
      indexes: torch.Tensor
          The indexes of the sparsity that can be structurally removed.
      remained_indexes: torch.Tensor
          The indexes of values that need to be remained.
      """
      assert isinstance(t_mask, torch.Tensor)
      shape = list(t_mask.size())
      n_dims = len(shape)
      dim_list = list(range(n_dims))
      # try to reduce the mask from the dim-th dimension
      dim = dim if dim >= 0 else n_dims + dim
      dim_list.remove(dim)
  
      t_merged = torch.sum(t_mask, dim_list)
      assert t_merged.size(0) == shape[dim]
      all_pruned = t_merged == 0
      need_remain = t_merged != 0
      # return the indexes of the sparsity that can be removed
      indexes = torch.nonzero(all_pruned, as_tuple=True)[0]
      remained_indexes = torch.nonzero(need_remain, as_tuple=True)[0]
      return indexes, remained_indexes
  
file_path: nni/nni/compression/speedup/replacement.py
imports: import logging
  import math
  import torch
  import torch.nn
  from .error_code import EmptyLayerError, ShapeMisMatchError, InputsNumberError, OutputTypeError, UnBalancedGroupError
label_desc: Use image node_id 1 for calling a global function with example usage: convert_to_coarse_mask(t_mask, dim) and returns: indexes,  remained_indexes