class_docstr: Implementation of conditional positional encoding.
  
  For more details refer to paper:
  `Conditional Positional Encodings for Vision Transformers <https://arxiv.org/pdf/2102.10882.pdf>`_
  
  In our implementation, we can reparameterize this module to eliminate a skip connection.
class_docstr_tok: ["Implementation","of","conditional","positional","encoding",".","For","more","details","refer","to","paper",":","`","Conditional","Positional","Encodings","for","Vision","Transformers","<","https",":","\/\/arxiv.org\/pdf\/2102.10882.pdf",">","`","_","In","our","implementation",",","we","can","reparameterize","this","module","to","eliminate","a","skip","connection","."]
docstr: Build reparameterizable conditional positional encoding
  
  Args:
      in_channels: Number of input channels.
      embed_dim: Number of embedding dimensions. Default: 768
      spatial_shape: Spatial shape of kernel for positional encoding. Default: (7, 7)
      inference_mode: Flag to instantiate block in inference mode. Default: ``False``
code: def __init__(
      self,
      in_channels: int,
      embed_dim: int = 768,
      spatial_shape: Union[int, Tuple[int, int]] = (7, 7),
      inference_mode=False,
  ) -> None:
      """Build reparameterizable conditional positional encoding
  
      Args:
          in_channels: Number of input channels.
          embed_dim: Number of embedding dimensions. Default: 768
          spatial_shape: Spatial shape of kernel for positional encoding. Default: (7, 7)
          inference_mode: Flag to instantiate block in inference mode. Default: ``False``
      """
      super(RepCPE, self).__init__()
      if isinstance(spatial_shape, int):
          spatial_shape = tuple([spatial_shape] * 2)
      assert isinstance(spatial_shape, Tuple), (
          f'"spatial_shape" must by a sequence or int, '
          f"get {type(spatial_shape)} instead."
      )
      assert len(spatial_shape) == 2, (
          f'Length of "spatial_shape" should be 2, '
          f"got {len(spatial_shape)} instead."
      )
  
      self.spatial_shape = spatial_shape
      self.embed_dim = embed_dim
      self.in_channels = in_channels
      self.groups = embed_dim
  
      if inference_mode:
          self.reparam_conv = nn.Conv2d(
              in_channels=self.in_channels,
              out_channels=self.embed_dim,
              kernel_size=self.spatial_shape,
              stride=1,
              padding=int(self.spatial_shape[0] // 2),
              groups=self.embed_dim,
              bias=True,
          )
      else:
          self.pe = nn.Conv2d(
              in_channels,
              embed_dim,
              spatial_shape,
              1,
              int(spatial_shape[0] // 2),
              bias=True,
              groups=embed_dim,
          )
  
imports: import os
  import copy
  from functools import partial
  from typing import List, Tuple, Optional, Union
  import torch
  import torch.nn
  from timm.data import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD
  from timm.models.layers import DropPath, trunc_normal_
  from timm.models.registry import register_model
  from models.modules.mobileone import MobileOneBlock
  from models.modules.replknet import ReparamLargeKernelConv
label_desc: Use image node_id 1 to create a new RepCPE object from inherited base classes: nn with example: obj = RepCPE(in_channels, embed_dim, spatial_shape, inference_mode)