docstr: Creates a ViT encoder using transformers.ViTModel.
  
  use_pretrained: If True, uses a pretrained transformer based on the
      pretrained_model argument.
  pretrained: If str, expects the path to a pretrained model or the id of
      a model on huggingface.co, and ignores the configuration provided in
      the arguments.
docstr_tok: ["Creates","a","ViT","encoder","using","transformers.ViTModel",".","use_pretrained",":","If","True",",","uses","a","pretrained","transformer","based","on","the","pretrained_model","argument",".","pretrained",":","If","str",",","expects","the","path","to","a","pretrained","model","or","the","id","of","a","model","on","huggingface.co",",","and","ignores","the","configuration","provided","in","the","arguments","."]
code: def __init__(
      self,
      height: int,
      width: int,
      num_channels: int = 3,
      use_pretrained: bool = True,
      pretrained_model: str = "google/vit-base-patch16-224",
      saved_weights_in_checkpoint: bool = False,
      hidden_size: int = 768,
      num_hidden_layers: int = 12,
      num_attention_heads: int = 12,
      intermediate_size: int = 3072,
      hidden_act: str = "gelu",
      hidden_dropout_prob: float = 0.1,
      attention_probs_dropout_prob: float = 0.1,
      initializer_range: float = 0.02,
      layer_norm_eps: float = 1e-12,
      gradient_checkpointing: bool = False,
      patch_size: int = 16,
      trainable: bool = True,
      output_attentions: bool = False,
      encoder_config=None,
      **kwargs,
  ):
      """Creates a ViT encoder using transformers.ViTModel.
  
      use_pretrained: If True, uses a pretrained transformer based on the
          pretrained_model argument.
      pretrained: If str, expects the path to a pretrained model or the id of
          a model on huggingface.co, and ignores the configuration provided in
          the arguments.
      """
      super().__init__()
      self.config = encoder_config
  
      try:
          from transformers import ViTConfig, ViTModel
      except ModuleNotFoundError:
          raise RuntimeError(
              " transformers is not installed. "
              "In order to install all image feature dependencies run "
              "pip install ludwig[image]"
          )
  
      # map parameter input feature config names to internal names
      img_height = height
      img_width = width
      in_channels = num_channels
  
      img_width = img_width or img_height
      if img_width != img_height:
          raise ValueError(
              "img_height and img_width should be identical."
          )
      self._input_shape = (in_channels, img_height, img_width)
  
      if use_pretrained and not saved_weights_in_checkpoint:
          transformer = ViTModel.from_pretrained(pretrained_model)
      else:
          config = ViTConfig(
              image_size=img_height,
              num_channels=in_channels,
              patch_size=patch_size,
              hidden_size=hidden_size,
              num_hidden_layers=num_hidden_layers,
              num_attention_heads=num_attention_heads,
              intermediate_size=intermediate_size,
              hidden_act=hidden_act,
              hidden_dropout_prob=hidden_dropout_prob,
              attention_probs_dropout_prob=attention_probs_dropout_prob,
              initializer_range=initializer_range,
              layer_norm_eps=layer_norm_eps,
              gradient_checkpointing=gradient_checkpointing,
          )
          transformer = ViTModel(config)
  
      self.transformer = FreezeModule(transformer, frozen=not trainable)
  
      self._output_shape = (transformer.config.hidden_size,)
      self.output_attentions = output_attentions
  
imports: import logging
  from typing import Any, Dict, List, Optional, Tuple, Type, Union
  import torch
  from ludwig.api_annotations import DeveloperAPI
  from ludwig.constants import ENCODER_OUTPUT, IMAGE
  from ludwig.encoders.base import Encoder
  from ludwig.encoders.registry import register_encoder
  from ludwig.encoders.types import EncoderOutputDict
  from ludwig.modules.convolutional_modules import Conv2DStack, ResNet
  from ludwig.modules.fully_connected_modules import FCStack
  from ludwig.modules.mlp_mixer_modules import MLPMixer
  from ludwig.schema.encoders.image.base import ImageEncoderConfig, MLPMixerConfig, ResNetConfig, Stacked2DCNNConfig, ViTConfig
  from ludwig.utils.torch_utils import FreezeModule
label_desc: Use image node_id 1 to create a new ViTEncoder object from inherited base classes: ImageEncoder with example: obj = ViTEncoder(height, width, num_channels, use_pretrained, pretrained_model, saved_weights_in_checkpoint, hidden_size, num_hidden_layers, num_attention_heads, intermediate_size, hidden_act, hidden_dropout_prob, attention_probs_dropout_prob, initializer_range, layer_norm_eps, gradient_checkpointing, patch_size, trainable, output_attentions, encoder_config)