code: def test_mask_conflict(self):
      outdir = os.path.join(prefix, "masks")
      os.makedirs(outdir, exist_ok=True)
      for name in model_names:
          print("Test mask conflict for %s" % name)
          model = getattr(models, name)
          net = model().to(device)
          dummy_input = torch.ones(1, 3, 224, 224).to(device)
          # random generate the prune sparsity for each layer
          cfglist = []
          for layername, layer in net.named_modules():
              if isinstance(layer, nn.Conv2d):
                  # pruner cannot allow the sparsity to be 0 or 1
                  sparsity = np.random.uniform(0.01, 0.99)
                  cfg = {
                      "op_types": ["Conv2d"],
                      "op_names": [layername],
                      "sparsity": sparsity,
                  }
                  cfglist.append(cfg)
          pruner = L1FilterPruner(net, cfglist)
          pruner.compress()
          ck_file = os.path.join(outdir, "%s.pth" % name)
          mask_file = os.path.join(outdir, "%s_mask" % name)
          pruner.export_model(ck_file, mask_file)
          pruner._unwrap_model()
          # Fix the mask conflict
          fixed_mask, _ = fix_mask_conflict(mask_file, net, dummy_input)
  
          # use the channel dependency groud truth to check if
          # fix the mask conflict successfully
          for dset in channel_dependency_ground_truth[name]:
              lset = list(dset)
              for i, _ in enumerate(lset):
                  assert fixed_mask[lset[0]]["weight"].size(
                      0
                  ) == fixed_mask[lset[i]]["weight"].size(0)
                  w_index1 = self.get_pruned_index(
                      fixed_mask[lset[0]]["weight"]
                  )
                  w_index2 = self.get_pruned_index(
                      fixed_mask[lset[i]]["weight"]
                  )
                  assert w_index1 == w_index2
                  if hasattr(fixed_mask[lset[0]], "bias"):
                      b_index1 = self.get_pruned_index(
                          fixed_mask[lset[0]]["bias"]
                      )
                      b_index2 = self.get_pruned_index(
                          fixed_mask[lset[i]]["bias"]
                      )
                      assert b_index1 == b_index2
  
file_path: auptimizer/tests/compression/test_compression_utils.py
imports: import os
  import unittest
  from unittest import TestCase, main
  import torch
  import torch.nn
  import torchvision.models
  import numpy
  from aup.compression.torch import L1FilterPruner
  from aup.compression.torch.utils.shape_dependency import ChannelDependency
  from aup.compression.torch.utils.mask_conflict import fix_mask_conflict
  from aup.compression.torch.utils.counter import count_flops_params
label_desc: Use image node_id 3 for calling the AnalysisUtilsTest obj's underlying member method code with example usage: obj.test_mask_conflict() without return types