code: def __init__(
      self,
      dim,
      key_dim,
      num_heads,
      attn_ratio=4,
      activation=None,
      lr_mult=1.0,
  ):
      super().__init__()
      self.num_heads = num_heads
      self.scale = key_dim**-0.5
      self.key_dim = key_dim
      self.nh_kd = nh_kd = key_dim * num_heads
      self.d = int(attn_ratio * key_dim)
      self.dh = int(attn_ratio * key_dim) * num_heads
      self.attn_ratio = attn_ratio
  
      self.to_q = Conv2DBN(dim, nh_kd, 1, lr_mult=lr_mult)
      self.to_k = Conv2DBN(dim, nh_kd, 1, lr_mult=lr_mult)
      self.to_v = Conv2DBN(dim, self.dh, 1, lr_mult=lr_mult)
  
      self.proj = nn.Sequential(
          activation(),
          Conv2DBN(self.dh, dim, bn_weight_init=0, lr_mult=lr_mult),
      )
  
imports: from functools import partial
  from collections import defaultdict
  import paddle
  import paddle.nn
  import paddle.nn.functional
  import paddleseg
  from paddleseg import utils
  from paddleseg.models import layers
  from paddleseg.cvlibs import manager
  from paddleseg.models.backbones.transformer_utils import Identity, DropPath
  from ppmatting.models.layers import MLFF
  from ppmatting.models.losses import MRSD, GradientLoss
label_desc: Use image node_id 1 to create a new Attention object from inherited base classes: nn with example: obj = Attention(dim, key_dim, num_heads, attn_ratio, activation, lr_mult)