class_docstr: Shared RNN model.
class_docstr_tok: ["Shared","RNN","model","."]
code: def forward(
      self,  # pylint:disable=arguments-differ
      inputs,
      dag,
      hidden=None,
      is_train=True,
  ):
      time_steps = inputs.size(0)
      batch_size = inputs.size(1)
  
      is_train = is_train and self.args.mode in ["train"]
  
      self.w_hh = _get_dropped_weights(
          self.w_hh_raw, self.args.shared_wdrop, self.training
      )
      self.w_hc = _get_dropped_weights(
          self.w_hc_raw, self.args.shared_wdrop, self.training
      )
  
      if hidden is None:
          hidden = self.static_init_hidden[batch_size]
  
      embed = self.encoder(inputs)
  
      if self.args.shared_dropouti > 0:
          embed = self.lockdrop(
              embed, self.args.shared_dropouti if is_train else 0
          )
  
      # TODO(brendan): The norm of hidden states are clipped here because
      # otherwise ENAS is especially prone to exploding activations on the
      # forward pass. This could probably be fixed in a more elegant way, but
      # it might be exposing a weakness in the ENAS algorithm as currently
      # proposed.
      #
      # For more details, see
      # https://github.com/carpedm20/ENAS-pytorch/issues/6
      clipped_num = 0
      max_clipped_norm = 0
      h1tohT = []
      logits = []
      for step in range(time_steps):
          x_t = embed[step]
          logit, hidden = self.cell(x_t, hidden, dag)
  
          hidden_norms = hidden.norm(dim=-1)
          max_norm = 25.0
          if hidden_norms.data.max() > max_norm:
              # TODO(brendan): Just directly use the torch slice operations
              # in PyTorch v0.4.
              #
              # This workaround for PyTorch v0.3.1 does everything in numpy,
              # because the PyTorch slicing and slice assignment is too
              # flaky.
              hidden_norms = hidden_norms.data.cpu().numpy()
  
              clipped_num += 1
              if hidden_norms.max() > max_clipped_norm:
                  max_clipped_norm = hidden_norms.max()
  
              clip_select = hidden_norms > max_norm
              clip_norms = hidden_norms[clip_select]
  
              mask = np.ones(hidden.size())
              normalizer = max_norm / clip_norms
              normalizer = normalizer[:, np.newaxis]
  
              mask[clip_select] = normalizer
              hidden *= torch.autograd.Variable(
                  torch.FloatTensor(mask).cuda(), requires_grad=False
              )
  
          logits.append(logit)
          h1tohT.append(hidden)
  
      if clipped_num > 0:
          logger.info(
              f"clipped {clipped_num} hidden states in one forward "
              f"pass. "
              f"max clipped hidden state norm: {max_clipped_norm}"
          )
  
      h1tohT = torch.stack(h1tohT)
      output = torch.stack(logits)
      raw_output = output
      if self.args.shared_dropout > 0:
          output = self.lockdrop(
              output, self.args.shared_dropout if is_train else 0
          )
  
      dropped_output = output
  
      decoded = self.decoder(
          output.view(output.size(0) * output.size(1), output.size(2))
      )
      decoded = decoded.view(
          output.size(0), output.size(1), decoded.size(1)
      )
  
      extra_out = {
          "dropped": dropped_output,
          "hiddens": h1tohT,
          "raw": raw_output,
      }
      return decoded, hidden, extra_out
  
imports: import numpy
  import collections
  import torch
  from torch import nn
  import torch.nn.functional
  from torch.autograd import Variable
  import models.shared_base
  import utils
label_desc: Use image node_id 2 for calling the RNN obj's underlying member method code with example usage: obj.forward(inputs, dag, hidden, is_train) and returns: decoded,  hidden,  extra_out