code: def add_decomposed_rel_pos(
      attn: paddle.Tensor,
      q: paddle.Tensor,
      rel_pos_h: paddle.Tensor,
      rel_pos_w: paddle.Tensor,
      q_size: Tuple[int, int],
      k_size: Tuple[int, int],
  ) -> paddle.Tensor:
      """
      Calculate decomposed Relative Positional Embeddings from :paper:`mvitv2`.
      https://github.com/facebookresearch/mvit/blob/19786631e330df9f3622e5402b4a419a263a2c80/mvit/models/attention.py   # noqa B950
      Args:
          attn (Tensor): attention map.
          q (Tensor): query q in the attention layer with shape (B, q_h * q_w, C).
          rel_pos_h (Tensor): relative position embeddings (Lh, C) for height axis.
          rel_pos_w (Tensor): relative position embeddings (Lw, C) for width axis.
          q_size (Tuple): spatial sequence size of query q with (q_h, q_w).
          k_size (Tuple): spatial sequence size of key k with (k_h, k_w).
  
      Returns:
          attn (Tensor): attention map with added relative positional embeddings.
      """
      q_h, q_w = q_size
      k_h, k_w = k_size
      Rh = get_rel_pos(q_h, k_h, rel_pos_h)
      Rw = get_rel_pos(q_w, k_w, rel_pos_w)
  
      B, _, dim = q.shape
      r_q = q.reshape([B, q_h, q_w, dim])
      rel_h = paddle.einsum("bhwc,hkc->bhwk", r_q, Rh)
      rel_w = paddle.einsum("bhwc,wkc->bhwk", r_q, Rw)
  
      attn = (
          attn.reshape([B, q_h, q_w, k_h, k_w])
          + rel_h[:, :, :, :, None]
          + rel_w[:, :, :, None, :]
      ).reshape([B, q_h * q_w, k_h * k_w])
  
      return attn
  
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 4 for calling a global function with example usage: add_decomposed_rel_pos(attn, q, rel_pos_h, rel_pos_w, q_size, k_size) and returns: attn