class_docstr: Implementation Sequential Decoder module in `SAR.
  
  <https://arxiv.org/abs/1811.00751>`_.
  
  Args:
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`.
      module_loss (dict, optional): Config to build module_loss. Defaults
          to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      enc_bi_rnn (bool): If True, use bidirectional RNN in encoder. Defaults
          to False.
      dec_bi_rnn (bool): If True, use bidirectional RNN in decoder. Defaults
          to False.
      dec_do_rnn (float): Dropout of RNN layer in decoder. Defaults to 0.
      dec_gru (bool): If True, use GRU, else LSTM in decoder. Defaults to
          False.
      d_k (int): Dim of conv layers in attention module. Defaults to 64.
      d_model (int): Dim of channels from backbone :math:`D_i`. Defaults to
          512.
      d_enc (int): Dim of encoder RNN layer :math:`D_m`. Defaults to 512.
      pred_dropout (float): Dropout probability of prediction layer. Defaults
          to 0.
      max_seq_len (int): Maximum sequence length during decoding. Defaults to
          40.
      mask (bool): If True, mask padding in feature map. Defaults to False.
      pred_concat (bool): If True, concat glimpse feature from
          attention with holistic feature and hidden state. Defaults to
          False.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Implementation","Sequential","Decoder","module","in","`","SAR",".","<","https",":","\/\/arxiv.org\/abs\/1811.00751",">","`","_",".","Args",":","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","module_loss","(","dict",",","optional",")",":","Config","to","build","module_loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","enc_bi_rnn","(","bool",")",":","If","True",",","use","bidirectional","RNN","in","encoder",".","Defaults","to","False",".","dec_bi_rnn","(","bool",")",":","If","True",",","use","bidirectional","RNN","in","decoder",".","Defaults","to","False",".","dec_do_rnn","(","float",")",":","Dropout","of","RNN","layer","in","decoder",".","Defaults","to","0.","dec_gru","(","bool",")",":","If","True",",","use","GRU",",","else","LSTM","in","decoder",".","Defaults","to","False",".","d_k","(","int",")",":","Dim","of","conv","layers","in","attention","module",".","Defaults","to","64.","d_model","(","int",")",":","Dim","of","channels","from","backbone",":","math",":","`","D_i","`",".","Defaults","to","512.","d_enc","(","int",")",":","Dim","of","encoder","RNN","layer",":","math",":","`","D_m","`",".","Defaults","to","512.","pred_dropout","(","float",")",":","Dropout","probability","of","prediction","layer",".","Defaults","to","0.","max_seq_len","(","int",")",":","Maximum","sequence","length","during","decoding",".","Defaults","to","40.","mask","(","bool",")",":","If","True",",","mask","padding","in","feature","map",".","Defaults","to","False",".","pred_concat","(","bool",")",":","If","True",",","concat","glimpse","feature","from","attention","with","holistic","feature","and","hidden","state",".","Defaults","to","False",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
docstr: Args:
      feat (Tensor): Tensor of shape :math:`(N, D_i, H, W)`.
      out_enc (Tensor): Encoder output of shape
          :math:`(N, D_m, H, W)`.
      data_samples (list[TextRecogDataSample]): Batch of
          TextRecogDataSample, containing gt_text and valid_ratio
          information.
  
  Returns:
      Tensor: A raw logit tensor of shape :math:`(N, T, C)`.
docstr_tok: ["Args",":","feat","(","Tensor",")",":","Tensor","of","shape",":","math",":","`","(","N",",","D_i",",","H",",","W",")","`",".","out_enc","(","Tensor",")",":","Encoder","output","of","shape",":","math",":","`","(","N",",","D_m",",","H",",","W",")","`",".","data_samples","(","list","[","TextRecogDataSample","]",")",":","Batch","of","TextRecogDataSample",",","containing","gt_text","and","valid_ratio","information",".","Returns",":","Tensor",":","A","raw","logit","tensor","of","shape",":","math",":","`","(","N",",","T",",","C",")","`","."]
code: def forward_train(
      self,
      feat: torch.Tensor,
      out_enc: torch.Tensor,
      data_samples: Optional[Sequence[TextRecogDataSample]] = None,
  ) -> torch.Tensor:
      """
      Args:
          feat (Tensor): Tensor of shape :math:`(N, D_i, H, W)`.
          out_enc (Tensor): Encoder output of shape
              :math:`(N, D_m, H, W)`.
          data_samples (list[TextRecogDataSample]): Batch of
              TextRecogDataSample, containing gt_text and valid_ratio
              information.
  
      Returns:
          Tensor: A raw logit tensor of shape :math:`(N, T, C)`.
      """
      valid_ratios = None
      if data_samples is not None:
          valid_ratios = (
              [
                  data_sample.get("valid_ratio", 1.0)
                  for data_sample in data_samples
              ]
              if self.mask
              else None
          )
  
      padded_targets = [
          data_sample.gt_text.padded_indexes
          for data_sample in data_samples
      ]
      padded_targets = torch.stack(padded_targets, dim=0).to(
          feat.device
      )
      tgt_embedding = self.embedding(padded_targets)
  
      outputs = []
      for i in range(-1, self.max_seq_len):
          if i == -1:
              if self.dec_gru:
                  hx1 = cx1 = self.rnn_decoder_layer1(out_enc)
                  hx2 = cx2 = self.rnn_decoder_layer2(hx1)
              else:
                  hx1, cx1 = self.rnn_decoder_layer1(out_enc)
                  hx2, cx2 = self.rnn_decoder_layer2(hx1)
          else:
              y_prev = tgt_embedding[:, i, :]
              y, hx1, cx1, hx2, cx2 = self._2d_attention(
                  y_prev,
                  feat,
                  out_enc,
                  hx1,
                  cx1,
                  hx2,
                  cx2,
                  valid_ratios=valid_ratios,
              )
              y = self.pred_dropout(y)
  
              outputs.append(y)
  
      outputs = torch.stack(outputs, 1)
  
      return outputs
  
imports: import math
  from typing import Dict, List, Optional, Sequence, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseDecoder
label_desc: Use image node_id 3 for calling the SequentialSARDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: outputs