class_docstr: Patch Merging Layer.
  Args:
      input_resolution (tuple[int]): Resolution of input feature.
      dim (int): Number of input channels.
      norm_layer (nn.Module, optional): Normalization layer.  Default: nn.LayerNorm
class_docstr_tok: ["Patch","Merging","Layer",".","Args",":","input_resolution","(","tuple","[","int","]",")",":","Resolution","of","input","feature",".","dim","(","int",")",":","Number","of","input","channels",".","norm_layer","(","nn.Module",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm"]
docstr: Forward function.
  Args:
      x: Input feature, tensor size (B, H*W, C).
      H, W: Spatial resolution of the input feature.
docstr_tok: ["Forward","function",".","Args",":","x",":","Input","feature",",","tensor","size","(","B",",","H","*","W",",","C",")",".","H",",","W",":","Spatial","resolution","of","the","input","feature","."]
code: def forward(self, x):
      """Forward function.
      Args:
          x: Input feature, tensor size (B, H*W, C).
          H, W: Spatial resolution of the input feature.
      """
      B, L, C = x.shape
      H = int(sqrt(L))
      W = H
  
      x = x.view(B, H, W, C)
  
      # padding
      pad_input = (H % 2 == 1) or (W % 2 == 1)
      if pad_input:
          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)
  
      return x
  
imports: import os
  import logging
  import torch
  import torch.nn
  import torch.nn.functional
  from functools import partial
  import torch.distributed
  from torch.nn.init import trunc_normal_
  from megatron.model.transformer import DropPath
  from megatron import get_args
  from megatron.model import LayerNorm
  import numpy
  from math import sqrt
label_desc: Use image node_id 2 for calling the PatchMerging obj's underlying member method code with example usage: obj.forward(x) and returns: x