class_docstr: Relative Position Bias
  Adapted from Swin-V1 relative position bias impl, modularized.
class_docstr_tok: ["Relative","Position","Bias","Adapted","from","Swin-V1","relative","position","bias","impl",",","modularized","."]
code: def __init__(self, window_size, num_heads, prefix_tokens=0):
      super().__init__()
      assert prefix_tokens <= 1
      self.window_size = window_size
      self.window_area = window_size[0] * window_size[1]
      self.bias_shape = (self.window_area + prefix_tokens,) * 2 + (
          num_heads,
      )
  
      num_relative_distance = (2 * window_size[0] - 1) * (
          2 * window_size[1] - 1
      ) + 3 * prefix_tokens
      self.relative_position_bias_table = nn.Parameter(
          torch.zeros(num_relative_distance, num_heads)
      )
      self.register_buffer(
          "relative_position_index",
          gen_relative_position_index(
              self.window_size, class_token=prefix_tokens > 0
          ).view(-1),
          persistent=False,
      )
  
      self.init_weights()
  
imports: import math
  import os
  from typing import Optional, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from .interpolate import RegularGridInterpolator
  from .mlp import Mlp
  from .weight_init import trunc_normal_
label_desc: Use image node_id 1 to create a new RelPosBias object from inherited base classes: nn with example: obj = RelPosBias(window_size, num_heads, prefix_tokens)