code: def __init__(
      self,
      dim,
      num_heads,
      mlp_ratio=4.0,
      qkv_bias=False,
      drop=0.0,
      attn_drop=0.0,
      drop_path=0.0,
      act_layer=nn.GELU,
      norm_layer=nn.LayerNorm,
      windowed=False,
      window_size=14,
      pad_mode="constant",
      layer_scale=False,
      with_cp=False,
      ffn_layer=Mlp,
      memeff=False,
  ):
      super().__init__()
      self.with_cp = with_cp
      self.norm1 = norm_layer(dim)
      if windowed:
          self.attn = WindowedAttention(
              dim,
              num_heads=num_heads,
              qkv_bias=qkv_bias,
              attn_drop=attn_drop,
              proj_drop=drop,
              window_size=window_size,
              pad_mode=pad_mode,
          )
      elif memeff:
          self.attn = MemEffAttention(
              dim,
              num_heads=num_heads,
              qkv_bias=qkv_bias,
              attn_drop=attn_drop,
              proj_drop=drop,
          )
      else:
          self.attn = Attention(
              dim,
              num_heads=num_heads,
              qkv_bias=qkv_bias,
              attn_drop=attn_drop,
              proj_drop=drop,
          )
      # NOTE: drop path for stochastic depth, we shall see if this is better than dropout here
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
      self.norm2 = norm_layer(dim)
      mlp_hidden_dim = int(dim * mlp_ratio)
      self.mlp = ffn_layer(
          in_features=dim,
          hidden_features=mlp_hidden_dim,
          act_layer=act_layer,
          drop=drop,
      )
      self.layer_scale = layer_scale
      if layer_scale:
          self.gamma1 = nn.Parameter(
              torch.ones((dim)), requires_grad=True
          )
          self.gamma2 = nn.Parameter(
              torch.ones((dim)), requires_grad=True
          )
  
imports: import logging
  import math
  from functools import partial
  from itertools import repeat
  from typing import Callable, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from mmcv.runner import BaseModule, load_checkpoint
  from mmseg.ops import resize
  from mmseg.utils import get_root_logger
  from torch import Tensor
  from .drop_path import DropPath
label_desc: Use image node_id 1 to create a new Block object from inherited base classes: nn with example: obj = Block(dim, num_heads, mlp_ratio, qkv_bias, drop, attn_drop, drop_path, act_layer, norm_layer, windowed, window_size, pad_mode, layer_scale, with_cp, ffn_layer, memeff)