class_docstr: A class to wrap training code.
docstr: Computes the loss for the same batch for M models.
  
  This amounts to an estimate of the loss, which is turned into an
  estimate for the gradients of the shared model.
code: def get_loss(self, inputs, targets, hidden, dags):
      """Computes the loss for the same batch for M models.
  
      This amounts to an estimate of the loss, which is turned into an
      estimate for the gradients of the shared model.
      """
      if not isinstance(dags, list):
          dags = [dags]
  
      loss = 0
      for dag in dags:
          output, hidden, extra_out = self.shared(
              inputs, dag, hidden=hidden
          )
          output_flat = output.view(-1, self.dataset.num_tokens)
          sample_loss = (
              self.ce(output_flat, targets)
              / self.args.shared_num_sample
          )
          loss += sample_loss
  
      assert (
          len(dags) == 1
      ), "there are multiple `hidden` for multple `dags`"
      return loss, hidden, extra_out
  
imports: import contextlib
  import glob
  import math
  import os
  import numpy
  import scipy.signal
  from tensorboard import TensorBoard
  import torch
  from torch import nn
  import torch.nn.parallel
  from torch.autograd import Variable
  import models
  import utils
label_desc: Use image node_id 4 for calling the Trainer obj's underlying member method code with example usage: obj.get_loss(inputs, targets, hidden, dags) and returns: loss,  hidden,  extra_out