docstr: Loss function and optimizer for single device
  
  Parameters
  ----------
  criterion: torch.nn.Module
      criterion to compute loss
  grad_accum: int
      number of batches to accumulate gradients
  opt: Optimizer
      Model optimizer to use. If None, then no backward and update will be
      performed
docstr_tok: ["Loss","function","and","optimizer","for","single","device","Parameters","--","--","--","--","--","criterion",":","torch.nn.Module","criterion","to","compute","loss","grad_accum",":","int","number","of","batches","to","accumulate","gradients","opt",":","Optimizer","Model","optimizer","to","use",".","If","None",",","then","no","backward","and","update","will","be","performed"]
code: def __init__(self, criterion, grad_accum, opt=None):
      """Loss function and optimizer for single device
  
      Parameters
      ----------
      criterion: torch.nn.Module
          criterion to compute loss
      grad_accum: int
          number of batches to accumulate gradients
      opt: Optimizer
          Model optimizer to use. If None, then no backward and update will be
          performed
      """
      super(SimpleLossCompute, self).__init__()
      self.criterion = criterion
      self.opt = opt
      self.acc_loss = 0
      self.n_correct = 0
      self.norm_term = 0
      self.loss = 0
      self.batch_count = 0
      self.grad_accum = grad_accum
  
imports: import torch
  import torch.distributed
  import torch.nn
  import torch.nn.functional
label_desc: Use image node_id 1 to create a new SimpleLossCompute object from inherited base classes: nn with example: obj = SimpleLossCompute(criterion, grad_accum, opt)