docstr: Patchify with overlap
  
  Args:
      x: tensor of size [B, C, H, W]
      patch_size: patch size
  
  Returns:
      Tensor of patches with shape [B*num_patches_H*num_patches_W, patch_size^2, C]
docstr_tok: ["Patchify","with","overlap","Args",":","x",":","tensor","of","size","[","B",",","C",",","H",",","W","]","patch_size",":","patch","size","Returns",":","Tensor","of","patches","with","shape","[","B","*","num_patches_H","*","num_patches_W",",","patch_size^2",",","C","]"]
code: def _window_partition_conv2d(
      self, x: Tensor, patch_size: int
  ) -> Tensor:
      """Patchify with overlap
  
      Args:
          x: tensor of size [B, C, H, W]
          patch_size: patch size
  
      Returns:
          Tensor of patches with shape [B*num_patches_H*num_patches_W, patch_size^2, C]
      """
      B, C, H, W = x.shape
  
      # PyTorch expects [output C, input C, kernel H, kernel W]
      kernel = torch.diag(x.new_ones(patch_size**2 * C)).reshape(
          C * patch_size**2, C, patch_size, patch_size
      )
      patches = F.conv2d(
          x, kernel, stride=self.stride
      )  # [B, patch_size^2*C, num_patches_H, num_patches_W]
      n_patches_H, n_patches_W = patches.shape[-2:]
      return (
          patches.reshape(
              B, C, patch_size**2, n_patches_H, n_patches_W
          )
          .permute(
              0, 3, 4, 2, 1
          )  # [B, npatch_H, npatch_W, seq_len,  C]
          .contiguous()
          .reshape(B * n_patches_H * n_patches_W, patch_size**2, C)
      )
  
file_path: NeuralCompression/projects/torch_vct/neural/patcher.py
imports: import math
  from typing import NamedTuple, Optional, Tuple, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from torch import Tensor
label_desc: Use image node_id 5 for calling the Patcher obj's underlying member method code with example usage: obj._window_partition_conv2d(x, patch_size) and returns: patches