class_docstr: Implementation Parallel 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_rnn_dropout (float): Dropout of RNN layer in decoder.
          Defaults to 0.0.
      dec_gru (bool): If True, use GRU, else LSTM in decoder. Defaults to
          False.
      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.
      d_k (int): Dim of channels of attention module. Defaults to 64.
      pred_dropout (float): Dropout probability of prediction layer. Defaults
          to 0.0.
      max_seq_len (int): Maximum sequence length for decoding. Defaults to
          30.
      mask (bool): If True, mask padding in feature map. Defaults to True.
      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","Parallel","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_rnn_dropout","(","float",")",":","Dropout","of","RNN","layer","in","decoder",".","Defaults","to","0.0.","dec_gru","(","bool",")",":","If","True",",","use","GRU",",","else","LSTM","in","decoder",".","Defaults","to","False",".","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.","d_k","(","int",")",":","Dim","of","channels","of","attention","module",".","Defaults","to","64.","pred_dropout","(","float",")",":","Dropout","probability","of","prediction","layer",".","Defaults","to","0.0.","max_seq_len","(","int",")",":","Maximum","sequence","length","for","decoding",".","Defaults","to","30.","mask","(","bool",")",":","If","True",",","mask","padding","in","feature","map",".","Defaults","to","True",".","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: Sequence[TextRecogDataSample],
  ) -> 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)`.
      """
      if data_samples is not None:
          assert len(data_samples) == feat.size(0)
  
      valid_ratios = (
          [
              img_meta.get("valid_ratio", 1.0)
              for img_meta 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)
      # bsz * seq_len * emb_dim
      out_enc = out_enc.unsqueeze(1)
      # bsz * 1 * emb_dim
      in_dec = torch.cat((out_enc, tgt_embedding), dim=1)
      # bsz * (seq_len + 1) * C
      out_dec = self._2d_attention(
          in_dec, feat, out_enc, valid_ratios=valid_ratios
      )
      # bsz * (seq_len + 1) * num_classes
  
      return out_dec[:, 1:, :]
  
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 ParallelSARDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: out_dec