class_docstr: Convolutional relative position encoding. 
class_docstr_tok: ["Convolutional","relative","position","encoding","."]
docstr: Initialization.
      Ch: Channels per head.
      h: Number of heads.
      window: Window size(s) in convolutional relative positional encoding. It can have two forms:
          1. An integer of window size, which assigns all attention heads with the same window s
              size in ConvRelPosEnc.
          2. A dict mapping window size to #attention head splits (
              e.g. {window size 1: #attention head split 1, window size 2: #attention head split 2})
              It will apply different window size to the attention head splits.
docstr_tok: ["Initialization",".","Ch",":","Channels","per","head",".","h",":","Number","of","heads",".","window",":","Window","size","(","s",")","in","convolutional","relative","positional","encoding",".","It","can","have","two","forms",":","1",".","An","integer","of","window","size",",","which","assigns","all","attention","heads","with","the","same","window","s","size","in","ConvRelPosEnc",".","2",".","A","dict","mapping","window","size","to","#","attention","head","splits","(","e.g",".","{","window","size","1",":","#","attention","head","split","1",",","window","size","2",":","#","attention","head","split","2","}",")","It","will","apply","different","window","size","to","the","attention","head","splits","."]
code: def __init__(self, head_chs, num_heads, window):
      """
      Initialization.
          Ch: Channels per head.
          h: Number of heads.
          window: Window size(s) in convolutional relative positional encoding. It can have two forms:
              1. An integer of window size, which assigns all attention heads with the same window s
                  size in ConvRelPosEnc.
              2. A dict mapping window size to #attention head splits (
                  e.g. {window size 1: #attention head split 1, window size 2: #attention head split 2})
                  It will apply different window size to the attention head splits.
      """
      super().__init__()
  
      if isinstance(window, int):
          # Set the same window size for all attention heads.
          window = {window: num_heads}
          self.window = window
      elif isinstance(window, dict):
          self.window = window
      else:
          raise ValueError()
  
      self.conv_list = nn.ModuleList()
      self.head_splits = []
      for cur_window, cur_head_split in window.items():
          dilation = 1
          # Determine padding size.
          # Ref: https://discuss.pytorch.org/t/how-to-keep-the-shape-of-input-and-output-same-when-dilation-conv/14338
          padding_size = (
              cur_window + (cur_window - 1) * (dilation - 1)
          ) // 2
          cur_conv = nn.Conv2d(
              cur_head_split * head_chs,
              cur_head_split * head_chs,
              kernel_size=(cur_window, cur_window),
              padding=(padding_size, padding_size),
              dilation=(dilation, dilation),
              groups=cur_head_split * head_chs,
          )
          self.conv_list.append(cur_conv)
          self.head_splits.append(cur_head_split)
      self.channel_splits = [x * head_chs for x in self.head_splits]
  
imports: from functools import partial
  from typing import Tuple, List, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import PatchEmbed, Mlp, DropPath, to_2tuple, trunc_normal_, _assert, LayerNorm
  from ._builder import build_model_with_cfg
  from ._registry import register_model, generate_default_cfgs
label_desc: Use image node_id 1 to create a new ConvRelPosEnc object from inherited base classes: nn with example: obj = ConvRelPosEnc(head_chs, num_heads, window)