code: def gen_relative_position_index(
      window_size: Tuple[int, int]
  ) -> torch.Tensor:
      num_relative_distance = (2 * window_size[0] - 1) * (
          2 * window_size[1] - 1
      ) + 3
      # cls to token & token 2 cls & cls to cls
      # get pair-wise relative position index for each token inside the window
      window_area = window_size[0] * window_size[1]
      coords = torch.stack(
          torch.meshgrid(
              [
                  torch.arange(window_size[0]),
                  torch.arange(window_size[1]),
              ]
          )
      )  # 2, Wh, Ww
      coords_flatten = torch.flatten(coords, 1)  # 2, Wh*Ww
      relative_coords = (
          coords_flatten[:, :, None] - coords_flatten[:, None, :]
      )  # 2, Wh*Ww, Wh*Ww
      relative_coords = relative_coords.permute(
          1, 2, 0
      ).contiguous()  # Wh*Ww, Wh*Ww, 2
      relative_coords[:, :, 0] += (
          window_size[0] - 1
      )  # shift to start from 0
      relative_coords[:, :, 1] += window_size[1] - 1
      relative_coords[:, :, 0] *= 2 * window_size[1] - 1
      relative_position_index = torch.zeros(
          size=(window_area + 1,) * 2, dtype=relative_coords.dtype
      )
      relative_position_index[1:, 1:] = relative_coords.sum(
          -1
      )  # Wh*Ww, Wh*Ww
      relative_position_index[0, 0:] = num_relative_distance - 3
      relative_position_index[0:, 0] = num_relative_distance - 2
      relative_position_index[0, 0] = num_relative_distance - 1
      return relative_position_index
  
imports: import math
  from typing import Callable, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.utils.checkpoint import checkpoint
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import PatchEmbed, Mlp, SwiGLU, LayerNorm, DropPath, trunc_normal_, use_fused_attn
  from timm.layers import resample_patch_embed, resample_abs_pos_embed, resize_rel_pos_bias_table
  from ._builder import build_model_with_cfg
  from ._registry import generate_default_cfgs, register_model
  from .vision_transformer import checkpoint_filter_fn
label_desc: Use image node_id 1 for calling a global function with example usage: gen_relative_position_index(window_size) and returns: relative_position_index