class_docstr: Vision Transformer with support for patch or hybrid CNN input stage
      
class_docstr_tok: ["Vision","Transformer","with","support","for","patch","or","hybrid","CNN","input","stage"]
code: def __init__(
      self,
      img_size=224,
      patch_size=16,
      in_chans=3,
      class_num=1000,
      embed_dim=[192],
      key_dim=[64],
      depth=[12],
      num_heads=[3],
      attn_ratio=[2],
      mlp_ratio=[2],
      hybrid_backbone=None,
      down_ops=[],
      attention_activation=nn.Hardswish,
      mlp_activation=nn.Hardswish,
      distillation=True,
      drop_path=0,
  ):
      super().__init__()
  
      self.class_num = class_num
      self.num_features = embed_dim[-1]
      self.embed_dim = embed_dim
      self.distillation = distillation
  
      self.patch_embed = hybrid_backbone
  
      self.blocks = []
      down_ops.append([""])
      resolution = img_size // patch_size
      for i, (ed, kd, dpth, nh, ar, mr, do) in enumerate(
          zip(
              embed_dim,
              key_dim,
              depth,
              num_heads,
              attn_ratio,
              mlp_ratio,
              down_ops,
          )
      ):
          for _ in range(dpth):
              self.blocks.append(
                  Residual(
                      Attention(
                          ed,
                          kd,
                          nh,
                          attn_ratio=ar,
                          activation=attention_activation,
                          resolution=resolution,
                      ),
                      drop_path,
                  )
              )
              if mr > 0:
                  h = int(ed * mr)
                  self.blocks.append(
                      Residual(
                          nn.Sequential(
                              Linear_BN(ed, h),
                              mlp_activation(),
                              Linear_BN(h, ed, bn_weight_init=0),
                          ),
                          drop_path,
                      )
                  )
          if do[0] == "Subsample":
              # ('Subsample',key_dim, num_heads, attn_ratio, mlp_ratio, stride)
              resolution_ = (resolution - 1) // do[5] + 1
              self.blocks.append(
                  AttentionSubsample(
                      *embed_dim[i : i + 2],
                      key_dim=do[1],
                      num_heads=do[2],
                      attn_ratio=do[3],
                      activation=attention_activation,
                      stride=do[5],
                      resolution=resolution,
                      resolution_=resolution_,
                  )
              )
              resolution = resolution_
              if do[4] > 0:  # mlp_ratio
                  h = int(embed_dim[i + 1] * do[4])
                  self.blocks.append(
                      Residual(
                          nn.Sequential(
                              Linear_BN(embed_dim[i + 1], h),
                              mlp_activation(),
                              Linear_BN(
                                  h, embed_dim[i + 1], bn_weight_init=0
                              ),
                          ),
                          drop_path,
                      )
                  )
      self.blocks = nn.Sequential(*self.blocks)
  
      # Classifier head
      self.head = (
          BN_Linear(embed_dim[-1], class_num)
          if class_num > 0
          else Identity()
      )
      if distillation:
          self.head_dist = (
              BN_Linear(embed_dim[-1], class_num)
              if class_num > 0
              else Identity()
          )
  
imports: import itertools
  import math
  import warnings
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddle.nn.initializer import Constant
  from paddle.nn.initializer import TruncatedNormal
  from paddle.regularizer import L2Decay
  from .vision_transformer import Identity
  from .vision_transformer import ones_
  from .vision_transformer import trunc_normal_
  from .vision_transformer import zeros_
label_desc: Use image node_id 1 to create a new LeViT object from inherited base classes: nn with example: obj = LeViT(img_size, patch_size, in_chans, class_num, embed_dim, key_dim, depth, num_heads, attn_ratio, mlp_ratio, hybrid_backbone, down_ops, attention_activation, mlp_activation, distillation, drop_path)