class_docstr: See :func:`shifted_window_attention_3d`.
code: def define_relative_position_index(self) -> None:
      # get pair-wise relative position index for each token inside the window
      coords_dhw = [torch.arange(self.window_size[i]) for i in range(3)]
      coords = torch.stack(
          torch.meshgrid(
              coords_dhw[0], coords_dhw[1], coords_dhw[2], indexing="ij"
          )
      )  # 3, Wd, Wh, Ww
      coords_flatten = torch.flatten(coords, 1)  # 3, Wd*Wh*Ww
      relative_coords = (
          coords_flatten[:, :, None] - coords_flatten[:, None, :]
      )  # 3, Wd*Wh*Ww, Wd*Wh*Ww
      relative_coords = relative_coords.permute(
          1, 2, 0
      ).contiguous()  # Wd*Wh*Ww, Wd*Wh*Ww, 3
      relative_coords[:, :, 0] += (
          self.window_size[0] - 1
      )  # shift to start from 0
      relative_coords[:, :, 1] += self.window_size[1] - 1
      relative_coords[:, :, 2] += self.window_size[2] - 1
  
      relative_coords[:, :, 0] *= (2 * self.window_size[1] - 1) * (
          2 * self.window_size[2] - 1
      )
      relative_coords[:, :, 1] *= 2 * self.window_size[2] - 1
      # We don't flatten the relative_position_index here in 3d case.
      relative_position_index = relative_coords.sum(
          -1
      )  # Wd*Wh*Ww, Wd*Wh*Ww
      self.register_buffer(
          "relative_position_index", relative_position_index
      )
  
imports: from functools import partial
  from typing import Any, Callable, List, Optional, Tuple
  import torch
  import torch.nn.functional
  from torch import nn, Tensor
  from ...transforms._presets import VideoClassification
  from ...utils import _log_api_usage_once
  from .._api import register_model, Weights, WeightsEnum
  from .._meta import _KINETICS400_CATEGORIES
  from .._utils import _ovewrite_named_param, handle_legacy_interface
  from ..swin_transformer import PatchMerging, SwinTransformerBlock
label_desc: Use image node_id 3 for calling the ShiftedWindowAttention3d obj's underlying member method code with example usage: obj.define_relative_position_index() without return types