class_docstr: This class defines the `Vision Transformer architecture <https://arxiv.org/abs/2010.11929>`_. Our model implementation
  is inspired from `Early Convolutions Help Transformers See Better <https://arxiv.org/abs/2106.14881>`_
  
  .. note::
      Our implementation is different from the original implementation in two ways:
      1. Kernel size is odd.
      2. Our positional encoding implementation allows us to use ViT with any multiple input scales
      3. We do not use StochasticDepth
      4. We do not add positional encoding to class token (if enabled), as suggested in `DeiT-3 paper <https://arxiv.org/abs/2204.07118>`_
class_docstr_tok: ["This","class","defines","the","`","Vision","Transformer","architecture","<","https",":","\/\/arxiv.org\/abs\/2010.11929",">","`","_",".","Our","model","implementation","is","inspired","from","`","Early","Convolutions","Help","Transformers","See","Better","<","https",":","\/\/arxiv.org\/abs\/2106.14881",">","`","_","..","note",":",":","Our","implementation","is","different","from","the","original","implementation","in","two","ways",":","1",".","Kernel","size","is","odd",".","2",".","Our","positional","encoding","implementation","allows","us","to","use","ViT","with","any","multiple","input","scales","3",".","We","do","not","use","StochasticDepth","4",".","We","do","not","add","positional","encoding","to","class","token","(","if","enabled",")",",","as","suggested","in","`","DeiT-3","paper","<","https",":","\/\/arxiv.org\/abs\/2204.07118",">","`","_"]
code: def _features_from_transformer(
      self, x: Tensor, *args, **kwargs
  ) -> Tuple[Tensor, Tuple[int, int]]:
      # this function extract patch embeddings and then apply transformer module to learn
      # inter-patch representations
  
      # [B, N, C] --> [N, B, embed_dim], where B is batch size, N is number of tokens,
      # and embed_dim is feature dim
      x, (n_h, n_w) = self.extract_patch_embeddings(x)
  
      if self.use_pytorch_mha:
          # For PyTorch MHA, we need sequence first.
          # For our custom MHA implementation, batch is the first
          x = x.transpose(0, 1)
  
      if self.training and self.gradient_checkpointing:
          # we use sequential checkpoint function, which divides the model into chunks and checkpoints each segment
          # This maybe useful when dealing with large models
  
          # Right now, gradient checkpoint function does not like kwargs. Therefore, we use default MHA implementation
          # over the PyTorch's fused implementation.
          # Note that default MHA implementation is batch-first, while pytorch implementation is sequence-first.
          x = gradient_checkpoint_fn(
              self.transformer, self.checkpoint_segments, x
          )
      else:
          for layer in self.transformer:
              x = layer(x, use_pytorch_mha=self.use_pytorch_mha)
      x = self.post_transformer_norm(x)
  
      if self.use_pytorch_mha:
          # [N, B, C] --> [B, N, C]
          x = x.transpose(0, 1)
  
      return x, (n_h, n_w)
  
imports: import argparse
  from typing import Dict, List, Optional, Tuple, Union
  import numpy
  import torch
  from torch import Tensor, nn
  from torch.utils.checkpoint import checkpoint_sequential
  from cvnets.layers import ConvLayer2d, Dropout, Identity, LinearLayer, MaxPool2d, PositionalEmbedding, TransposeConvLayer2d, get_normalization_layer
  from cvnets.misc.common import parameter_list
  from cvnets.misc.init_utils import initialize_conv_layer
  from cvnets.models import MODEL_REGISTRY
  from cvnets.models.classification.base_image_encoder import BaseImageEncoder
  from cvnets.models.classification.config.vit import get_configuration
  from cvnets.modules import TransformerEncoder
  from utils import logger
label_desc: Use image node_id 8 for calling the VisionTransformer obj's underlying member method code with example usage: obj._features_from_transformer(x) and returns: x,  n_h,  n_w