



'''simple docstring'''




import copy
import os
from typing import Union

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


UpperCamelCase__ :			Optional[int]												=				logging.get_logger(__name__)

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






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	Any    					=	'''pix2struct_text_model'''
			_A   :	Any    					=	['''past_key_values''']
			_A   :	Optional[int]    					=	{
			    '''hidden_size''': '''hidden_size''',
			    '''num_attention_heads''': '''num_heads''',
			    '''num_hidden_layers''': '''num_layers''',
			}

			def __init__(							self  :				List[str]							,  lowerCAmelCase__  :				Dict=5_0_2_4_4							,  lowerCAmelCase__  :				Optional[Any]=7_6_8							,  lowerCAmelCase__  :				Union[str, Any]=6_4							,  lowerCAmelCase__  :				Tuple=2_0_4_8							,  lowerCAmelCase__  :				str=1_2							,  lowerCAmelCase__  :				Union[str, Any]=1_2							,  lowerCAmelCase__  :				Optional[int]=3_2							,  lowerCAmelCase__  :				Optional[Any]=1_2_8							,  lowerCAmelCase__  :				int=0.1							,  lowerCAmelCase__  :				Optional[Any]=1E-6							,  lowerCAmelCase__  :				str=1.0							,  lowerCAmelCase__  :				str="gelu_new"							,  lowerCAmelCase__  :				str=0							,  lowerCAmelCase__  :				List[Any]=False							,  lowerCAmelCase__  :				str=0							,  lowerCAmelCase__  :				Optional[int]=1							,  lowerCAmelCase__  :				Optional[Any]=False							,  lowerCAmelCase__  :				Optional[Any]=True							,  **lowerCAmelCase__  :				Tuple							,  ):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	vocab_size
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	hidden_size
					__SCREAMING_SNAKE_CASE :	Tuple					 =	d_kv
					__SCREAMING_SNAKE_CASE :	Any					 =	d_ff
					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	num_layers
					__SCREAMING_SNAKE_CASE :	int					 =	num_heads
					__SCREAMING_SNAKE_CASE :	List[str]					 =	relative_attention_num_buckets
					__SCREAMING_SNAKE_CASE :	str					 =	relative_attention_max_distance
					__SCREAMING_SNAKE_CASE :	Any					 =	dropout_rate
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	layer_norm_epsilon
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	initializer_factor
					__SCREAMING_SNAKE_CASE :	Dict					 =	use_cache

					__SCREAMING_SNAKE_CASE :	List[str]					 =	eos_token_id
					__SCREAMING_SNAKE_CASE :	str					 =	decoder_start_token_id

					# for backwards compatibility
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	dense_act_fn

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



			@classmethod
			def UpperCamelCase__      (							cls  :				Any							,  lowerCAmelCase__  :				Union[str, os.PathLike]							,  **lowerCAmelCase__  :				str		):





					"""simple docstring"""






					cls._set_token_in_kwargs(lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Optional[int]					 =	cls.get_config_dict(lowerCAmelCase__							,  **lowerCAmelCase__		)

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






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	List[Any]    					=	'''pix2struct_vision_model'''

			def __init__(							self  :				Tuple							,  lowerCAmelCase__  :				Optional[int]=7_6_8							,  lowerCAmelCase__  :				List[Any]=7_6_8							,  lowerCAmelCase__  :				Tuple=2_0_4_8							,  lowerCAmelCase__  :				Tuple=6_4							,  lowerCAmelCase__  :				List[Any]=1_2							,  lowerCAmelCase__  :				Union[str, Any]=1_2							,  lowerCAmelCase__  :				Dict="gelu_new"							,  lowerCAmelCase__  :				int=1E-6							,  lowerCAmelCase__  :				List[str]=0.0							,  lowerCAmelCase__  :				List[str]=0.0							,  lowerCAmelCase__  :				Any=1E-10							,  lowerCAmelCase__  :				str=1.0							,  lowerCAmelCase__  :				Dict=4_0_9_6							,  lowerCAmelCase__  :				int=3_2							,  lowerCAmelCase__  :				Dict=1_2_8							,  **lowerCAmelCase__  :				List[str]							,  ):





					"""simple docstring"""






					super().__init__(**lowerCAmelCase__		)

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



			@classmethod
			def UpperCamelCase__      (							cls  :				Union[str, Any]							,  lowerCAmelCase__  :				Union[str, os.PathLike]							,  **lowerCAmelCase__  :				List[Any]		):





					"""simple docstring"""






					cls._set_token_in_kwargs(lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE ,		__SCREAMING_SNAKE_CASE :	Any					 =	cls.get_config_dict(lowerCAmelCase__							,  **lowerCAmelCase__		)

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






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	Optional[int]    					=	'''pix2struct'''
			_A   :	Any    					=	True

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





					"""simple docstring"""






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

					if text_config is None:
							__SCREAMING_SNAKE_CASE :	Tuple					 =	{}
							logger.info("""text_config is None. Initializing the Pix2StructTextConfig with default values."""		)

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

					__SCREAMING_SNAKE_CASE :	List[str]					 =	PixaStructTextConfig(**lowerCAmelCase__		)
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	PixaStructVisionConfig(**lowerCAmelCase__		)

					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	self.text_config.decoder_start_token_id
					__SCREAMING_SNAKE_CASE :	Optional[Any]					 =	self.text_config.pad_token_id
					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	self.text_config.eos_token_id

					__SCREAMING_SNAKE_CASE :	Optional[int]					 =	initializer_factor
					__SCREAMING_SNAKE_CASE :	str					 =	initializer_range

					__SCREAMING_SNAKE_CASE :	Tuple					 =	self.initializer_range
					__SCREAMING_SNAKE_CASE :	Dict					 =	self.initializer_range

					__SCREAMING_SNAKE_CASE :	Union[str, Any]					 =	is_vqa

			@classmethod
			def UpperCamelCase__      (							cls  :				Dict							,  lowerCAmelCase__  :				PixaStructTextConfig							,  lowerCAmelCase__  :				PixaStructVisionConfig							,  **lowerCAmelCase__  :				Any		):





					"""simple docstring"""






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



			def UpperCamelCase__      (							self  :				Union[str, Any]		):





					"""simple docstring"""






					__SCREAMING_SNAKE_CASE :	List[Any]					 =	copy.deepcopy(self.__dict__		)
					__SCREAMING_SNAKE_CASE :	List[Any]					 =	self.text_config.to_dict()
					__SCREAMING_SNAKE_CASE :	Dict					 =	self.vision_config.to_dict()
					__SCREAMING_SNAKE_CASE :	List[str]					 =	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


UpperCamelCase__ :			Any												=				logging.get_logger(__name__)

UpperCamelCase__ :			Dict												=				{
    '''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 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	Optional[int]    					=	'''beit'''

			def __init__(							self  :				Tuple							,  lowerCAmelCase__  :				List[Any]=8_1_9_2							,  lowerCAmelCase__  :				List[Any]=7_6_8							,  lowerCAmelCase__  :				List[Any]=1_2							,  lowerCAmelCase__  :				Union[str, Any]=1_2							,  lowerCAmelCase__  :				Dict=3_0_7_2							,  lowerCAmelCase__  :				List[Any]="gelu"							,  lowerCAmelCase__  :				List[Any]=0.0							,  lowerCAmelCase__  :				int=0.0							,  lowerCAmelCase__  :				Tuple=0.02							,  lowerCAmelCase__  :				Any=1E-12							,  lowerCAmelCase__  :				Dict=2_2_4							,  lowerCAmelCase__  :				List[str]=1_6							,  lowerCAmelCase__  :				int=3							,  lowerCAmelCase__  :				Union[str, Any]=False							,  lowerCAmelCase__  :				Union[str, Any]=False							,  lowerCAmelCase__  :				Any=False							,  lowerCAmelCase__  :				Union[str, Any]=False							,  lowerCAmelCase__  :				Optional[int]=0.1							,  lowerCAmelCase__  :				Dict=0.1							,  lowerCAmelCase__  :				Tuple=True							,  lowerCAmelCase__  :				str=[3, 5, 7, 1_1]							,  lowerCAmelCase__  :				str=[1, 2, 3, 6]							,  lowerCAmelCase__  :				Dict=True							,  lowerCAmelCase__  :				Dict=0.4							,  lowerCAmelCase__  :				int=2_5_6							,  lowerCAmelCase__  :				Any=1							,  lowerCAmelCase__  :				str=False							,  lowerCAmelCase__  :				Union[str, Any]=2_5_5							,  **lowerCAmelCase__  :				Optional[int]							,  ):





					"""simple docstring"""






					super().__init__(**lowerCAmelCase__		)

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

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






class 		_UpperCamelCase						(							lowerCamelCase__					):


			'''simple docstring'''

			_A   :	List[str]    					=	version.parse('''1.11'''					)

			@property
			def UpperCamelCase__      (							self  :				List[str]		):





					"""simple docstring"""






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



			@property
			def UpperCamelCase__      (							self  :				Any		):





					"""simple docstring"""






					return 1E-4