class_docstr: An implementation of Spatial Reduction Attention of PVT.
  
  This module is modified from MultiheadAttention which is a module from
  mmcv.cnn.bricks.transformer.
  
  Args:
      embed_dims (int): The embedding dimension.
      num_heads (int): Parallel attention heads.
      attn_drop (float): A Dropout layer on attn_output_weights.
          Default: 0.0.
      proj_drop (float): A Dropout layer after `nn.MultiheadAttention`.
          Default: 0.0.
      dropout_layer (obj:`ConfigDict`): The dropout_layer used
          when adding the shortcut. Default: None.
      batch_first (bool): Key, Query and Value are shape of
          (batch, n, embed_dim)
          or (n, batch, embed_dim). Default: False.
      qkv_bias (bool): enable bias for qkv if True. Default: True.
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='LN').
      sr_ratio (int): The ratio of spatial reduction of Spatial Reduction
          Attention of PVT. Default: 1.
      init_cfg (obj:`mmengine.ConfigDict`): The Config for initialization.
          Default: None.
class_docstr_tok: ["An","implementation","of","Spatial","Reduction","Attention","of","PVT",".","This","module","is","modified","from","MultiheadAttention","which","is","a","module","from","mmcv.cnn.bricks.transformer",".","Args",":","embed_dims","(","int",")",":","The","embedding","dimension",".","num_heads","(","int",")",":","Parallel","attention","heads",".","attn_drop","(","float",")",":","A","Dropout","layer","on","attn_output_weights",".","Default",":","0.0.","proj_drop","(","float",")",":","A","Dropout","layer","after","`","nn.MultiheadAttention","`",".","Default",":","0.0.","dropout_layer","(","obj",":","`","ConfigDict","`",")",":","The","dropout_layer","used","when","adding","the","shortcut",".","Default",":","None",".","batch_first","(","bool",")",":","Key",",","Query","and","Value","are","shape","of","(","batch",",","n",",","embed_dim",")","or","(","n",",","batch",",","embed_dim",")",".","Default",":","False",".","qkv_bias","(","bool",")",":","enable","bias","for","qkv","if","True",".","Default",":","True",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='LN","'",")",".","sr_ratio","(","int",")",":","The","ratio","of","spatial","reduction","of","Spatial","Reduction","Attention","of","PVT",".","Default",":","1.","init_cfg","(","obj",":","`","mmengine.ConfigDict","`",")",":","The","Config","for","initialization",".","Default",":","None","."]
code: def forward(self, x, hw_shape, identity=None):
      x_q = x
      if self.sr_ratio > 1:
          x_kv = nlc_to_nchw(x, hw_shape)
          x_kv = self.sr(x_kv)
          x_kv = nchw_to_nlc(x_kv)
          x_kv = self.norm(x_kv)
      else:
          x_kv = x
  
      if identity is None:
          identity = x_q
  
      # Because the dataflow('key', 'query', 'value') of
      # ``torch.nn.MultiheadAttention`` is (num_queries, batch,
      # embed_dims), We should adjust the shape of dataflow from
      # batch_first (batch, num_queries, embed_dims) to num_queries_first
      # (num_queries ,batch, embed_dims), and recover ``attn_output``
      # from num_queries_first to batch_first.
      if self.batch_first:
          x_q = x_q.transpose(0, 1)
          x_kv = x_kv.transpose(0, 1)
  
      out = self.attn(query=x_q, key=x_kv, value=x_kv)[0]
  
      if self.batch_first:
          out = out.transpose(0, 1)
  
      return identity + self.dropout_layer(self.proj_drop(out))
  
imports: import math
  import warnings
  from collections import OrderedDict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, build_activation_layer, build_norm_layer
  from mmcv.cnn.bricks.drop import build_dropout
  from mmcv.cnn.bricks.transformer import MultiheadAttention
  from mmengine.logging import MMLogger
  from mmengine.model import BaseModule, ModuleList, Sequential, constant_init, normal_init, trunc_normal_init
  from mmengine.model.weight_init import trunc_normal_
  from mmengine.runner.checkpoint import CheckpointLoader, load_state_dict
  from torch.nn.modules.utils import _pair
  from mmdet.registry import MODELS
  from ..layers import PatchEmbed, nchw_to_nlc, nlc_to_nchw
label_desc: Use image node_id 2 for calling the SpatialReductionAttention obj's underlying member method code with example usage: obj.forward(x, hw_shape, identity) and returns: unknown