class_docstr: Multi-head Attention block with relative position embeddings.
class_docstr_tok: ["Multi-head","Attention","block","with","relative","position","embeddings","."]
docstr: Args:
      dim (int): Number of input channels.
      num_heads (int): Number of attention heads.
      qkv_bias (bool:  If True, add a learnable bias to query, key, value.
      rel_pos (bool): If True, add relative positional embeddings to the attention map.
      rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
      input_size (int or None): Input resolution for calculating the relative positional
          parameter size.
docstr_tok: ["Args",":","dim","(","int",")",":","Number","of","input","channels",".","num_heads","(","int",")",":","Number","of","attention","heads",".","qkv_bias","(","bool",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","rel_pos","(","bool",")",":","If","True",",","add","relative","positional","embeddings","to","the","attention","map",".","rel_pos_zero_init","(","bool",")",":","If","True",",","zero","initialize","relative","positional","parameters",".","input_size","(","int","or","None",")",":","Input","resolution","for","calculating","the","relative","positional","parameter","size","."]
code: def __init__(
      self,
      dim: int,
      num_heads: int = 8,
      qkv_bias: bool = True,
      use_rel_pos: bool = False,
      rel_pos_zero_init: bool = True,
      input_size: Optional[Tuple[int, int]] = None,
  ) -> None:
      """
      Args:
          dim (int): Number of input channels.
          num_heads (int): Number of attention heads.
          qkv_bias (bool:  If True, add a learnable bias to query, key, value.
          rel_pos (bool): If True, add relative positional embeddings to the attention map.
          rel_pos_zero_init (bool): If True, zero initialize relative positional parameters.
          input_size (int or None): Input resolution for calculating the relative positional
              parameter size.
      """
      super().__init__()
      self.num_heads = num_heads
      head_dim = dim // num_heads
      self.scale = head_dim**-0.5
  
      self.qkv = nn.Linear(
          dim, dim * 3, bias_attr=qkv_bias if not qkv_bias else None
      )
      self.proj = nn.Linear(dim, dim)
  
      self.use_rel_pos = use_rel_pos
      if self.use_rel_pos:
          assert (
              input_size is not None
          ), "Input size must be provided if using relative positional encoding."
          # initialize relative positional embeddings
          self.rel_pos_h = paddle.create_parameter(
              shape=[2 * input_size[0] - 1, head_dim],
              dtype="float32",
              default_initializer=nn.initializer.Constant(value=0.0),
          )
          self.rel_pos_w = paddle.create_parameter(
              shape=[2 * input_size[1] - 1, head_dim],
              dtype="float32",
              default_initializer=nn.initializer.Constant(value=0.0),
          )
  
imports: import sys
  import os
  from functools import partial
  from typing import Optional, Tuple, Type
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from .common import LayerNorm2d, MLPBlock
label_desc: Use image node_id 1 to create a new Attention object from inherited base classes: nn with example: obj = Attention(dim, num_heads, qkv_bias, use_rel_pos, rel_pos_zero_init, input_size)