


import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


a_					:    List[Any]          =    logging.get_logger(__name__)

a_					:    List[str]          =    {
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}




class  a     (     _a       ):
 _lowerCAmelCase 					=	"""pix2struct_text_model"""
 _lowerCAmelCase 					=	["""past_key_values"""]
 _lowerCAmelCase 					=	{
     """hidden_size""": """hidden_size""",
     """num_attention_heads""": """num_heads""",
     """num_hidden_layers""": """num_layers""",
 }
 def __init__( self      ,				__magic_name__=5_02_44      ,				__magic_name__=7_68      ,				__magic_name__=64      ,				__magic_name__=20_48      ,				__magic_name__=12      ,				__magic_name__=12      ,				__magic_name__=32      ,				__magic_name__=1_28      ,				__magic_name__=0.1      ,				__magic_name__=1e-6      ,				__magic_name__=1.0      ,				__magic_name__="gelu_new"      ,				__magic_name__=0      ,				__magic_name__=False      ,				__magic_name__=0      ,				__magic_name__=1      ,				__magic_name__=False      ,				__magic_name__=True      ,				**__magic_name__      ,				)					->							List[Any]:
      _a			      =							vocab_size
      _a			      =							hidden_size
      _a			      =							d_kv
      _a			      =							d_ff
      _a			      =							num_layers
      _a			      =							num_heads
      _a			      =							relative_attention_num_buckets
      _a			      =							relative_attention_max_distance
      _a			      =							dropout_rate
      _a			      =							layer_norm_epsilon
      _a			      =							initializer_factor
      _a			      =							use_cache

      _a			      =							eos_token_id
      _a			      =							decoder_start_token_id

      # for backwards compatibility
      _a			      =							dense_act_fn

      super().__init__(
          pad_token_id=snake_case_      ,				eos_token_id=snake_case_      ,				decoder_start_token_id=snake_case_      ,				tie_word_embeddings=snake_case_      ,				is_decoder=snake_case_      ,				**snake_case_      ,				)




 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				**__magic_name__						)					->							"PretrainedConfig":
      cls._set_token_in_kwargs(snake_case_						)

      _a      ,   _a			      =							cls.get_config_dict(snake_case_      ,				**snake_case_						)

      # get the text config dict if we are loading from Pix2StructConfig
      if config_dict.get('model_type'						) == "pix2struct":
           _a			      =							config_dict['text_config']

      if "model_type" in config_dict and hasattr(cls      ,				'model_type'						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
               f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'						)

      return cls.from_dict(snake_case_      ,				**snake_case_						)





class  a     (     _a       ):
 _lowerCAmelCase 					=	"""pix2struct_vision_model"""
 def __init__( self      ,				__magic_name__=7_68      ,				__magic_name__=7_68      ,				__magic_name__=20_48      ,				__magic_name__=64      ,				__magic_name__=12      ,				__magic_name__=12      ,				__magic_name__="gelu_new"      ,				__magic_name__=1e-6      ,				__magic_name__=0.0      ,				__magic_name__=0.0      ,				__magic_name__=1e-10      ,				__magic_name__=1.0      ,				__magic_name__=40_96      ,				__magic_name__=32      ,				__magic_name__=1_28      ,				**__magic_name__      ,				)					->							Union[str, Any]:
      super().__init__(**snake_case_						)

      _a			      =							hidden_size
      _a			      =							patch_embed_hidden_size
      _a			      =							d_ff
      _a			      =							dropout_rate
      _a			      =							num_hidden_layers
      _a			      =							num_attention_heads
      _a			      =							initializer_range
      _a			      =							initializer_factor
      _a			      =							attention_dropout
      _a			      =							layer_norm_eps
      _a			      =							dense_act_fn
      _a			      =							seq_len
      _a			      =							relative_attention_num_buckets
      _a			      =							relative_attention_max_distance
      _a			      =							d_kv




 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				**__magic_name__						)					->							"PretrainedConfig":
      cls._set_token_in_kwargs(snake_case_						)

      _a      ,   _a			      =							cls.get_config_dict(snake_case_      ,				**snake_case_						)

      # get the vision config dict if we are loading from Pix2StructConfig
      if config_dict.get('model_type'						) == "pix2struct":
           _a			      =							config_dict['vision_config']

      if "model_type" in config_dict and hasattr(cls      ,				'model_type'						) and config_dict["model_type"] != cls.model_type:
           logger.warning(
               f'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
               f'{cls.model_type}. This is not supported for all configurations of models and can yield errors.'						)

      return cls.from_dict(snake_case_      ,				**snake_case_						)





class  a     (     _a       ):
 _lowerCAmelCase 					=	"""pix2struct"""
 _lowerCAmelCase 					=	True
 def __init__( self      ,				__magic_name__=None      ,				__magic_name__=None      ,				__magic_name__=1.0      ,				__magic_name__=0.0_2      ,				__magic_name__=False      ,				__magic_name__=False      ,				__magic_name__=True      ,				**__magic_name__      ,				)					->							List[str]:
      super().__init__(tie_word_embeddings=snake_case_      ,				is_encoder_decoder=snake_case_      ,				**snake_case_						)

      if text_config is None:
           _a			      =							{}
           logger.info('text_config is None. Initializing the Pix2StructTextConfig with default values.'						)

      if vision_config is None:
           _a			      =							{}
           logger.info('vision_config is None. Initializing the Pix2StructVisionConfig with default values.'						)

      _a			      =							PixaStructTextConfig(**snake_case_						)
      _a			      =							PixaStructVisionConfig(**snake_case_						)

      _a			      =							self.text_config.decoder_start_token_id
      _a			      =							self.text_config.pad_token_id
      _a			      =							self.text_config.eos_token_id

      _a			      =							initializer_factor
      _a			      =							initializer_range

      _a			      =							self.initializer_range
      _a			      =							self.initializer_range

      _a			      =							is_vqa
 @classmethod
 def 							__UpperCAmelCase		( cls      ,				__magic_name__      ,				__magic_name__      ,				**__magic_name__						)					->							List[str]:
      return cls(text_config=text_config.to_dict()      ,				vision_config=vision_config.to_dict()      ,				**snake_case_						)




 def 							__UpperCAmelCase		( self						)					->							Any:
      _a			      =							copy.deepcopy(self.__dict__						)
      _a			      =							self.text_config.to_dict()
      _a			      =							self.vision_config.to_dict()
      _a			      =							self.__class__.model_type
      return output





'''simple docstring'''






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


a_					:    int          =    {"configuration_vit": ["VIT_PRETRAINED_CONFIG_ARCHIVE_MAP", "ViTConfig", "ViTOnnxConfig"]}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    List[Any]          =    ["ViTFeatureExtractor"]
 a_					:    Optional[int]          =    ["ViTImageProcessor"]

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Optional[int]          =    [
     "VIT_PRETRAINED_MODEL_ARCHIVE_LIST",
     "ViTForImageClassification",
     "ViTForMaskedImageModeling",
     "ViTModel",
     "ViTPreTrainedModel",
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Any          =    [
     "TFViTForImageClassification",
     "TFViTModel",
     "TFViTPreTrainedModel",
 ]

try:
 if not is_flax_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 a_					:    Dict          =    [
     "FlaxViTForImageClassification",
     "FlaxViTModel",
     "FlaxViTPreTrainedModel",
 ]

if TYPE_CHECKING:
 from .configuration_vit import VIT_PRETRAINED_CONFIG_ARCHIVE_MAP, ViTConfig, ViTOnnxConfig

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_vit import ViTFeatureExtractor
  from .image_processing_vit import ViTImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_vit import (
      VIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      ViTForImageClassification,
      ViTForMaskedImageModeling,
      ViTModel,
      ViTPreTrainedModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_vit import TFViTForImageClassification, TFViTModel, TFViTPreTrainedModel

 try:
  if not is_flax_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_flax_vit import FlaxViTForImageClassification, FlaxViTModel, FlaxViTPreTrainedModel


else:
 import sys

 a_					:    List[str]          =    _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

