


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

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


SCREAMING_SNAKE_CASE :    Tuple									=				logging.get_logger(__name__)

SCREAMING_SNAKE_CASE :    Optional[int]									=				{
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

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



		def __init__(self				,       a_=5_02_44				,       a_=7_68				,       a_=64				,       a_=20_48				,       a_=12				,       a_=12				,       a_=32				,       a_=1_28				,       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'''

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

			__snake_case	:						str						=				eos_token_id
			__snake_case	:						Any						=				decoder_start_token_id

			# for backwards compatibility
			__snake_case	:						List[str]						=				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_					)

			__snake_case	,							__snake_case	:						Optional[int]						=				cls.get_config_dict(a_				,       **a_					)

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






		'''simple docstring'''

		lowerCamelCase__				='pix2struct_vision_model'



		def __init__(self				,       a_=7_68				,       a_=7_68				,       a_=20_48				,       a_=64				,       a_=12				,       a_=12				,       a_="gelu_new"				,       a_=1E-6				,       a_=0.0				,       a_=0.0				,       a_=1E-10				,       a_=1.0				,       a_=40_96				,       a_=32				,       a_=1_28				,       **a_				,       ):





			'''simple docstring'''

			super().__init__(**a_					)

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



		@classmethod
		def 				SCREAMING_SNAKE_CASE  (cls				,       a_				,       **a_					):





			'''simple docstring'''

			cls._set_token_in_kwargs(a_					)

			__snake_case	,							__snake_case	:						Optional[Any]						=				cls.get_config_dict(a_				,       **a_					)

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



class 			_UpperCAmelCase (							__snake_case				):






		'''simple docstring'''

		lowerCamelCase__				='pix2struct'
		lowerCamelCase__				=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:
				__snake_case	:						List[str]						=				{}
				logger.info('''text_config is None. Initializing the Pix2StructTextConfig with default values.'''					)

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

			__snake_case	:						Dict						=				PixaStructTextConfig(**a_					)
			__snake_case	:						Optional[int]						=				PixaStructVisionConfig(**a_					)

			__snake_case	:						Any						=				self.text_config.decoder_start_token_id
			__snake_case	:						Tuple						=				self.text_config.pad_token_id
			__snake_case	:						Optional[int]						=				self.text_config.eos_token_id

			__snake_case	:						str						=				initializer_factor
			__snake_case	:						Tuple						=				initializer_range

			__snake_case	:						Tuple						=				self.initializer_range
			__snake_case	:						str						=				self.initializer_range

			__snake_case	:						Union[str, Any]						=				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'''

			__snake_case	:						Optional[int]						=				copy.deepcopy(self.__dict__					)
			__snake_case	:						Optional[int]						=				self.text_config.to_dict()
			__snake_case	:						Dict						=				self.vision_config.to_dict()
			__snake_case	:						str						=				self.__class__.model_type
			return output









"""simple docstring"""
import numpy as np






def 		lowercase							(     _snake_case						:      int     ,   _snake_case						:      Optional[Any]     ,   _snake_case						:      Optional[int]     ,   _snake_case						:      int     ,   _snake_case						:      Union[str, Any]     )     ->Dict:
	"""simple docstring"""





	__snake_case	:						Union[str, Any]						=				int(np.ceil((x_end - xa) / h     )     )
	__snake_case	:						Dict						=				np.zeros((n + 1,)     )
	__snake_case	:						List[Any]						=				ya
	__snake_case	:						int						=				xa

	for k in range(_snake_case     ):
		__snake_case	:						Any						=				f(_snake_case     ,   y[k]     )
		__snake_case	:						List[Any]						=				f(x + 0.5 * h     ,   y[k] + 0.5 * h * ka     )
		__snake_case	:						int						=				f(x + 0.5 * h     ,   y[k] + 0.5 * h * ka     )
		__snake_case	:						Optional[int]						=				f(x + h     ,   y[k] + h * ka     )
		__snake_case	:						Optional[int]						=				y[k] + (1 / 6) * h * (ka + 2 * ka + 2 * ka + ka)
		x += h

	return y


if __name__ == "__main__":
			import doctest

			doctest.testmod()





