class_docstr: Patch Merging Layer.
  
  Args:
      dim (int): Number of input channels.
      norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm
class_docstr_tok: ["Patch","Merging","Layer",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","norm_layer","(","nn.Module",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm"]
docstr: x: B, H*W, C
docstr_tok: ["x",":","B",",","H","*","W",",","C"]
code: def forward(self, x, H, W):
      """
      x: B, H*W, C
      """
      B, L, C = x.shape
      assert L == H * W, "input feature has wrong size"
  
      x = x.view(B, H, W, C)
  
      # padding
      # 如果输入feature map的H，W不是2的整数倍，需要进行padding
      pad_input = (H % 2 == 1) or (W % 2 == 1)
      if pad_input:
          # to pad the last 3 dimensions, starting from the last dimension and moving forward.
          # (C_front, C_back, W_left, W_right, H_top, H_bottom)
          # 注意这里的Tensor通道是[B, H, W, C]，所以会和官方文档有些不同
          x = F.pad(x, (0, 0, 0, W % 2, 0, H % 2))
  
      x0 = x[:, 0::2, 0::2, :]  # [B, H/2, W/2, C]
      x1 = x[:, 1::2, 0::2, :]  # [B, H/2, W/2, C]
      x2 = x[:, 0::2, 1::2, :]  # [B, H/2, W/2, C]
      x3 = x[:, 1::2, 1::2, :]  # [B, H/2, W/2, C]
      x = torch.cat([x0, x1, x2, x3], -1)  # [B, H/2, W/2, 4*C]
      x = x.view(B, -1, 4 * C)  # [B, H/2*W/2, 4*C]
  
      x = self.norm(x)
      x = self.reduction(x)  # [B, H/2*W/2, 2*C]
  
      return x
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  import numpy
  from typing import Optional
label_desc: Use image node_id 2 for calling the PatchMerging obj's underlying member method code with example usage: obj.forward(x, H, W) and returns: x