


import copy
import os
from typing import Union

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


lowerCAmelCase	=							logging.get_logger(__name__)

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


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      Any  				=			'''pix2struct_text_model'''
							_lowercase     :      Dict  				=			['''past_key_values''']
							_lowercase     :      Optional[Any]  				=			{
							    '''hidden_size''': '''hidden_size''',
							    '''num_attention_heads''': '''num_heads''',
							    '''num_hidden_layers''': '''num_layers''',
							}

							def __init__(							self:     List[str]   ,						UpperCamelCase_:     int=50_244   ,						UpperCamelCase_:     Tuple=768   ,						UpperCamelCase_:     Optional[Any]=64   ,						UpperCamelCase_:     str=2_048   ,						UpperCamelCase_:     Dict=12   ,						UpperCamelCase_:     Union[str, Any]=12   ,						UpperCamelCase_:     int=32   ,						UpperCamelCase_:     Tuple=128   ,						UpperCamelCase_:     Dict=0.1   ,						UpperCamelCase_:     List[Any]=1E-6   ,						UpperCamelCase_:     List[Any]=1.0   ,						UpperCamelCase_:     List[Any]="gelu_new"   ,						UpperCamelCase_:     str=0   ,						UpperCamelCase_:     Tuple=False   ,						UpperCamelCase_:     Dict=0   ,						UpperCamelCase_:     Tuple=1   ,						UpperCamelCase_:     str=False   ,						UpperCamelCase_:     int=True   ,						**UpperCamelCase_:     str   ,						)      ->       Optional[Any]:





									"""simple docstring"""







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

									lowercase__						=				eos_token_id
									lowercase__						=				decoder_start_token_id

									# for backwards compatibility
									lowercase__						=				dense_act_fn

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


							@classmethod
							def 				lowerCamelCase_			(							cls:     Dict   ,						UpperCamelCase_:     Union[str, os.PathLike]   ,						**UpperCamelCase_:     Union[str, Any]							)      ->       "PretrainedConfig":





									"""simple docstring"""







									cls._set_token_in_kwargs(UpperCamelCase_							)

									lowercase__					,		lowercase__						=				cls.get_config_dict(UpperCamelCase_   ,						**UpperCamelCase_							)

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


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      Optional[int]  				=			'''pix2struct_vision_model'''

							def __init__(							self:     Dict   ,						UpperCamelCase_:     int=768   ,						UpperCamelCase_:     Any=768   ,						UpperCamelCase_:     Dict=2_048   ,						UpperCamelCase_:     Dict=64   ,						UpperCamelCase_:     List[str]=12   ,						UpperCamelCase_:     Tuple=12   ,						UpperCamelCase_:     Tuple="gelu_new"   ,						UpperCamelCase_:     int=1E-6   ,						UpperCamelCase_:     Dict=0.0   ,						UpperCamelCase_:     Union[str, Any]=0.0   ,						UpperCamelCase_:     int=1E-1_0   ,						UpperCamelCase_:     Optional[Any]=1.0   ,						UpperCamelCase_:     Union[str, Any]=4_096   ,						UpperCamelCase_:     Optional[int]=32   ,						UpperCamelCase_:     Optional[int]=128   ,						**UpperCamelCase_:     Union[str, Any]   ,						)      ->       List[Any]:





									"""simple docstring"""







									super().__init__(**UpperCamelCase_							)

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


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





									"""simple docstring"""







									cls._set_token_in_kwargs(UpperCamelCase_							)

									lowercase__					,		lowercase__						=				cls.get_config_dict(UpperCamelCase_   ,						**UpperCamelCase_							)

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


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      List[str]  				=			'''pix2struct'''
							_lowercase     :      str  				=			True

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





									"""simple docstring"""







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

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

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

									lowercase__						=				PixaStructTextConfig(**UpperCamelCase_							)
									lowercase__						=				PixaStructVisionConfig(**UpperCamelCase_							)

									lowercase__						=				self.text_config.decoder_start_token_id
									lowercase__						=				self.text_config.pad_token_id
									lowercase__						=				self.text_config.eos_token_id

									lowercase__						=				initializer_factor
									lowercase__						=				initializer_range

									lowercase__						=				self.initializer_range
									lowercase__						=				self.initializer_range

									lowercase__						=				is_vqa

							@classmethod
							def 				lowerCamelCase_			(							cls:     Optional[Any]   ,						UpperCamelCase_:     PixaStructTextConfig   ,						UpperCamelCase_:     PixaStructVisionConfig   ,						**UpperCamelCase_:     int							)      ->       Optional[Any]:





									"""simple docstring"""







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


							def 				lowerCamelCase_			(							self:     Any							)      ->       Dict:





									"""simple docstring"""







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






import copy
import os
from typing import Union

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


lowerCAmelCase	=							logging.get_logger(__name__)

lowerCAmelCase	=							{
    'microsoft/git-base': 'https://huggingface.co/microsoft/git-base/resolve/main/config.json',
}


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      int  				=			'''git_vision_model'''

							def __init__(							self:     Tuple   ,						UpperCamelCase_:     Optional[int]=768   ,						UpperCamelCase_:     Optional[int]=3_072   ,						UpperCamelCase_:     Optional[int]=12   ,						UpperCamelCase_:     Union[str, Any]=12   ,						UpperCamelCase_:     Any=3   ,						UpperCamelCase_:     str=224   ,						UpperCamelCase_:     int=16   ,						UpperCamelCase_:     Any="quick_gelu"   ,						UpperCamelCase_:     Union[str, Any]=1E-5   ,						UpperCamelCase_:     Tuple=0.0   ,						UpperCamelCase_:     Tuple=0.02   ,						**UpperCamelCase_:     str   ,						)      ->       Optional[int]:





									"""simple docstring"""







									super().__init__(**UpperCamelCase_							)

									lowercase__						=				hidden_size
									lowercase__						=				intermediate_size
									lowercase__						=				num_hidden_layers
									lowercase__						=				num_attention_heads
									lowercase__						=				num_channels
									lowercase__						=				patch_size
									lowercase__						=				image_size
									lowercase__						=				initializer_range
									lowercase__						=				attention_dropout
									lowercase__						=				layer_norm_eps
									lowercase__						=				hidden_act


							@classmethod
							def 				lowerCamelCase_			(							cls:     Optional[Any]   ,						UpperCamelCase_:     Union[str, os.PathLike]   ,						**UpperCamelCase_:     List[Any]							)      ->       "PretrainedConfig":





									"""simple docstring"""







									cls._set_token_in_kwargs(UpperCamelCase_							)

									lowercase__					,		lowercase__						=				cls.get_config_dict(UpperCamelCase_   ,						**UpperCamelCase_							)

									# get the vision config dict if we are loading from GITConfig
									if config_dict.get('''model_type'''							) == "git":
											lowercase__						=				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(UpperCamelCase_   ,						**UpperCamelCase_							)


class 	_a							(      UpperCamelCase__      ):
							_lowercase     :      Optional[int]  				=			'''git'''

							def __init__(							self:     Optional[Any]   ,						UpperCamelCase_:     Optional[Any]=None   ,						UpperCamelCase_:     List[str]=30_522   ,						UpperCamelCase_:     List[Any]=768   ,						UpperCamelCase_:     List[Any]=6   ,						UpperCamelCase_:     Union[str, Any]=12   ,						UpperCamelCase_:     Any=3_072   ,						UpperCamelCase_:     Any="gelu"   ,						UpperCamelCase_:     List[Any]=0.1   ,						UpperCamelCase_:     Dict=0.1   ,						UpperCamelCase_:     str=1_024   ,						UpperCamelCase_:     Any=0.02   ,						UpperCamelCase_:     str=1E-1_2   ,						UpperCamelCase_:     Optional[int]=0   ,						UpperCamelCase_:     Optional[Any]="absolute"   ,						UpperCamelCase_:     Optional[int]=True   ,						UpperCamelCase_:     List[Any]=False   ,						UpperCamelCase_:     List[Any]=101   ,						UpperCamelCase_:     int=102   ,						UpperCamelCase_:     List[str]=None   ,						**UpperCamelCase_:     int   ,						)      ->       Union[str, Any]:





									"""simple docstring"""







									super().__init__(bos_token_id=UpperCamelCase_   ,						eos_token_id=UpperCamelCase_   ,						pad_token_id=UpperCamelCase_   ,						**UpperCamelCase_							)

									if vision_config is None:
											lowercase__						=				{}
											logger.info('''vision_config is None. initializing the GitVisionConfig with default values.'''							)

									lowercase__						=				GitVisionConfig(**UpperCamelCase_							)
									lowercase__						=				vocab_size
									lowercase__						=				hidden_size
									lowercase__						=				num_hidden_layers
									lowercase__						=				num_attention_heads
									lowercase__						=				hidden_act
									lowercase__						=				intermediate_size
									lowercase__						=				hidden_dropout_prob
									lowercase__						=				attention_probs_dropout_prob
									lowercase__						=				max_position_embeddings
									lowercase__						=				initializer_range
									lowercase__						=				layer_norm_eps
									lowercase__						=				position_embedding_type
									lowercase__						=				use_cache
									lowercase__						=				tie_word_embeddings
									lowercase__						=				num_image_with_embedding

									lowercase__						=				bos_token_id
									lowercase__						=				eos_token_id


							def 				lowerCamelCase_			(							self:     Dict							)      ->       Tuple:





									"""simple docstring"""







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


