docstr: Filters with the minimum sum of the weights' L1 norm are pruned in this paper:
  PRUNING FILTERS FOR EFFICIENT CONVNETS,
  https://arxiv.org/abs/1608.08710
  
  So if sparsity is 0.2 for conv1, the expected masks should mask out filter 0, this can be verified through:
  `all(torch.sum(mask1, (1, 2, 3)).numpy() == np.array([0., 25., 25., 25., 25.]))`
  
  If sparsity is 0.6 for conv2, the expected masks should mask out filter 0,1,2, this can be verified through:
  `all(torch.sum(mask2, (1, 2, 3)).numpy() == np.array([0., 0., 0., 0., 0., 0., 125., 125., 125., 125.]))`
docstr_tok: ["Filters","with","the","minimum","sum","of","the","weights","'","L1","norm","are","pruned","in","this","paper",":","PRUNING","FILTERS","FOR","EFFICIENT","CONVNETS",",","https",":","\/\/arxiv.org\/abs\/1608.08710","So","if","sparsity","is","0.2","for","conv1",",","the","expected","masks","should","mask","out","filter","0",",","this","can","be","verified","through",":","`","all","(","torch.sum","(","mask1",",","(","1",",","2",",","3",")",")",".numpy","(",")","==","np.array","(","[","0.",",","25.",",","25.",",","25.",",","25",".","]",")",")","`","If","sparsity","is","0.6","for","conv2",",","the","expected","masks","should","mask","out","filter","0,1,2",",","this","can","be","verified","through",":","`","all","(","torch.sum","(","mask2",",","(","1",",","2",",","3",")",")",".numpy","(",")","==","np.array","(","[","0.",",","0.",",","0.",",","0.",",","0.",",","0.",",","125.",",","125.",",","125.",",","125",".","]",")",")","`"]
code: def test_torch_l1filter_pruner(self):
      """
      Filters with the minimum sum of the weights' L1 norm are pruned in this paper:
      PRUNING FILTERS FOR EFFICIENT CONVNETS,
      https://arxiv.org/abs/1608.08710
  
      So if sparsity is 0.2 for conv1, the expected masks should mask out filter 0, this can be verified through:
      `all(torch.sum(mask1, (1, 2, 3)).numpy() == np.array([0., 25., 25., 25., 25.]))`
  
      If sparsity is 0.6 for conv2, the expected masks should mask out filter 0,1,2, this can be verified through:
      `all(torch.sum(mask2, (1, 2, 3)).numpy() == np.array([0., 0., 0., 0., 0., 0., 125., 125., 125., 125.]))`
      """
      w1 = np.array([np.ones((1, 5, 5)) * i for i in range(5)]).astype(
          np.float32
      )
      w2 = np.array([np.ones((5, 5, 5)) * i for i in range(10)]).astype(
          np.float32
      )
  
      model = TorchModel()
      config_list = [
          {
              "sparsity": 0.2,
              "op_types": ["Conv2d"],
              "op_names": ["conv1"],
          },
          {
              "sparsity": 0.6,
              "op_types": ["Conv2d"],
              "op_names": ["conv2"],
          },
      ]
      pruner = L1FilterPruner(model, config_list)
  
      model.conv1.module.weight.data = torch.tensor(w1).float()
      model.conv2.module.weight.data = torch.tensor(w2).float()
      mask1 = pruner.calc_mask(model.conv1)
      mask2 = pruner.calc_mask(model.conv2)
      assert all(
          torch.sum(mask1["weight_mask"], (1, 2, 3)).numpy()
          == np.array([0.0, 25.0, 25.0, 25.0, 25.0])
      )
      assert all(
          torch.sum(mask2["weight_mask"], (1, 2, 3)).numpy()
          == np.array(
              [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 125.0, 125.0, 125.0, 125.0]
          )
      )
  
imports: from unittest import TestCase, main
  import numpy
  import torch
  import torch.nn.functional
  import schema
  from aup.compression.torch.pruning import *
  from aup.compression.torch.quantization import *
  import math
label_desc: Use image node_id 5 for calling the CompressorTestCase obj's underlying member method code with example usage: obj.test_torch_l1filter_pruner() without return types