code: def calc_mask(self, sparsity, wrapper, wrapper_idx=None):
      msg = "module type {} is not supported!".format(wrapper.type)
      # assert wrapper.type == 'Conv2d', msg
      weight = wrapper.module.weight.data
      bias = None
      if (
          hasattr(wrapper.module, "bias")
          and wrapper.module.bias is not None
      ):
          bias = wrapper.module.bias.data
  
      if wrapper.weight_mask is None:
          mask_weight = (
              torch.ones(weight.size()).type_as(weight).detach()
          )
      else:
          mask_weight = wrapper.weight_mask.clone()
      if bias is not None:
          if wrapper.bias_mask is None:
              mask_bias = torch.ones(bias.size()).type_as(bias).detach()
          else:
              mask_bias = wrapper.bias_mask.clone()
      else:
          mask_bias = None
      base_mask = {"weight_mask": mask_weight, "bias_mask": mask_bias}
  
      num_total = weight.size(1)
      num_prune = int(num_total * sparsity)
  
      if num_total < 2 or num_prune < 1:
          return base_mask
      w_abs = weight.abs()
      if wrapper.type == "Conv2d":
          w_abs_structured = w_abs.sum((0, 2, 3))
          threshold = torch.topk(
              w_abs_structured, num_prune, largest=False
          )[0].max()
          mask_weight = (
              torch.gt(w_abs_structured, threshold)[None, :, None, None]
              .expand_as(weight)
              .type_as(weight)
          )
          return {"weight_mask": mask_weight.detach()}
      else:
          # Linear
          assert wrapper.type == "Linear"
          w_abs_structured = w_abs.sum((0))
          threshold = torch.topk(
              w_abs_structured, num_prune, largest=False
          )[0].max()
          mask_weight = (
              torch.gt(w_abs_structured, threshold)[None, :]
              .expand_as(weight)
              .type_as(weight)
          )
          return {
              "weight_mask": mask_weight.detach(),
              "bias_mask": mask_bias,
          }
  
imports: import os
  import psutil
  import sys
  import numpy
  import torch
  import torchvision.models
  import torch.nn
  import torch.nn.functional
  from torchvision.models.vgg import vgg16
  from torchvision.models.resnet import resnet18
  import unittest
  from unittest import TestCase, main
  from aup.compression.torch import L1FilterPruner, apply_compression_results, ModelSpeedup
  from aup.compression.torch.pruning.weight_masker import WeightMasker
  from aup.compression.torch.pruning.one_shot import _StructuredFilterPruner
label_desc: Use image node_id 2 for calling the L1ChannelMasker obj's underlying member method code with example usage: obj.calc_mask(sparsity, wrapper, wrapper_idx) and returns: base_mask, dict, dict