docstr: Scale factors with minimum l1 norm in the BN layers are pruned in this paper:
  Learning Efficient Convolutional Networks through Network Slimming,
  https://arxiv.org/pdf/1708.06519.pdf
  
  So if sparsity is 0.2, the expected masks should mask out channel 0, this can be verified through:
  `all(mask1.numpy() == np.array([0., 1., 1., 1., 1.]))`
  `all(mask2.numpy() == np.array([0., 1., 1., 1., 1.]))`
  
  If sparsity is 0.6, the expected masks should mask out channel 0,1,2, this can be verified through:
  `all(mask1.numpy() == np.array([0., 0., 0., 1., 1.]))`
  `all(mask2.numpy() == np.array([0., 0., 0., 1., 1.]))`
docstr_tok: ["Scale","factors","with","minimum","l1","norm","in","the","BN","layers","are","pruned","in","this","paper",":","Learning","Efficient","Convolutional","Networks","through","Network","Slimming",",","https",":","\/\/arxiv.org\/pdf\/1708.06519.pdf","So","if","sparsity","is","0.2",",","the","expected","masks","should","mask","out","channel","0",",","this","can","be","verified","through",":","`","all","(","mask1.numpy","(",")","==","np.array","(","[","0.",",","1.",",","1.",",","1.",",","1",".","]",")",")","`","`","all","(","mask2.numpy","(",")","==","np.array","(","[","0.",",","1.",",","1.",",","1.",",","1",".","]",")",")","`","If","sparsity","is","0.6",",","the","expected","masks","should","mask","out","channel","0,1,2",",","this","can","be","verified","through",":","`","all","(","mask1.numpy","(",")","==","np.array","(","[","0.",",","0.",",","0.",",","1.",",","1",".","]",")",")","`","`","all","(","mask2.numpy","(",")","==","np.array","(","[","0.",",","0.",",","0.",",","1.",",","1",".","]",")",")","`"]
code: def test_torch_slim_pruner(self):
      """
      Scale factors with minimum l1 norm in the BN layers are pruned in this paper:
      Learning Efficient Convolutional Networks through Network Slimming,
      https://arxiv.org/pdf/1708.06519.pdf
  
      So if sparsity is 0.2, the expected masks should mask out channel 0, this can be verified through:
      `all(mask1.numpy() == np.array([0., 1., 1., 1., 1.]))`
      `all(mask2.numpy() == np.array([0., 1., 1., 1., 1.]))`
  
      If sparsity is 0.6, the expected masks should mask out channel 0,1,2, this can be verified through:
      `all(mask1.numpy() == np.array([0., 0., 0., 1., 1.]))`
      `all(mask2.numpy() == np.array([0., 0., 0., 1., 1.]))`
      """
      w = np.array([0, 1, 2, 3, 4])
      model = TorchModel()
      config_list = [{"sparsity": 0.2, "op_types": ["BatchNorm2d"]}]
      model.bn1.weight.data = torch.tensor(w).float()
      model.bn2.weight.data = torch.tensor(-w).float()
      pruner = SlimPruner(model, config_list)
  
      mask1 = pruner.calc_mask(model.bn1)
      mask2 = pruner.calc_mask(model.bn2)
      assert all(
          mask1["weight_mask"].numpy()
          == np.array([0.0, 1.0, 1.0, 1.0, 1.0])
      )
      assert all(
          mask2["weight_mask"].numpy()
          == np.array([0.0, 1.0, 1.0, 1.0, 1.0])
      )
      assert all(
          mask1["bias_mask"].numpy()
          == np.array([0.0, 1.0, 1.0, 1.0, 1.0])
      )
      assert all(
          mask2["bias_mask"].numpy()
          == np.array([0.0, 1.0, 1.0, 1.0, 1.0])
      )
  
      model = TorchModel()
      config_list = [{"sparsity": 0.6, "op_types": ["BatchNorm2d"]}]
      model.bn1.weight.data = torch.tensor(w).float()
      model.bn2.weight.data = torch.tensor(w).float()
      pruner = SlimPruner(model, config_list)
  
      mask1 = pruner.calc_mask(model.bn1)
      mask2 = pruner.calc_mask(model.bn2)
      assert all(
          mask1["weight_mask"].numpy()
          == np.array([0.0, 0.0, 0.0, 1.0, 1.0])
      )
      assert all(
          mask2["weight_mask"].numpy()
          == np.array([0.0, 0.0, 0.0, 1.0, 1.0])
      )
      assert all(
          mask1["bias_mask"].numpy()
          == np.array([0.0, 0.0, 0.0, 1.0, 1.0])
      )
      assert all(
          mask2["bias_mask"].numpy()
          == np.array([0.0, 0.0, 0.0, 1.0, 1.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 6 for calling the CompressorTestCase obj's underlying member method code with example usage: obj.test_torch_slim_pruner() without return types