code: def window_partition(x, window_size):
      """window partition operation 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
  
       Args:
          x: input tensor.
          window_size: local window size.
      """
      x_shape = x.size()
      if len(x_shape) == 5:
          b, d, h, w, c = x_shape
          x = x.view(
              b,
              d // window_size[0],
              window_size[0],
              h // window_size[1],
              window_size[1],
              w // window_size[2],
              window_size[2],
              c,
          )
          windows = (
              x.permute(0, 1, 3, 5, 2, 4, 6, 7)
              .contiguous()
              .view(
                  -1,
                  window_size[0] * window_size[1] * window_size[2],
                  c,
              )
          )
      elif len(x_shape) == 4:
          b, h, w, c = x.shape
          x = x.view(
              b,
              h // window_size[0],
              window_size[0],
              w // window_size[1],
              window_size[1],
              c,
          )
          windows = (
              x.permute(0, 1, 3, 2, 4, 5)
              .contiguous()
              .view(-1, window_size[0] * window_size[1], c)
          )
      return windows
  
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 1 for calling a global function with example usage: window_partition(x, window_size) and returns: windows