class_docstr: Wrapper for normal RNN Cells, make it support variational dropout
class_docstr_tok: ["Wrapper","for","normal","RNN","Cells",",","make","it","support","variational","dropout"]
docstr: :param PackedSequence input_x: [seq_len, batch_size, input_size]
  :param hidden: for LSTM, tuple of (h_0, c_0), [batch_size, hidden_size]
      for other RNN, h_0, [batch_size, hidden_size]
  :param mask_x: [batch_size, input_size] dropout mask for input
  :param mask_h: [batch_size, hidden_size] dropout mask for hidden
  :return PackedSequence output: [seq_len, bacth_size, hidden_size]
          hidden: for LSTM, tuple of (h_n, c_n), [batch_size, hidden_size]
                  for other RNN, h_n, [batch_size, hidden_size]
docstr_tok: [":","param","PackedSequence","input_x",":","[","seq_len",",","batch_size",",","input_size","]",":","param","hidden",":","for","LSTM",",","tuple","of","(","h_0",",","c_0",")",",","[","batch_size",",","hidden_size","]","for","other","RNN",",","h_0",",","[","batch_size",",","hidden_size","]",":","param","mask_x",":","[","batch_size",",","input_size","]","dropout","mask","for","input",":","param","mask_h",":","[","batch_size",",","hidden_size","]","dropout","mask","for","hidden",":","return","PackedSequence","output",":","[","seq_len",",","bacth_size",",","hidden_size","]","hidden",":","for","LSTM",",","tuple","of","(","h_n",",","c_n",")",",","[","batch_size",",","hidden_size","]","for","other","RNN",",","h_n",",","[","batch_size",",","hidden_size","]"]
code: def forward(self, input_x, hidden, mask_x, mask_h, is_reversed=False):
      r"""
      :param PackedSequence input_x: [seq_len, batch_size, input_size]
      :param hidden: for LSTM, tuple of (h_0, c_0), [batch_size, hidden_size]
          for other RNN, h_0, [batch_size, hidden_size]
      :param mask_x: [batch_size, input_size] dropout mask for input
      :param mask_h: [batch_size, hidden_size] dropout mask for hidden
      :return PackedSequence output: [seq_len, bacth_size, hidden_size]
              hidden: for LSTM, tuple of (h_n, c_n), [batch_size, hidden_size]
                      for other RNN, h_n, [batch_size, hidden_size]
      """
  
      def get_hi(hi, h0, size):
          h0_size = size - hi.size(0)
          if h0_size > 0:
              return torch.cat([hi, h0[:h0_size]], dim=0)
          return hi[:size]
  
      is_lstm = isinstance(hidden, tuple)
      input, batch_sizes = input_x.data, input_x.batch_sizes
      output = []
      cell = self.cell
      if is_reversed:
          batch_iter = flip(batch_sizes, [0])
          idx = input.size(0)
      else:
          batch_iter = batch_sizes
          idx = 0
  
      if is_lstm:
          hn = (hidden[0].clone(), hidden[1].clone())
      else:
          hn = hidden.clone()
      hi = hidden
      for size in batch_iter:
          if is_reversed:
              input_i = input[idx - size : idx] * mask_x[:size]
              idx -= size
          else:
              input_i = input[idx : idx + size] * mask_x[:size]
              idx += size
          mask_hi = mask_h[:size]
          if is_lstm:
              hx, cx = hi
              hi = (
                  get_hi(hx, hidden[0], size) * mask_hi,
                  get_hi(cx, hidden[1], size),
              )
              hi = cell(input_i, hi)
              hn[0][:size] = hi[0]
              hn[1][:size] = hi[1]
              output.append(hi[0])
          else:
              hi = get_hi(hi, hidden, size) * mask_hi
              hi = cell(input_i, hi)
              hn[:size] = hi
              output.append(hi)
  
      if is_reversed:
          output = list(reversed(output))
      output = torch.cat(output, dim=0)
      return PackedSequence(output, batch_sizes), hn
  
imports: import torch
  import torch.nn
  from torch.nn.utils.rnn import PackedSequence, pack_padded_sequence, pad_packed_sequence
label_desc: Use image node_id 2 for calling the VarRnnCellWrapper obj's underlying member method code with example usage: obj.forward(input_x, hidden, mask_x, mask_h, is_reversed) and returns: PackedSequence,  hn, hi, torch