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 sparsity for pruning
  Parameters
  ----------
  config : dict
      Layer's pruning config
  Returns
  -------
  float
      Target sparsity to be pruned
docstr_tok: ["Calculate","the","sparsity","for","pruning","Parameters","--","--","--","--","--","config",":","dict","Layer","'s","pruning","config","Returns","--","--","--","-","float","Target","sparsity","to","be","pruned"]
code: def compute_target_sparsity(self, config):
      """
      Calculate the sparsity for pruning
      Parameters
      ----------
      config : dict
          Layer's pruning config
      Returns
      -------
      float
          Target sparsity to be pruned
      """
  
      end_epoch = config.get("end_epoch", 1)
      start_epoch = config.get("start_epoch", 0)
      freq = config.get("frequency", 1)
      final_sparsity = config.get("final_sparsity", 0)
      initial_sparsity = config.get("initial_sparsity", 0)
      if end_epoch <= start_epoch or initial_sparsity >= final_sparsity:
          logger.warning(
              "your end epoch <= start epoch or initial_sparsity >= final_sparsity"
          )
          return final_sparsity
  
      if end_epoch <= self.now_epoch:
          return final_sparsity
  
      span = ((end_epoch - start_epoch - 1) // freq) * freq
      assert span > 0
      target_sparsity = (
          final_sparsity
          + (initial_sparsity - final_sparsity)
          * (1.0 - ((self.now_epoch - start_epoch) / span)) ** 3
      )
      return target_sparsity
  
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 4 for calling the AGPPruner obj's underlying member method code with example usage: obj.compute_target_sparsity(config) and returns: target_sparsity, final_sparsity, final_sparsity