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))
            # self.rel_pos_h = nn.Parameter(paddle.zeros(2 * input_size[0] - 1, head_dim))
            # self.rel_pos_w = nn.Parameter(paddle.zeros(2 * input_size[1] - 1, head_dim))

        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.
        
contrib/SegmentAnything/segment_anything/modeling/image_encoder.py