class_docstr: See :func:`shifted_window_attention_v2`.
class_docstr_tok: ["See",":","func",":","`","shifted_window_attention_v2","`","."]
code: def define_relative_position_bias_table(self):
      # get relative_coords_table
      relative_coords_h = torch.arange(
          -(self.window_size[0] - 1),
          self.window_size[0],
          dtype=torch.float32,
      )
      relative_coords_w = torch.arange(
          -(self.window_size[1] - 1),
          self.window_size[1],
          dtype=torch.float32,
      )
      relative_coords_table = torch.stack(
          torch.meshgrid(
              [relative_coords_h, relative_coords_w], indexing="ij"
          )
      )
      relative_coords_table = (
          relative_coords_table.permute(1, 2, 0)
          .contiguous()
          .unsqueeze(0)
      )  # 1, 2*Wh-1, 2*Ww-1, 2
  
      relative_coords_table[:, :, :, 0] /= self.window_size[0] - 1
      relative_coords_table[:, :, :, 1] /= self.window_size[1] - 1
  
      relative_coords_table *= 8  # normalize to -8, 8
      relative_coords_table = (
          torch.sign(relative_coords_table)
          * torch.log2(torch.abs(relative_coords_table) + 1.0)
          / 3.0
      )
      self.register_buffer(
          "relative_coords_table", relative_coords_table
      )
  
imports: import math
  from functools import partial
  from typing import Any, Callable, List, Optional
  import torch
  import torch.nn.functional
  from torch import nn, Tensor
  from ..ops.misc import MLP, Permute
  from ..ops.stochastic_depth import StochasticDepth
  from ..transforms._presets import ImageClassification, InterpolationMode
  from ..utils import _log_api_usage_once
  from ._api import register_model, Weights, WeightsEnum
  from ._meta import _IMAGENET_CATEGORIES
  from ._utils import _ovewrite_named_param, handle_legacy_interface
label_desc: Use image node_id 2 for calling the ShiftedWindowAttentionV2 obj's underlying member method code with example usage: obj.define_relative_position_bias_table() without return types