code: def __init__(
      self,
      dim,
      key_dim,
      num_heads=8,
      attn_ratio=4,
      resolution=14,
      kernels=(5, 5, 5, 5),
  ):
      super().__init__()
      self.num_heads = num_heads
      self.scale = key_dim**-0.5
      self.key_dim = key_dim
      self.val_dim = int(attn_ratio * key_dim)
      self.attn_ratio = attn_ratio
  
      qkvs = []
      dws = []
      for i in range(num_heads):
          qkvs.append(
              ConvNorm(
                  dim // (num_heads), self.key_dim * 2 + self.val_dim
              )
          )
          dws.append(
              ConvNorm(
                  self.key_dim,
                  self.key_dim,
                  kernels[i],
                  1,
                  kernels[i] // 2,
                  groups=self.key_dim,
              )
          )
      self.qkvs = torch.nn.ModuleList(qkvs)
      self.dws = torch.nn.ModuleList(dws)
      self.proj = torch.nn.Sequential(
          torch.nn.ReLU(),
          ConvNorm(self.val_dim * num_heads, dim, bn_weight_init=0),
      )
  
      points = list(
          itertools.product(range(resolution), range(resolution))
      )
      N = len(points)
      attention_offsets = {}
      idxs = []
      for p1 in points:
          for p2 in points:
              offset = (abs(p1[0] - p2[0]), abs(p1[1] - p2[1]))
              if offset not in attention_offsets:
                  attention_offsets[offset] = len(attention_offsets)
              idxs.append(attention_offsets[offset])
      self.attention_biases = torch.nn.Parameter(
          torch.zeros(num_heads, len(attention_offsets))
      )
      self.register_buffer(
          "attention_bias_idxs",
          torch.LongTensor(idxs).view(N, N),
          persistent=False,
      )
      self.attention_bias_cache = {}
  
imports: import itertools
  from collections import OrderedDict
  from typing import Dict
  import torch
  import torch.nn
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.layers import SqueezeExcite, SelectAdaptivePool2d, trunc_normal_, _assert
  from ._builder import build_model_with_cfg
  from ._manipulate import checkpoint_seq
  from ._registry import register_model, generate_default_cfgs
label_desc: Use image node_id 1 to create a new CascadedGroupAttention object from inherited base classes: torch.nn with example: obj = CascadedGroupAttention(dim, key_dim, num_heads, attn_ratio, resolution, kernels)