




"""simple docstring"""




import copy
import os
from typing import Union

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


UpperCamelCase__         =      logging.get_logger(__name__)

UpperCamelCase__         =      {
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}
class       a__   ( snake_case__				):
						_a							:   Any =   """pix2struct_text_model"""
						_a							:   List[str] =   ["""past_key_values"""]
						_a							:   Union[str, Any] =   {
						    """hidden_size""": """hidden_size""",
						    """num_attention_heads""": """num_heads""",
						    """num_hidden_layers""": """num_layers""",
						}






						def __init__(       self		,      _A=5_0_2_4_4		,      _A=7_6_8		,      _A=6_4		,      _A=2_0_4_8		,      _A=1_2		,      _A=1_2		,      _A=3_2		,      _A=1_2_8		,      _A=0.1		,      _A=1E-6		,      _A=1.0		,      _A="gelu_new"		,      _A=0		,      _A=False		,      _A=0		,      _A=1		,      _A=False		,      _A=True		,      **_A		,      ):




											"""simple docstring"""



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

											__lowerCAmelCase           =	eos_token_id
											__lowerCAmelCase           =	decoder_start_token_id

											# for backwards compatibility
											__lowerCAmelCase           =	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     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      **_A      ):




											"""simple docstring"""



											cls._set_token_in_kwargs(_A      )

											__lowerCAmelCase       ,							__lowerCAmelCase           =	cls.get_config_dict(_A		,      **_A      )

											# get the text config dict if we are loading from Pix2StructConfig
											if config_dict.get("model_type"      ) == "pix2struct":
																__lowerCAmelCase           =	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__   ( snake_case__				):
						_a							:   int =   """pix2struct_vision_model"""






						def __init__(       self		,      _A=7_6_8		,      _A=7_6_8		,      _A=2_0_4_8		,      _A=6_4		,      _A=1_2		,      _A=1_2		,      _A="gelu_new"		,      _A=1E-6		,      _A=0.0		,      _A=0.0		,      _A=1E-1_0		,      _A=1.0		,      _A=4_0_9_6		,      _A=3_2		,      _A=1_2_8		,      **_A		,      ):




											"""simple docstring"""



											super().__init__(**_A      )

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






						@classmethod
						def     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      **_A      ):




											"""simple docstring"""



											cls._set_token_in_kwargs(_A      )

											__lowerCAmelCase       ,							__lowerCAmelCase           =	cls.get_config_dict(_A		,      **_A      )

											# get the vision config dict if we are loading from Pix2StructConfig
											if config_dict.get("model_type"      ) == "pix2struct":
																__lowerCAmelCase           =	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__   ( snake_case__				):
						_a							:   Any =   """pix2struct"""
						_a							:   List[str] =   True






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




											"""simple docstring"""



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

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

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

											__lowerCAmelCase           =	PixaStructTextConfig(**_A      )
											__lowerCAmelCase           =	PixaStructVisionConfig(**_A      )

											__lowerCAmelCase           =	self.text_config.decoder_start_token_id
											__lowerCAmelCase           =	self.text_config.pad_token_id
											__lowerCAmelCase           =	self.text_config.eos_token_id

											__lowerCAmelCase           =	initializer_factor
											__lowerCAmelCase           =	initializer_range

											__lowerCAmelCase           =	self.initializer_range
											__lowerCAmelCase           =	self.initializer_range

											__lowerCAmelCase           =	is_vqa






						@classmethod
						def     __SCREAMING_SNAKE_CASE(       cls		,      _A		,      _A		,      **_A      ):




											"""simple docstring"""



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






						def     __SCREAMING_SNAKE_CASE(       self      ):




											"""simple docstring"""



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










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


UpperCamelCase__         =      logging.get_logger(__name__)

UpperCamelCase__         =      {
    """alibaba-damo/mgp-str-base""": """https://huggingface.co/alibaba-damo/mgp-str-base/resolve/main/config.json""",
}
class       a__   ( snake_case__				):
						_a							:   Dict =   """mgp-str"""






						def __init__(       self		,      _A=[3_2, 1_2_8]		,      _A=4		,      _A=3		,      _A=2_7		,      _A=3_8		,      _A=5_0_2_5_7		,      _A=3_0_5_2_2		,      _A=7_6_8		,      _A=1_2		,      _A=1_2		,      _A=4.0		,      _A=True		,      _A=False		,      _A=1E-5		,      _A=0.0		,      _A=0.0		,      _A=0.0		,      _A=False		,      _A=0.02		,      **_A		,      ):




											"""simple docstring"""



											super().__init__(**_A      )

											__lowerCAmelCase           =	image_size
											__lowerCAmelCase           =	patch_size
											__lowerCAmelCase           =	num_channels
											__lowerCAmelCase           =	max_token_length
											__lowerCAmelCase           =	num_character_labels
											__lowerCAmelCase           =	num_bpe_labels
											__lowerCAmelCase           =	num_wordpiece_labels
											__lowerCAmelCase           =	hidden_size
											__lowerCAmelCase           =	num_hidden_layers
											__lowerCAmelCase           =	num_attention_heads
											__lowerCAmelCase           =	mlp_ratio
											__lowerCAmelCase           =	distilled
											__lowerCAmelCase           =	layer_norm_eps
											__lowerCAmelCase           =	drop_rate
											__lowerCAmelCase           =	qkv_bias
											__lowerCAmelCase           =	attn_drop_rate
											__lowerCAmelCase           =	drop_path_rate
											__lowerCAmelCase           =	output_aa_attentions
											__lowerCAmelCase           =	initializer_range




