docstr: With filters(kernels) weights defined as above (w), it is obvious that w[4] and w[5] is the Geometric Median
  which minimize the total geometric distance by defination of Geometric Median in this paper:
  Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration,
  https://arxiv.org/pdf/1811.00250.pdf
  
  So if sparsity is 0.2, the expected masks should mask out w[4] and w[5], this can be verified through:
  `all(torch.sum(masks, (1, 2, 3)).numpy() == np.array([125., 125., 125., 125., 0., 0., 125., 125., 125., 125.]))`
  
  If sparsity is 0.6, the expected masks should mask out w[2] - w[7], this can be verified through:
  `all(torch.sum(masks, (1, 2, 3)).numpy() == np.array([125., 125., 0., 0., 0., 0., 0., 0., 125., 125.]))`
docstr_tok: ["With","filters","(","kernels",")","weights","defined","as","above","(","w",")",",","it","is","obvious","that","w","[","4","]","and","w","[","5","]","is","the","Geometric","Median","which","minimize","the","total","geometric","distance","by","defination","of","Geometric","Median","in","this","paper",":","Filter","Pruning","via","Geometric","Median","for","Deep","Convolutional","Neural","Networks","Acceleration",",","https",":","\/\/arxiv.org\/pdf\/1811.00250.pdf","So","if","sparsity","is","0.2",",","the","expected","masks","should","mask","out","w","[","4","]","and","w","[","5","]",",","this","can","be","verified","through",":","`","all","(","torch.sum","(","masks",",","(","1",",","2",",","3",")",")",".numpy","(",")","==","np.array","(","[","125.",",","125.",",","125.",",","125.",",","0.",",","0.",",","125.",",","125.",",","125.",",","125",".","]",")",")","`","If","sparsity","is","0.6",",","the","expected","masks","should","mask","out","w","[","2","]","-","w","[","7","]",",","this","can","be","verified","through",":","`","all","(","torch.sum","(","masks",",","(","1",",","2",",","3",")",")",".numpy","(",")","==","np.array","(","[","125.",",","125.",",","0.",",","0.",",","0.",",","0.",",","0.",",","0.",",","125.",",","125",".","]",")",")","`"]
code: def test_torch_fpgm_pruner(self):
      """
      With filters(kernels) weights defined as above (w), it is obvious that w[4] and w[5] is the Geometric Median
      which minimize the total geometric distance by defination of Geometric Median in this paper:
      Filter Pruning via Geometric Median for Deep Convolutional Neural Networks Acceleration,
      https://arxiv.org/pdf/1811.00250.pdf
  
      So if sparsity is 0.2, the expected masks should mask out w[4] and w[5], this can be verified through:
      `all(torch.sum(masks, (1, 2, 3)).numpy() == np.array([125., 125., 125., 125., 0., 0., 125., 125., 125., 125.]))`
  
      If sparsity is 0.6, the expected masks should mask out w[2] - w[7], this can be verified through:
      `all(torch.sum(masks, (1, 2, 3)).numpy() == np.array([125., 125., 0., 0., 0., 0., 0., 0., 125., 125.]))`
      """
      w = np.array(
          [np.ones((5, 5, 5)) * (i + 1) for i in range(10)]
      ).astype(np.float32)
  
      model = TorchModel()
      config_list = [
          {"sparsity": 0.6, "op_types": ["Conv2d"]},
          {"sparsity": 0.2, "op_types": ["Conv2d"]},
      ]
      pruner = FPGMPruner(
          model,
          config_list,
          torch.optim.SGD(model.parameters(), lr=0.01),
      )
  
      model.conv2.module.weight.data = torch.tensor(w).float()
      masks = pruner.calc_mask(model.conv2)
      assert all(
          torch.sum(masks["weight_mask"], (1, 2, 3)).numpy()
          == np.array(
              [
                  125.0,
                  125.0,
                  125.0,
                  125.0,
                  0.0,
                  0.0,
                  125.0,
                  125.0,
                  125.0,
                  125.0,
              ]
          )
      )
  
      model.conv2.module.weight.data = torch.tensor(w).float()
      model.conv2.if_calculated = False
      model.conv2.config = config_list[0]
      masks = pruner.calc_mask(model.conv2)
      assert all(
          torch.sum(masks["weight_mask"], (1, 2, 3)).numpy()
          == np.array(
              [125.0, 125.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.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 4 for calling the CompressorTestCase obj's underlying member method code with example usage: obj.test_torch_fpgm_pruner() without return types