code: def StackedRNN(inners, num_layers, lstm=False, dropout=0, train=True):
      num_directions = len(inners)
      total_layers = num_layers * num_directions
  
      def forward(
          input,
          hidden,
          weight,
          batch_sizes,
          input_quantizers,
          weight_quantizers,
      ):
          assert len(weight) == total_layers
          next_hidden = []
  
          if lstm:
              hidden = list(zip(*hidden))
  
          for i in range(num_layers):
              all_output = []
              for j, inner in enumerate(inners):
                  l = i * num_directions + j
  
                  hy, output = inner(
                      input,
                      hidden[l],
                      weight[l],
                      batch_sizes,
                      input_quantizer=input_quantizers[l],
                      weight_quantizer=weight_quantizers[l],
                  )
                  next_hidden.append(hy)
                  all_output.append(output)
  
              input = torch.cat(all_output, input.dim() - 1)
  
              if dropout != 0 and i < num_layers - 1:
                  input = F.dropout(
                      input, p=dropout, training=train, inplace=False
                  )
  
          if lstm:
              next_h, next_c = zip(*next_hidden)
              next_hidden = (
                  torch.cat(next_h, 0).view(
                      total_layers, *next_h[0].size()
                  ),
                  torch.cat(next_c, 0).view(
                      total_layers, *next_c[0].size()
                  ),
              )
          else:
              next_hidden = torch.cat(next_hidden, 0).view(
                  total_layers, *next_hidden[0].size()
              )
  
          return next_hidden, input
  
      return forward
  
file_path: lightseq/lightseq/training/pytorch_quantization/nn/_functions/quant_rnn.py
imports: import warnings
  from torch.autograd import NestedIOFunction
  from torch.nn import functional
  import torch
  import itertools
  from functools import partial
label_desc: Use image node_id 5 for calling a global function with example usage: StackedRNN(inners, num_layers, lstm, dropout, train) and returns: forward, next_hidden,  input