class_docstr: Transformer blocks with support of window attention and residual propagation blocks.
class_docstr_tok: ["Transformer","blocks","with","support","of","window","attention","and","residual","propagation","blocks","."]
code: def forward(self, x: Tensor) -> Tensor:
      shortcut = x
      x = self.norm1(x)
      # Window partition
      if self.window_size > 0:
          H, W = x.shape[1], x.shape[2]
          x, pad_hw = window_partition(x, self.window_size)
  
      x = self.attn(x)
      # Reverse window partition
      if self.window_size > 0:
          x = window_unpartition(x, self.window_size, pad_hw, (H, W))
  
      x = shortcut + x
      x = x + self.mlp(self.norm2(x))
  
      return x
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  import torch.nn.functional
  from torch import nn
  from kornia.contrib.models.common import LayerNorm2d, window_partition, window_unpartition
  from kornia.contrib.models.sam.architecture.common import MLPBlock
  from kornia.core import Module, Tensor, zeros
label_desc: Use image node_id 2 for calling the Block obj's underlying member method code with example usage: obj.forward(x) and returns: x