class_docstr: Patch merging layer based on: "Liu et al.,
  Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  <https://arxiv.org/abs/2103.14030>"
  https://github.com/microsoft/Swin-Transformer
code: def forward(self, x):
      x_shape = x.size()
      if len(x_shape) == 5:
          b, d, h, w, c = x_shape
          pad_input = (h % 2 == 1) or (w % 2 == 1) or (d % 2 == 1)
          if pad_input:
              x = F.pad(x, (0, 0, 0, w % 2, 0, h % 2, 0, d % 2))
          x = torch.cat(
              [
                  x[:, i::2, j::2, k::2, :]
                  for i, j, k in itertools.product(
                      range(2), range(2), range(2)
                  )
              ],
              -1,
          )
  
      elif len(x_shape) == 4:
          b, h, w, c = x_shape
          pad_input = (h % 2 == 1) or (w % 2 == 1)
          if pad_input:
              x = F.pad(x, (0, 0, 0, w % 2, 0, h % 2))
          x = torch.cat(
              [
                  x[:, j::2, i::2, :]
                  for i, j in itertools.product(range(2), range(2))
              ],
              -1,
          )
  
      x = self.norm(x)
      x = self.reduction(x)
      return x
  
imports: from __future__ import annotations
  import itertools
  from collections.abc import Sequence
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch.nn import LayerNorm
  from typing_extensions import Final
  from monai.networks.blocks import MLPBlock
  from monai.networks.blocks import PatchEmbed, UnetOutBlock, UnetrBasicBlock, UnetrUpBlock
  from monai.networks.layers import DropPath, trunc_normal_
  from monai.utils import ensure_tuple_rep, look_up_option, optional_import
  from monai.utils.deprecate_utils import deprecated_arg
label_desc: Use image node_id 2 for calling the PatchMergingV2 obj's underlying member method code with example usage: obj.forward(x) and returns: x