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], optional): Batch of
          TextRecogDataSample, containing valid_ratio
          information. Defaults to None.
  
  Returns:
      Tensor: Character probabilities. of shape
      :math:`(N, self.max_seq_len, C)` where :math:`C` is
      ``num_classes``.
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","]",",","optional",")",":","Batch","of","TextRecogDataSample",",","containing","valid_ratio","information",".","Defaults","to","None",".","Returns",":","Tensor",":","Character","probabilities",".","of","shape",":","math",":","`","(","N",",","self.max_seq_len",",","C",")","`","where",":","math",":","`","C","`","is","``","num_classes","``","."]
code: def forward_test(
      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], optional): Batch of
              TextRecogDataSample, containing valid_ratio
              information. Defaults to None.
  
      Returns:
          Tensor: Character probabilities. of shape
          :math:`(N, self.max_seq_len, C)` where :math:`C` is
          ``num_classes``.
      """
      if data_samples is not None:
          assert len(data_samples) == feat.size(0)
  
      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
          )
  
      seq_len = self.max_seq_len
  
      bsz = feat.size(0)
      start_token = torch.full(
          (bsz,), self.start_idx, device=feat.device, dtype=torch.long
      )
      # bsz
      start_token = self.embedding(start_token)
      # bsz * emb_dim
      start_token = start_token.unsqueeze(1).expand(-1, seq_len, -1)
      # bsz * seq_len * emb_dim
      out_enc = out_enc.unsqueeze(1)
      # bsz * 1 * emb_dim
      decoder_input = torch.cat((out_enc, start_token), dim=1)
      # bsz * (seq_len + 1) * emb_dim
  
      outputs = []
      for i in range(1, seq_len + 1):
          decoder_output = self._2d_attention(
              decoder_input, feat, out_enc, valid_ratios=valid_ratios
          )
          char_output = decoder_output[:, i, :]  # bsz * num_classes
          outputs.append(char_output)
          _, max_idx = torch.max(char_output, dim=1, keepdim=False)
          char_embedding = self.embedding(max_idx)  # bsz * emb_dim
          if i < seq_len:
              decoder_input[:, i + 1, :] = char_embedding
  
      outputs = torch.stack(outputs, 1)  # bsz * seq_len * num_classes
  
      return self.softmax(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 4 for calling the ParallelSARDecoder obj's underlying member method code with example usage: obj.forward_test(feat, out_enc, data_samples) and returns: self