
"""simple docstring"""





import copy
import os
from typing import Union

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


_a		       =							logging.get_logger(__name__)

_a		       =							{
    'google/pix2struct-textcaps-base': (
        'https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json'
    ),
}


class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						List[str]       =		"""pix2struct_text_model"""
  SCREAMING_SNAKE_CASE__			:						List[str]       =		["""past_key_values"""]
  SCREAMING_SNAKE_CASE__			:						Optional[Any]       =		{
      """hidden_size""": """hidden_size""",
      """num_attention_heads""": """num_heads""",
      """num_hidden_layers""": """num_layers""",
  }







  def __init__(		self				,   lowercase_=5_0244				,   lowercase_=768				,   lowercase_=64				,   lowercase_=2048				,   lowercase_=12				,   lowercase_=12				,   lowercase_=32				,   lowercase_=128				,   lowercase_=0.1				,   lowercase_=1E-6				,   lowercase_=1.0				,   lowercase_="gelu_new"				,   lowercase_=0				,   lowercase_=False				,   lowercase_=0				,   lowercase_=1				,   lowercase_=False				,   lowercase_=True				,   **lowercase_				,   ):

     """simple docstring"""
     UpperCAmelCase_					:					Dict			     =    vocab_size
     UpperCAmelCase_					:					str			     =    hidden_size
     UpperCAmelCase_					:					Dict			     =    d_kv
     UpperCAmelCase_					:					int			     =    d_ff
     UpperCAmelCase_					:					Union[str, Any]			     =    num_layers
     UpperCAmelCase_					:					List[Any]			     =    num_heads
     UpperCAmelCase_					:					int			     =    relative_attention_num_buckets
     UpperCAmelCase_					:					int			     =    relative_attention_max_distance
     UpperCAmelCase_					:					Optional[int]			     =    dropout_rate
     UpperCAmelCase_					:					Any			     =    layer_norm_epsilon
     UpperCAmelCase_					:					List[str]			     =    initializer_factor
     UpperCAmelCase_					:					Union[str, Any]			     =    use_cache

     UpperCAmelCase_					:					List[str]			     =    eos_token_id
     UpperCAmelCase_					:					Optional[int]			     =    decoder_start_token_id

     # for backwards compatibility
     UpperCAmelCase_					:					int			     =    dense_act_fn

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







  @classmethod
  def        UpperCamelCase__					(		cls				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     cls._set_token_in_kwargs(lowercase_  )

     UpperCAmelCase_     ,   UpperCAmelCase_					:					List[Any]			     =    cls.get_config_dict(lowercase_				,   **lowercase_  )

     # get the text config dict if we are loading from Pix2StructConfig
     if config_dict.get("model_type"  ) == "pix2struct":
        UpperCAmelCase_					:					Optional[Any]			     =    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(lowercase_				,   **lowercase_  )




class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						int       =		"""pix2struct_vision_model"""







  def __init__(		self				,   lowercase_=768				,   lowercase_=768				,   lowercase_=2048				,   lowercase_=64				,   lowercase_=12				,   lowercase_=12				,   lowercase_="gelu_new"				,   lowercase_=1E-6				,   lowercase_=0.0				,   lowercase_=0.0				,   lowercase_=1E-1_0				,   lowercase_=1.0				,   lowercase_=4096				,   lowercase_=32				,   lowercase_=128				,   **lowercase_				,   ):

     """simple docstring"""
     super().__init__(**lowercase_  )

     UpperCAmelCase_					:					Tuple			     =    hidden_size
     UpperCAmelCase_					:					str			     =    patch_embed_hidden_size
     UpperCAmelCase_					:					Tuple			     =    d_ff
     UpperCAmelCase_					:					Union[str, Any]			     =    dropout_rate
     UpperCAmelCase_					:					List[str]			     =    num_hidden_layers
     UpperCAmelCase_					:					str			     =    num_attention_heads
     UpperCAmelCase_					:					Optional[Any]			     =    initializer_range
     UpperCAmelCase_					:					Dict			     =    initializer_factor
     UpperCAmelCase_					:					Optional[Any]			     =    attention_dropout
     UpperCAmelCase_					:					Union[str, Any]			     =    layer_norm_eps
     UpperCAmelCase_					:					List[Any]			     =    dense_act_fn
     UpperCAmelCase_					:					Union[str, Any]			     =    seq_len
     UpperCAmelCase_					:					Tuple			     =    relative_attention_num_buckets
     UpperCAmelCase_					:					Tuple			     =    relative_attention_max_distance
     UpperCAmelCase_					:					Optional[Any]			     =    d_kv







  @classmethod
  def        UpperCamelCase__					(		cls				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     cls._set_token_in_kwargs(lowercase_  )

     UpperCAmelCase_     ,   UpperCAmelCase_					:					List[str]			     =    cls.get_config_dict(lowercase_				,   **lowercase_  )

     # get the vision config dict if we are loading from Pix2StructConfig
     if config_dict.get("model_type"  ) == "pix2struct":
        UpperCAmelCase_					:					int			     =    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(lowercase_				,   **lowercase_  )




class A_	(lowercase__      ):




  '''simple docstring'''
  SCREAMING_SNAKE_CASE__			:						Any       =		"""pix2struct"""
  SCREAMING_SNAKE_CASE__			:						str       =		True







  def __init__(		self				,   lowercase_=None				,   lowercase_=None				,   lowercase_=1.0				,   lowercase_=0.02				,   lowercase_=False				,   lowercase_=False				,   lowercase_=True				,   **lowercase_				,   ):

     """simple docstring"""
     super().__init__(tie_word_embeddings=lowercase_				,   is_encoder_decoder=lowercase_				,   **lowercase_  )

     if text_config is None:
        UpperCAmelCase_					:					List[Any]			     =    {}
        logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."  )

     if vision_config is None:
        UpperCAmelCase_					:					Optional[Any]			     =    {}
        logger.info("vision_config is None. Initializing the Pix2StructVisionConfig with default values."  )

     UpperCAmelCase_					:					Dict			     =    PixaStructTextConfig(**lowercase_  )
     UpperCAmelCase_					:					Union[str, Any]			     =    PixaStructVisionConfig(**lowercase_  )

     UpperCAmelCase_					:					str			     =    self.text_config.decoder_start_token_id
     UpperCAmelCase_					:					Any			     =    self.text_config.pad_token_id
     UpperCAmelCase_					:					Union[str, Any]			     =    self.text_config.eos_token_id

     UpperCAmelCase_					:					Any			     =    initializer_factor
     UpperCAmelCase_					:					List[Any]			     =    initializer_range

     UpperCAmelCase_					:					List[Any]			     =    self.initializer_range
     UpperCAmelCase_					:					Dict			     =    self.initializer_range

     UpperCAmelCase_					:					str			     =    is_vqa







  @classmethod
  def        UpperCamelCase__					(		cls				,   lowercase_				,   lowercase_				,   **lowercase_  ):

     """simple docstring"""
     return cls(text_config=text_config.to_dict()				,   vision_config=vision_config.to_dict()				,   **lowercase_  )







  def        UpperCamelCase__					(		self  ):

     """simple docstring"""
     UpperCAmelCase_					:					Tuple			     =    copy.deepcopy(self.__dict__  )
     UpperCAmelCase_					:					Optional[int]			     =    self.text_config.to_dict()
     UpperCAmelCase_					:					int			     =    self.vision_config.to_dict()
     UpperCAmelCase_					:					Optional[Any]			     =    self.__class__.model_type
     return output









"""simple docstring"""
from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase_								=		logging.get_logger(__name__)

lowerCamelCase_								=		{
    "microsoft/beit-base-patch16-224-pt22k": (
        "https://huggingface.co/microsoft/beit-base-patch16-224-pt22k/resolve/main/config.json"
    ),
    # See all BEiT models at https://huggingface.co/models?filter=beit
}






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      str							=  '''beit'''




       def __init__(						self		,SCREAMING_SNAKE_CASE__=81_92		,SCREAMING_SNAKE_CASE__=7_68		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=12		,SCREAMING_SNAKE_CASE__=30_72		,SCREAMING_SNAKE_CASE__="gelu"		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0		,SCREAMING_SNAKE_CASE__=0.0_2		,SCREAMING_SNAKE_CASE__=1E-12		,SCREAMING_SNAKE_CASE__=2_24		,SCREAMING_SNAKE_CASE__=16		,SCREAMING_SNAKE_CASE__=3		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=0.1		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=[3, 5, 7, 11]		,SCREAMING_SNAKE_CASE__=[1, 2, 3, 6]		,SCREAMING_SNAKE_CASE__=True		,SCREAMING_SNAKE_CASE__=0.4		,SCREAMING_SNAKE_CASE__=2_56		,SCREAMING_SNAKE_CASE__=1		,SCREAMING_SNAKE_CASE__=False		,SCREAMING_SNAKE_CASE__=2_55		,**SCREAMING_SNAKE_CASE__		,)			->      Optional[Any]:





             """simple docstring"""






             super().__init__(**SCREAMING_SNAKE_CASE__							)

             __SCREAMING_SNAKE_CASE   :Any						=  vocab_size
             __SCREAMING_SNAKE_CASE   :Dict						=  hidden_size
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  num_hidden_layers
             __SCREAMING_SNAKE_CASE   :List[str]						=  num_attention_heads
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  intermediate_size
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  hidden_act
             __SCREAMING_SNAKE_CASE   :Tuple						=  hidden_dropout_prob
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  attention_probs_dropout_prob
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  initializer_range
             __SCREAMING_SNAKE_CASE   :str						=  layer_norm_eps

             __SCREAMING_SNAKE_CASE   :int						=  image_size
             __SCREAMING_SNAKE_CASE   :Tuple						=  patch_size
             __SCREAMING_SNAKE_CASE   :Any						=  num_channels
             __SCREAMING_SNAKE_CASE   :Any						=  use_mask_token
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  use_absolute_position_embeddings
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  use_relative_position_bias
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  use_shared_relative_position_bias
             __SCREAMING_SNAKE_CASE   :List[str]						=  layer_scale_init_value
             __SCREAMING_SNAKE_CASE   :Optional[Any]						=  drop_path_rate
             __SCREAMING_SNAKE_CASE   :str						=  use_mean_pooling
             # decode head attributes (semantic segmentation)
             __SCREAMING_SNAKE_CASE   :Dict						=  out_indices
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  pool_scales
             # auxiliary head attributes (semantic segmentation)
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  use_auxiliary_head
             __SCREAMING_SNAKE_CASE   :Union[str, Any]						=  auxiliary_loss_weight
             __SCREAMING_SNAKE_CASE   :Dict						=  auxiliary_channels
             __SCREAMING_SNAKE_CASE   :Optional[int]						=  auxiliary_num_convs
             __SCREAMING_SNAKE_CASE   :List[str]						=  auxiliary_concat_input
             __SCREAMING_SNAKE_CASE   :List[Any]						=  semantic_loss_ignore_index






class 					_SCREAMING_SNAKE_CASE(   A  ):
       SCREAMING_SNAKE_CASE_   :      List[Any]							=  version.parse('''1.11'''  )




       @property
       def     _UpperCamelCase     (						self							)			->      Mapping[str, Mapping[int, str]]:





             """simple docstring"""






             return OrderedDict(
                 [
                     ('''pixel_values''', {0: '''batch''', 1: '''num_channels''', 2: '''height''', 3: '''width'''}),
                 ]							)




       @property
       def     _UpperCamelCase     (						self							)			->      float:





             """simple docstring"""






             return 1E-4