class_docstr: Decoder module in `MASTER <https://arxiv.org/abs/1910.02562>`_.
  
  Code is partially modified from https://github.com/wenwenyu/MASTER-pytorch.
  
  Args:
      n_layers (int): Number of attention layers. Defaults to 3.
      n_head (int): Number of parallel attention heads. Defaults to 8.
      d_model (int): Dimension :math:`E` of the input from previous model.
          Defaults to 512.
      feat_size (int): The size of the input feature from previous model,
          usually :math:`H * W`. Defaults to 6 * 40.
      d_inner (int): Hidden dimension of feedforward layers.
          Defaults to 2048.
      attn_drop (float): Dropout rate of the attention layer. Defaults to 0.
      ffn_drop (float): Dropout rate of the feedforward layer. Defaults to 0.
      feat_pe_drop (float): Dropout rate of the feature positional encoding
          layer. Defaults to 0.2.
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`. Defaults to None.
      module_loss (dict, optional): Config to build module_loss. Defaults
          to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      max_seq_len (int): Maximum output sequence length :math:`T`. Defaults
          to 30.
      init_cfg (dict or list[dict], optional): Initialization configs.
class_docstr_tok: ["Decoder","module","in","`","MASTER","<","https",":","\/\/arxiv.org\/abs\/1910.02562",">","`","_",".","Code","is","partially","modified","from","https",":","\/\/github.com\/wenwenyu\/MASTER-pytorch",".","Args",":","n_layers","(","int",")",":","Number","of","attention","layers",".","Defaults","to","3.","n_head","(","int",")",":","Number","of","parallel","attention","heads",".","Defaults","to","8.","d_model","(","int",")",":","Dimension",":","math",":","`","E","`","of","the","input","from","previous","model",".","Defaults","to","512.","feat_size","(","int",")",":","The","size","of","the","input","feature","from","previous","model",",","usually",":","math",":","`","H","*","W","`",".","Defaults","to","6","*","40.","d_inner","(","int",")",":","Hidden","dimension","of","feedforward","layers",".","Defaults","to","2048.","attn_drop","(","float",")",":","Dropout","rate","of","the","attention","layer",".","Defaults","to","0.","ffn_drop","(","float",")",":","Dropout","rate","of","the","feedforward","layer",".","Defaults","to","0.","feat_pe_drop","(","float",")",":","Dropout","rate","of","the","feature","positional","encoding","layer",".","Defaults","to","0.2.","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","Defaults","to","None",".","module_loss","(","dict",",","optional",")",":","Config","to","build","module_loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","max_seq_len","(","int",")",":","Maximum","output","sequence","length",":","math",":","`","T","`",".","Defaults","to","30.","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs","."]
docstr: Forward for training. Source mask will not be used here.
  
  Args:
      feat (Tensor, optional): Input feature map from backbone.
      out_enc (Tensor): Unused.
      data_samples (list[TextRecogDataSample]): Batch of
          TextRecogDataSample, containing gt_text and valid_ratio
          information.
  
  Returns:
      Tensor: The raw logit tensor. Shape :math:`(N, T, C)` where
      :math:`C` is ``num_classes``.
docstr_tok: ["Forward","for","training",".","Source","mask","will","not","be","used","here",".","Args",":","feat","(","Tensor",",","optional",")",":","Input","feature","map","from","backbone",".","out_enc","(","Tensor",")",":","Unused",".","data_samples","(","list","[","TextRecogDataSample","]",")",":","Batch","of","TextRecogDataSample",",","containing","gt_text","and","valid_ratio","information",".","Returns",":","Tensor",":","The","raw","logit","tensor",".","Shape",":","math",":","`","(","N",",","T",",","C",")","`","where",":","math",":","`","C","`","is","``","num_classes","``","."]
code: def forward_train(
      self,
      feat: Optional[torch.Tensor] = None,
      out_enc: torch.Tensor = None,
      data_samples: Sequence[TextRecogDataSample] = None,
  ) -> torch.Tensor:
      """Forward for training. Source mask will not be used here.
  
      Args:
          feat (Tensor, optional): Input feature map from backbone.
          out_enc (Tensor): Unused.
          data_samples (list[TextRecogDataSample]): Batch of
              TextRecogDataSample, containing gt_text and valid_ratio
              information.
  
      Returns:
          Tensor: The raw logit tensor. Shape :math:`(N, T, C)` where
          :math:`C` is ``num_classes``.
      """
  
      # flatten 2D feature map
      if len(feat.shape) > 3:
          b, c, h, w = feat.shape
          feat = feat.view(b, c, h * w)
          feat = feat.permute((0, 2, 1))
      feat = self.feat_positional_encoding(feat)
  
      trg_seq = []
      for target in data_samples:
          trg_seq.append(target.gt_text.padded_indexes.to(feat.device))
  
      trg_seq = torch.stack(trg_seq, dim=0)
  
      src_mask = None
      tgt_mask = self.make_target_mask(trg_seq, device=feat.device)
      return self.decode(trg_seq, feat, src_mask, tgt_mask)
  
imports: import copy
  import math
  from typing import Dict, Optional, Sequence, Union
  import torch
  import torch.nn
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer
  from mmengine.model import ModuleList
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.models.common.modules import PositionalEncoding
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseDecoder
label_desc: Use image node_id 4 for calling the MasterDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: self