class_docstr: Parameters
  ----------
  model : torch.nn.Module
      Model to be pruned.
  config_list : listlist
      Supported keys:
          - initial_sparsity: This is to specify the sparsity when compressor starts to compress.
          - final_sparsity: This is to specify the sparsity when compressor finishes to compress.
          - start_epoch: This is to specify the epoch number when compressor starts to compress, default start from epoch 0.
          - end_epoch: This is to specify the epoch number when compressor finishes to compress.
          - frequency: This is to specify every *frequency* number epochs compressor compress once, default frequency=1.
  optimizer: torch.optim.Optimizer
      Optimizer used to train model.
  pruning_algorithm: str
      Algorithms being used to prune model,
      choose from `['level', 'slim', 'l1', 'l2', 'fpgm', 'taylorfo', 'apoz', 'mean_activation']`, by default `level`
class_docstr_tok: ["Parameters","--","--","--","--","--","model",":","torch.nn.Module","Model","to","be","pruned",".","config_list",":","listlist","Supported","keys",":","-","initial_sparsity",":","This","is","to","specify","the","sparsity","when","compressor","starts","to","compress",".","-","final_sparsity",":","This","is","to","specify","the","sparsity","when","compressor","finishes","to","compress",".","-","start_epoch",":","This","is","to","specify","the","epoch","number","when","compressor","starts","to","compress",",","default","start","from","epoch","0",".","-","end_epoch",":","This","is","to","specify","the","epoch","number","when","compressor","finishes","to","compress",".","-","frequency",":","This","is","to","specify","every","*","frequency","*","number","epochs","compressor","compress","once",",","default","frequency=1",".","optimizer",":","torch.optim.Optimizer","Optimizer","used","to","train","model",".","pruning_algorithm",":","str","Algorithms","being","used","to","prune","model",",","choose","from","`","[","'level","'",",","'slim","'",",","'l1","'",",","'l2","'",",","'fpgm","'",",","'taylorfo","'",",","'apoz","'",",","'mean_activation","'","]","`",",","by","default","`","level","`"]
docstr: Calculate the mask of given layer.
  Scale factors with the smallest absolute value in the BN layer are masked.
  Parameters
  ----------
  wrapper : Module
      the layer to instrument the compression operation
  wrapper_idx: int
      index of this wrapper in pruner's all wrappers
  Returns
  -------
  dict | None
      Dictionary for storing masks, keys of the dict:
      'weight_mask':  weight mask tensor
      'bias_mask': bias mask tensor (optional)
docstr_tok: ["Calculate","the","mask","of","given","layer",".","Scale","factors","with","the","smallest","absolute","value","in","the","BN","layer","are","masked",".","Parameters","--","--","--","--","--","wrapper",":","Module","the","layer","to","instrument","the","compression","operation","wrapper_idx",":","int","index","of","this","wrapper","in","pruner","'s","all","wrappers","Returns","--","--","--","-","dict","|","None","Dictionary","for","storing","masks",",","keys","of","the","dict",":","'weight_mask","'",":","weight","mask","tensor","'bias_mask","'",":","bias","mask","tensor","(","optional",")"]
code: def calc_mask(self, wrapper, wrapper_idx=None):
      """
      Calculate the mask of given layer.
      Scale factors with the smallest absolute value in the BN layer are masked.
      Parameters
      ----------
      wrapper : Module
          the layer to instrument the compression operation
      wrapper_idx: int
          index of this wrapper in pruner's all wrappers
      Returns
      -------
      dict | None
          Dictionary for storing masks, keys of the dict:
          'weight_mask':  weight mask tensor
          'bias_mask': bias mask tensor (optional)
      """
  
      config = wrapper.config
  
      start_epoch = config.get("start_epoch", 0)
      freq = config.get("frequency", 1)
  
      if wrapper.if_calculated:
          return None
      if not (
          self.now_epoch >= start_epoch
          and (self.now_epoch - start_epoch) % freq == 0
      ):
          return None
  
      target_sparsity = self.compute_target_sparsity(config)
      new_mask = self.masker.calc_mask(
          sparsity=target_sparsity,
          wrapper=wrapper,
          wrapper_idx=wrapper_idx,
      )
      if new_mask is not None:
          wrapper.if_calculated = True
  
      return new_mask
  
file_path: auptimizer/src/aup/compression/torch/pruning/agp.py
imports: import logging
  import torch
  from schema import And, Optional
  from .constants import MASKER_DICT
  from ..utils.config_validation import CompressorSchema
  from ..compressor import Pruner
label_desc: Use image node_id 3 for calling the AGPPruner obj's underlying member method code with example usage: obj.calc_mask(wrapper, wrapper_idx) and returns: new_mask, None, None