class_docstr: Implementation of a Basic Iterative Pruner.
  Any iterative pruning technique can be extended from this by implementing the `prune_model` method.
  
  :param model: Model that needs to be pruned
  :type model: torch.nn.Module
  :param train_loader: Dataloader for training
  :type train_loader: torch.utils.data.DataLoader
  :param test_loader: Dataloader for validation/testing
  :type test_loader: torch.utils.data.DataLoader
  :param loss_fn: Loss function to be used for training
  :type loss_fn: torch.nn.Module
  :param device: Device used for implementation ("cpu" by default)
  :type device: torch.device
class_docstr_tok: ["Implementation","of","a","Basic","Iterative","Pruner",".","Any","iterative","pruning","technique","can","be","extended","from","this","by","implementing","the","`","prune_model","`","method",".",":","param","model",":","Model","that","needs","to","be","pruned",":","type","model",":","torch.nn.Module",":","param","train_loader",":","Dataloader","for","training",":","type","train_loader",":","torch.utils.data.DataLoader",":","param","test_loader",":","Dataloader","for","validation\/testing",":","type","test_loader",":","torch.utils.data.DataLoader",":","param","loss_fn",":","Loss","function","to","be","used","for","training",":","type","loss_fn",":","torch.nn.Module",":","param","device",":","Device","used","for","implementation","(","``","cpu","''","by","default",")",":","type","device",":","torch.device"]
docstr: Function used for priniting layer-wise pruning statistics
  
  :param model_path: Path of the model whose statistics need to be displayed
                      If None, statistics of the final model is displayed
  :type model_path: str
  :param verbose: If true, the entire statistics is printed
  :type verbose: bool
  
  :return alive: If model_path is specified, percentage of alive neurons is returned.
                  If model_path is None and saved_models are available, returns a list
                  containing alive neurons percentage for each saved model
                  Else returns -1
  :type alive: int or list
docstr_tok: ["Function","used","for","priniting","layer-wise","pruning","statistics",":","param","model_path",":","Path","of","the","model","whose","statistics","need","to","be","displayed","If","None",",","statistics","of","the","final","model","is","displayed",":","type","model_path",":","str",":","param","verbose",":","If","true",",","the","entire","statistics","is","printed",":","type","verbose",":","bool",":","return","alive",":","If","model_path","is","specified",",","percentage","of","alive","neurons","is","returned",".","If","model_path","is","None","and","saved_models","are","available",",","returns","a","list","containing","alive","neurons","percentage","for","each","saved","model","Else","returns","-1",":","type","alive",":","int","or","list"]
code: def get_pruning_statistics(self, model_path=None, verbose=True):
      """
      Function used for priniting layer-wise pruning statistics
  
      :param model_path: Path of the model whose statistics need to be displayed
                          If None, statistics of the final model is displayed
      :type model_path: str
      :param verbose: If true, the entire statistics is printed
      :type verbose: bool
  
      :return alive: If model_path is specified, percentage of alive neurons is returned.
                      If model_path is None and saved_models are available, returns a list
                      containing alive neurons percentage for each saved model
                      Else returns -1
      :type alive: int or list
      """
  
      model = copy.deepcopy(self.model)
      if model_path:
          model.load_state_dict(torch.load(model_path))
      nonzero = total = 0
      for name, p in model.named_parameters():
          tensor = p.data.cpu().numpy()
          nz_count = np.count_nonzero(tensor)
          total_params = np.prod(tensor.shape)
          nonzero += nz_count
          total += total_params
          if verbose:
              print(
                  f"{name:20} | nonzeros = {nz_count:7} / {total_params:7} ({100 * nz_count / total_params:6.2f}%) | total_pruned = {total_params - nz_count :7} | shape = {tensor.shape}"
              )
      if verbose:
          print(
              f"alive: {nonzero}, pruned : {total - nonzero}, total: {total}, Compression rate : {total/nonzero:10.2f}x  ({100 * (total-nonzero) / total:6.2f}% pruned)"
          )
      return round((nonzero / total) * 100, 1)
  
file_path: KD_Lib/KD_Lib/Pruning/common/iterative_base_class.py
imports: import copy
  import numpy
  import torch
  import torch.nn
label_desc: Use image node_id 8 for calling the BaseIterativePruner obj's underlying member method code with example usage: obj.get_pruning_statistics(model_path, verbose) and returns: round