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 training the model for one epoch
docstr_tok: ["Function","used","for","training","the","model","for","one","epoch"]
code: def train_model(self):
      """
      Function used for training the model for one epoch
      """
  
      epoch_loss = 0.0
      correct = 0
      length_of_dataset = len(self.train_loader.dataset)
  
      for data, label in self.train_loader:
          data = data.to(self.device)
          label = label.to(self.device)
  
          out = self.model(data)
          if isinstance(out, tuple):
              out = out[0]
  
          loss = self.loss_fn(out, label)
  
          pred = out.argmax(dim=1, keepdim=True)
          correct += pred.eq(label.view_as(pred)).sum().item()
  
          self.optimizer.zero_grad()
          loss.backward()
  
          self.zero_pruned_gradients()
          self.optimizer.step()
  
          epoch_loss += loss.item()
  
      epoch_loss /= length_of_dataset
      epoch_acc = 100 * (correct / length_of_dataset)
      return epoch_loss, epoch_acc
  
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 2 for calling the BaseIterativePruner obj's underlying member method code with example usage: obj.train_model() and returns: epoch_loss,  epoch_acc