class_docstr: GroupMaskConflict fix the mask conflict between the layers that
  has group dependecy with each other.
  
  Parameters
  ----------
  masks : dict
      a dict object that stores the masks
  model : torch.nn.Module
      model to fix the mask conflict
  dummy_input : torch.Tensor
      input example to trace the model
  traced : torch._C.torch.jit.TopLevelTracedModule
      the traced model of the target model, is this parameter is not None,
      we donnot use the model and dummpy_input to get the trace graph.
class_docstr_tok: ["GroupMaskConflict","fix","the","mask","conflict","between","the","layers","that","has","group","dependecy","with","each","other",".","Parameters","--","--","--","--","--","masks",":","dict","a","dict","object","that","stores","the","masks","model",":","torch.nn.Module","model","to","fix","the","mask","conflict","dummy_input",":","torch.Tensor","input","example","to","trace","the","model","traced",":","torch._C.torch.jit.TopLevelTracedModule","the","traced","model","of","the","target","model",",","is","this","parameter","is","not","None",",","we","donnot","use","the","model","and","dummpy_input","to","get","the","trace","graph","."]
docstr: Fix the mask conflict before the mask inference for the layers that
  has group dependencies. This function should be called before the
  mask inference of the 'speedup' module.
docstr_tok: ["Fix","the","mask","conflict","before","the","mask","inference","for","the","layers","that","has","group","dependencies",".","This","function","should","be","called","before","the","mask","inference","of","the","'speedup","'","module","."]
code: def fix_mask(self):
      """
      Fix the mask conflict before the mask inference for the layers that
      has group dependencies. This function should be called before the
      mask inference of the 'speedup' module.
      """
      group_depen = GroupDependency(
          self.model, self.dummy_input, self.traced
      )
      depens = group_depen.dependency
      min_groups = group_depen.min_groups
      _logger.info(depens)
      for layername in depens:
          group_max = depens[layername]
          group_min = min_groups[layername]
          if (
              layername not in self.masks
              or "weight" not in self.masks[layername]
          ):
              # this layer not pruned
              continue
          w_mask = self.masks[layername]["weight"]
          shape = w_mask.size()
          count = np.prod(shape[1:])
          all_ones = (
              (w_mask.flatten(1).sum(-1) == count)
              .nonzero()
              .squeeze(1)
              .tolist()
          )
          all_zeros = (
              (w_mask.flatten(1).sum(-1) == 0)
              .nonzero()
              .squeeze(1)
              .tolist()
          )
          if len(all_ones) + len(all_zeros) < w_mask.size(0):
              # In fine-grained pruning, skip this layer
              _logger.info(
                  "Layers %s using fine-grained pruning", layername
              )
              continue
          assert shape[0] % group_max == 0
          # Find the number of masked filter for each group (mini_masked).
          # Because we have to keep the pruned filter can still
          # be divided into the same number of groups, so we only can
          # prune mini_masked filters for each group.
          step = shape[0] / group_max
          group_masked = []
          for i in range(group_max):
              _start = step * i
              _end = step * (i + 1)
              _tmp_list = list(
                  filter(lambda x: _start <= x and x < _end, all_zeros)
              )
              group_masked.append(_tmp_list)
          mini_masked = min([len(x) for x in group_masked])
          need_unmask = set()
          for gm in group_masked:
              for i in range(mini_masked, len(gm)):
                  # To keep the output channel number still being divisible to
                  # groups, we set the masks of following filters to be zero.
                  pos = gm[i]
                  need_unmask.add(pos)
          step = shape[0] / group_min
          for i in range(group_min):
              _start = step * i
              _end = step * (i + 1)
              _tmp_list = list(
                  filter(lambda x: _start <= x and x < _end, all_zeros)
              )
              if len(_tmp_list) == step:
                  # if the whole group is removed, then we don't have to unmask for
                  # the filters in this group
                  for pos in _tmp_list:
                      if pos in need_unmask:
                          need_unmask.remove(pos)
          for pos in need_unmask:
              self.masks[layername]["weight"][pos] = torch.ones(
                  shape[1:]
              )
              if hasattr(self.masks[layername], "bias"):
                  self.masks[layername]["bias"][pos] = 1
      return self.masks
  
imports: import os
  import logging
  import torch
  import numpy
  from .attr import get_nested_attr
  from .shape_dependency import ChannelDependency, GroupDependency, InputChannelDependency
label_desc: Use image node_id 2 for calling the GroupMaskConflict obj's underlying member method code with example usage: obj.fix_mask() and returns: self