class_docstr: Implement transformer encoder for text recognition, modified from
  `<https://github.com/FangShancheng/ABINet>`.
  
  Args:
      n_layers (int): Number of attention layers. Defaults to 2.
      n_head (int): Number of parallel attention heads. Defaults to 8.
      d_model (int): Dimension :math:`D_m` of the input from previous model.
          Defaults to 512.
      d_inner (int): Hidden dimension of feedforward layers. Defaults to
          2048.
      dropout (float): Dropout rate. Defaults to 0.1.
      max_len (int): Maximum output sequence length :math:`T`. Defaults to
          8 * 32.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
docstr: Args:
      feature (Tensor): Feature tensor of shape :math:`(N, D_m, H, W)`.
      data_samples (List[TextRecogDataSample]): List of data samples.
  
  Returns:
      Tensor: Features of shape :math:`(N, D_m, H, W)`.
code: def forward(
      self,
      feature: torch.Tensor,
      data_samples: List[TextRecogDataSample],
  ) -> torch.Tensor:
      """
      Args:
          feature (Tensor): Feature tensor of shape :math:`(N, D_m, H, W)`.
          data_samples (List[TextRecogDataSample]): List of data samples.
  
      Returns:
          Tensor: Features of shape :math:`(N, D_m, H, W)`.
      """
      n, c, h, w = feature.shape
      feature = feature.view(n, c, -1).transpose(1, 2)  # (n, h*w, c)
      feature = self.pos_encoder(feature)  # (n, h*w, c)
      feature = feature.transpose(0, 1)  # (h*w, n, c)
      for m in self.transformer:
          feature = m(feature)
      feature = feature.permute(1, 2, 0).view(n, c, h, w)
      return feature
  
file_path: mmocr/mmocr/models/textrecog/encoders/abi_encoder.py
imports: import copy
  from typing import Dict, List, Optional, Union
  import torch
  from mmcv.cnn.bricks.transformer import BaseTransformerLayer
  from mmengine.model import BaseModule, ModuleList
  from mmocr.models.common.modules import PositionalEncoding
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
label_desc: Use image node_id 2 for calling the ABIEncoder obj's underlying member method code with example usage: obj.forward(feature, data_samples) and returns: feature