



"""simple docstring"""





import copy
import os
from typing import Union

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


lowercase					=       logging.get_logger(__name__)

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




class       lowercase__      (   A__     ):
							'''simple docstring'''







							_UpperCAmelCase   					=       '''pix2struct_text_model'''
							_UpperCAmelCase   					=       ['''past_key_values''']
							_UpperCAmelCase   					=       {
							    '''hidden_size''': '''hidden_size''',
							    '''num_attention_heads''': '''num_heads''',
							    '''num_hidden_layers''': '''num_layers''',
							}






							def __init__(	self						,							snake_case=50244						,							snake_case=768						,							snake_case=64						,							snake_case=2048						,							snake_case=12						,							snake_case=12						,							snake_case=32						,							snake_case=128						,							snake_case=0.1						,							snake_case=1E-6						,							snake_case=1.0						,							snake_case="gelu_new"						,							snake_case=0						,							snake_case=False						,							snake_case=0						,							snake_case=1						,							snake_case=False						,							snake_case=True						,							**snake_case						,							)      ->				List[str]:
									_UpperCAmelCase							=		vocab_size
									_UpperCAmelCase							=		hidden_size
									_UpperCAmelCase							=		d_kv
									_UpperCAmelCase							=		d_ff
									_UpperCAmelCase							=		num_layers
									_UpperCAmelCase							=		num_heads
									_UpperCAmelCase							=		relative_attention_num_buckets
									_UpperCAmelCase							=		relative_attention_max_distance
									_UpperCAmelCase							=		dropout_rate
									_UpperCAmelCase							=		layer_norm_epsilon
									_UpperCAmelCase							=		initializer_factor
									_UpperCAmelCase							=		use_cache

									_UpperCAmelCase							=		eos_token_id
									_UpperCAmelCase							=		decoder_start_token_id

									# for backwards compatibility
									_UpperCAmelCase							=		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 							lowerCamelCase_ (	cls						,							snake_case						,							**snake_case    )      ->				int:
									cls._set_token_in_kwargs(_lowerCamelCase    )

									_UpperCAmelCase							=		cls.get_config_dict(_lowerCamelCase						,							**_lowerCamelCase    )

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







							_UpperCAmelCase   					=       '''pix2struct_vision_model'''






							def __init__(	self						,							snake_case=768						,							snake_case=768						,							snake_case=2048						,							snake_case=64						,							snake_case=12						,							snake_case=12						,							snake_case="gelu_new"						,							snake_case=1E-6						,							snake_case=0.0						,							snake_case=0.0						,							snake_case=1E-10						,							snake_case=1.0						,							snake_case=4096						,							snake_case=32						,							snake_case=128						,							**snake_case						,							)      ->				List[Any]:
									super().__init__(**_lowerCamelCase    )

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






							@classmethod
							def 							lowerCamelCase_ (	cls						,							snake_case						,							**snake_case    )      ->				str:
									cls._set_token_in_kwargs(_lowerCamelCase    )

									_UpperCAmelCase							=		cls.get_config_dict(_lowerCamelCase						,							**_lowerCamelCase    )

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







							_UpperCAmelCase   					=       '''pix2struct'''
							_UpperCAmelCase   					=       True






							def __init__(	self						,							snake_case=None						,							snake_case=None						,							snake_case=1.0						,							snake_case=0.02						,							snake_case=False						,							snake_case=False						,							snake_case=True						,							**snake_case						,							)      ->				Optional[int]:
									super().__init__(tie_word_embeddings=_lowerCamelCase						,							is_encoder_decoder=_lowerCamelCase						,							**_lowerCamelCase    )

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

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

									_UpperCAmelCase							=		PixaStructTextConfig(**_lowerCamelCase    )
									_UpperCAmelCase							=		PixaStructVisionConfig(**_lowerCamelCase    )

									_UpperCAmelCase							=		self.text_config.decoder_start_token_id
									_UpperCAmelCase							=		self.text_config.pad_token_id
									_UpperCAmelCase							=		self.text_config.eos_token_id

									_UpperCAmelCase							=		initializer_factor
									_UpperCAmelCase							=		initializer_range

									_UpperCAmelCase							=		self.initializer_range
									_UpperCAmelCase							=		self.initializer_range

									_UpperCAmelCase							=		is_vqa






							@classmethod
							def 							lowerCamelCase_ (	cls						,							snake_case						,							snake_case						,							**snake_case    )      ->				Union[str, Any]:
									return cls(text_config=text_config.to_dict()						,							vision_config=vision_config.to_dict()						,							**_lowerCamelCase    )






							def 							lowerCamelCase_ (	self    )      ->				Dict:
									_UpperCAmelCase							=		copy.deepcopy(self.__dict__    )
									_UpperCAmelCase							=		self.text_config.to_dict()
									_UpperCAmelCase							=		self.vision_config.to_dict()
									_UpperCAmelCase							=		self.__class__.model_type
									return output




"""simple docstring"""






from typing import TYPE_CHECKING

from ....utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__SCREAMING_SNAKE_CASE							=     {
    'configuration_mctct': ['MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MCTCTConfig'],
    'feature_extraction_mctct': ['MCTCTFeatureExtractor'],
    'processing_mctct': ['MCTCTProcessor'],
}


try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __SCREAMING_SNAKE_CASE							=     [
     'MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'MCTCTForCTC',
     'MCTCTModel',
     'MCTCTPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_mctct import MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP, MCTCTConfig
 from .feature_extraction_mctct import MCTCTFeatureExtractor
 from .processing_mctct import MCTCTProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_mctct import MCTCT_PRETRAINED_MODEL_ARCHIVE_LIST, MCTCTForCTC, MCTCTModel, MCTCTPreTrainedModel

else:
 import sys

 __SCREAMING_SNAKE_CASE							=     _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
