class_docstr: TinyViT Block.
  
  Args:
      dim (int): Number of input channels.
      input_resolution (tuple[int, int]): Input resolution.
      num_heads (int): Number of attention heads.
      window_size (int): Window size.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
      drop (float, optional): Dropout rate. Default: 0.0
      drop_path (float, optional): Stochastic depth rate. Default: 0.0
      local_conv_size (int): the kernel size of the convolution between
                             Attention and MLP. Default: 3
      activation: the activation function. Default: nn.GELU
class_docstr_tok: ["TinyViT","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","input_resolution","(","tuple","[","int",",","int","]",")",":","Input","resolution",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","Window","size",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","drop","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.0","drop_path","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","local_conv_size","(","int",")",":","the","kernel","size","of","the","convolution","between","Attention","and","MLP",".","Default",":","3","activation",":","the","activation","function",".","Default",":","nn.GELU"]
code: def forward(self, x):
      H, W = self.input_resolution
      B, L, C = x.shape
      assert L == H * W, "input feature has wrong size"
      res_x = x
      if H == self.window_size and W == self.window_size:
          x = self.attn(x)
      else:
          x = x.reshape((B, H, W, C))
          pad_b = (
              self.window_size - H % self.window_size
          ) % self.window_size
          pad_r = (
              self.window_size - W % self.window_size
          ) % self.window_size
          padding = pad_b > 0 or pad_r > 0
  
          if padding:
              x = F.pad(x, (0, 0, 0, pad_r, 0, pad_b, 0, 0))
  
          pH, pW = H + pad_b, W + pad_r
          nH = pH // self.window_size
          nW = pW // self.window_size
          # window partition
          x = (
              x.reshape(
                  (B, nH, self.window_size, nW, self.window_size, C)
              )
              .transpose((0, 1, 3, 2, 4, 5))
              .reshape(
                  (B * nH * nW, self.window_size * self.window_size, C)
              )
          )
          x = self.attn(x)
          # window reverse
          x = (
              x.reshape(
                  (B, nH, nW, self.window_size, self.window_size, C)
              )
              .transpose((0, 1, 3, 2, 4, 5))
              .reshape((B, pH, pW, C))
          )
  
          if padding:
              x = x[:, :H, :W]
  
          x = x.reshape((B, L, C))
  
      # x = res_x + self.drop_path(x)
      x = res_x + x
  
      x = x.transpose((0, 2, 1)).reshape((B, C, H, W))
      x = self.local_conv(x)
      x = x.reshape((B, C, L)).transpose((0, 2, 1))
  
      # x = x + self.drop_path(self.mlp(x))
      x = x + self.mlp(x)
      return x
  
imports: import itertools
  import paddle
  from paddle import nn
  from paddle.nn import functional
  from .common import LayerNorm2d
label_desc: Use image node_id 2 for calling the TinyViTBlock obj's underlying member method code with example usage: obj.forward(x) and returns: x