

'''simple docstring'''
import copy
import os
from typing import Union

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


lowerCamelCase			:				Optional[Any] 			=					logging.get_logger(__name__)

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







class 							A__   (	A__  ):
  A__					=    'pix2struct_text_model'
  A__					=    ['past_key_values']
  A__					=    {
      'hidden_size': 'hidden_size',
      'num_attention_heads': 'num_heads',
      'num_hidden_layers': 'num_layers',
  }





  def __init__(		self				:     Union[str, Any]							, _a				:     List[Any]=5_0244							, _a				:     Optional[int]=768							, _a				:     Tuple=64							, _a				:     List[str]=2048							, _a				:     int=12							, _a				:     Optional[int]=12							, _a				:     Dict=32							, _a				:     Any=128							, _a				:     List[str]=0.1							, _a				:     List[Any]=1e-6							, _a				:     Optional[Any]=1.0							, _a				:     Optional[Any]="gelu_new"							, _a				:     List[str]=0							, _a				:     Tuple=False							, _a				:     Optional[int]=0							, _a				:     Optional[int]=1							, _a				:     Any=False							, _a				:     List[Any]=True							, **_a				:     Union[str, Any]							, )     ->   List[Any]:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =vocab_size
       _SCREAMING_SNAKE_CASE							   =hidden_size
       _SCREAMING_SNAKE_CASE							   =d_kv
       _SCREAMING_SNAKE_CASE							   =d_ff
       _SCREAMING_SNAKE_CASE							   =num_layers
       _SCREAMING_SNAKE_CASE							   =num_heads
       _SCREAMING_SNAKE_CASE							   =relative_attention_num_buckets
       _SCREAMING_SNAKE_CASE							   =relative_attention_max_distance
       _SCREAMING_SNAKE_CASE							   =dropout_rate
       _SCREAMING_SNAKE_CASE							   =layer_norm_epsilon
       _SCREAMING_SNAKE_CASE							   =initializer_factor
       _SCREAMING_SNAKE_CASE							   =use_cache

       _SCREAMING_SNAKE_CASE							   =eos_token_id
       _SCREAMING_SNAKE_CASE							   =decoder_start_token_id

       # for backwards compatibility
       _SCREAMING_SNAKE_CASE							   =dense_act_fn

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





  @classmethod
  def 						A  (		cls				:     str							, _a				:     Union[str, os.PathLike]							, **_a				:     int			)     ->   "PretrainedConfig":





       '''simple docstring'''






       cls._set_token_in_kwargs(_a			)

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

       # get the text config dict if we are loading from Pix2StructConfig
       if config_dict.get('model_type'			) == "pix2struct":
            _SCREAMING_SNAKE_CASE							   =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(_a							, **_a			)







class 							A__   (	A__  ):
  A__					=    'pix2struct_vision_model'





  def __init__(		self				:     Dict							, _a				:     Union[str, Any]=768							, _a				:     Union[str, Any]=768							, _a				:     Union[str, Any]=2048							, _a				:     Optional[Any]=64							, _a				:     Optional[Any]=12							, _a				:     Optional[Any]=12							, _a				:     Optional[Any]="gelu_new"							, _a				:     int=1e-6							, _a				:     List[Any]=0.0							, _a				:     str=0.0							, _a				:     Optional[int]=1e-10							, _a				:     int=1.0							, _a				:     List[str]=4096							, _a				:     Optional[Any]=32							, _a				:     Tuple=128							, **_a				:     Dict							, )     ->   Optional[Any]:





       '''simple docstring'''






       super().__init__(**_a			)

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





  @classmethod
  def 						A  (		cls				:     int							, _a				:     Union[str, os.PathLike]							, **_a				:     Union[str, Any]			)     ->   "PretrainedConfig":





       '''simple docstring'''






       cls._set_token_in_kwargs(_a			)

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

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







class 							A__   (	A__  ):
  A__					=    'pix2struct'
  A__					=    True





  def __init__(		self				:     Optional[int]							, _a				:     Any=None							, _a				:     Union[str, Any]=None							, _a				:     Union[str, Any]=1.0							, _a				:     Union[str, Any]=0.02							, _a				:     Optional[Any]=False							, _a				:     str=False							, _a				:     Any=True							, **_a				:     List[str]							, )     ->   Any:





       '''simple docstring'''






       super().__init__(tie_word_embeddings=_a							, is_encoder_decoder=_a							, **_a			)

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

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

       _SCREAMING_SNAKE_CASE							   =PixaStructTextConfig(**_a			)
       _SCREAMING_SNAKE_CASE							   =PixaStructVisionConfig(**_a			)

       _SCREAMING_SNAKE_CASE							   =self.text_config.decoder_start_token_id
       _SCREAMING_SNAKE_CASE							   =self.text_config.pad_token_id
       _SCREAMING_SNAKE_CASE							   =self.text_config.eos_token_id

       _SCREAMING_SNAKE_CASE							   =initializer_factor
       _SCREAMING_SNAKE_CASE							   =initializer_range

       _SCREAMING_SNAKE_CASE							   =self.initializer_range
       _SCREAMING_SNAKE_CASE							   =self.initializer_range

       _SCREAMING_SNAKE_CASE							   =is_vqa





  @classmethod
  def 						A  (		cls				:     List[str]							, _a				:     PixaStructTextConfig							, _a				:     PixaStructVisionConfig							, **_a				:     Dict			)     ->   Optional[int]:





       '''simple docstring'''






       return cls(text_config=text_config.to_dict()							, vision_config=vision_config.to_dict()							, **_a			)





  def 						A  (		self				:     Dict			)     ->   Any:





       '''simple docstring'''






       _SCREAMING_SNAKE_CASE							   =copy.deepcopy(self.__dict__			)
       _SCREAMING_SNAKE_CASE							   =self.text_config.to_dict()
       _SCREAMING_SNAKE_CASE							   =self.vision_config.to_dict()
       _SCREAMING_SNAKE_CASE							   =self.__class__.model_type
       return output



'''simple docstring'''
import warnings


warnings.warn(
    "memory_utils has been reorganized to utils.memory. Import `find_executable_batchsize` from the main `__init__`: "
    "`from accelerate import find_executable_batch_size` to avoid this warning.",
    FutureWarning,
)
