code: def __init__(
      self,
      in_dim,
      out_dim,
      key_dim,
      num_heads=8,
      attn_ratio=2,
      activation=None,
      stride=2,
      resolution=14,
      resolution_=7,
  ):
      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) * self.num_heads
      self.attn_ratio = attn_ratio
      self.resolution_ = resolution_
      self.resolution_2 = resolution_**2
      self.training = True
      h = self.dh + nh_kd
      self.kv = Linear_BN(in_dim, h)
  
      self.q = nn.Sequential(
          Subsample(stride, resolution), Linear_BN(in_dim, nh_kd)
      )
      self.proj = nn.Sequential(
          activation(), Linear_BN(self.dh, out_dim)
      )
  
      self.stride = stride
      self.resolution = resolution
      points = list(
          itertools.product(range(resolution), range(resolution))
      )
      points_ = list(
          itertools.product(range(resolution_), range(resolution_))
      )
  
      N = len(points)
      N_ = len(points_)
      attention_offsets = {}
      idxs = []
      i = 0
      j = 0
      for p1 in points_:
          i += 1
          for p2 in points:
              j += 1
              size = 1
              offset = (
                  abs(p1[0] * stride - p2[0] + (size - 1) / 2),
                  abs(p1[1] * stride - p2[1] + (size - 1) / 2),
              )
              if offset not in attention_offsets:
                  attention_offsets[offset] = len(attention_offsets)
              idxs.append(attention_offsets[offset])
      self.attention_biases = self.create_parameter(
          shape=(num_heads, len(attention_offsets)),
          default_initializer=zeros_,
          attr=paddle.ParamAttr(regularizer=L2Decay(0.0)),
      )
  
      tensor_idxs_ = paddle.to_tensor(idxs, dtype="int64")
      self.register_buffer(
          "attention_bias_idxs", paddle.reshape(tensor_idxs_, [N_, N])
      )
  
imports: import itertools
  import math
  import warnings
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Constant
  from paddle.nn.initializer import TruncatedNormal
  from paddle.regularizer import L2Decay
  from .vision_transformer import Identity
  from .vision_transformer import ones_
  from .vision_transformer import trunc_normal_
  from .vision_transformer import zeros_
label_desc: Use image node_id 1 to create a new AttentionSubsample object from inherited base classes: nn with example: obj = AttentionSubsample(in_dim, out_dim, key_dim, num_heads, attn_ratio, activation, stride, resolution, resolution_)