





import copy
import os
from typing import Union

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


__lowercase       :List[Any]       =  logging.get_logger(__name__)

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



class    UpperCamelCase__     (				_a							):






							"""simple docstring"""

							snake_case_							 =						"""pix2struct_text_model"""
							snake_case_							 =						["""past_key_values"""]
							snake_case_							 =						{
							    """hidden_size""": """hidden_size""",
							    """num_attention_heads""": """num_heads""",
							    """num_hidden_layers""": """num_layers""",
							}

							def __init__(      self				:     Union[str, Any]							,	a				:     Optional[Any]=5_02_44							,	a				:     List[Any]=7_68							,	a				:     Optional[int]=64							,	a				:     Union[str, Any]=20_48							,	a				:     int=12							,	a				:     Dict=12							,	a				:     Dict=32							,	a				:     List[Any]=1_28							,	a				:     Union[str, Any]=0.1							,	a				:     Tuple=1E-6							,	a				:     Optional[Any]=1.0							,	a				:     Optional[Any]="gelu_new"							,	a				:     Tuple=0							,	a				:     List[str]=False							,	a				:     Optional[Any]=0							,	a				:     str=1							,	a				:     Dict=False							,	a				:     Dict=True							,	**a				:     Optional[Any]							,	)	->List[Any]:
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					vocab_size
													SCREAMING_SNAKE_CASE__     :				List[str]   =					hidden_size
													SCREAMING_SNAKE_CASE__     :				List[str]   =					d_kv
													SCREAMING_SNAKE_CASE__     :				Dict   =					d_ff
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					num_layers
													SCREAMING_SNAKE_CASE__     :				Dict   =					num_heads
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					relative_attention_num_buckets
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					relative_attention_max_distance
													SCREAMING_SNAKE_CASE__     :				List[str]   =					dropout_rate
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					layer_norm_epsilon
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					initializer_factor
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					use_cache

													SCREAMING_SNAKE_CASE__     :				Any   =					eos_token_id
													SCREAMING_SNAKE_CASE__     :				Tuple   =					decoder_start_token_id

													# for backwards compatibility
													SCREAMING_SNAKE_CASE__     :				str   =					dense_act_fn

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






							@classmethod
							def      A_  (      cls				:     Optional[int]							,	a				:     Dict							,	**a				:     List[Any]    )	->"PretrainedConfig":
													cls._set_token_in_kwargs(snake_case_    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Any   =					cls.get_config_dict(snake_case_							,	**snake_case_    )

													# 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(snake_case_							,	**snake_case_    )







class    UpperCamelCase__     (				_a							):






							"""simple docstring"""

							snake_case_							 =						"""pix2struct_vision_model"""

							def __init__(      self				:     Optional[int]							,	a				:     Optional[int]=7_68							,	a				:     List[Any]=7_68							,	a				:     Any=20_48							,	a				:     List[Any]=64							,	a				:     Any=12							,	a				:     Any=12							,	a				:     Dict="gelu_new"							,	a				:     Optional[Any]=1E-6							,	a				:     Optional[Any]=0.0							,	a				:     Dict=0.0							,	a				:     Tuple=1E-10							,	a				:     Any=1.0							,	a				:     str=40_96							,	a				:     Tuple=32							,	a				:     int=1_28							,	**a				:     Any							,	)	->Union[str, Any]:
													super().__init__(**snake_case_    )

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






							@classmethod
							def      A_  (      cls				:     str							,	a				:     Union[str, Any]							,	**a				:     List[Any]    )	->"PretrainedConfig":
													cls._set_token_in_kwargs(snake_case_    )

													SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				str   =					cls.get_config_dict(snake_case_							,	**snake_case_    )

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







class    UpperCamelCase__     (				_a							):






							"""simple docstring"""

							snake_case_							 =						"""pix2struct"""
							snake_case_							 =						True

							def __init__(      self				:     List[Any]							,	a				:     str=None							,	a				:     Optional[Any]=None							,	a				:     Any=1.0							,	a				:     List[str]=0.02							,	a				:     Union[str, Any]=False							,	a				:     int=False							,	a				:     List[str]=True							,	**a				:     Optional[int]							,	)	->List[str]:
													super().__init__(tie_word_embeddings=snake_case_							,	is_encoder_decoder=snake_case_							,	**snake_case_    )

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

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

													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					PixaStructTextConfig(**snake_case_    )
													SCREAMING_SNAKE_CASE__     :				str   =					PixaStructVisionConfig(**snake_case_    )

													SCREAMING_SNAKE_CASE__     :				Tuple   =					self.text_config.decoder_start_token_id
													SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.text_config.pad_token_id
													SCREAMING_SNAKE_CASE__     :				Dict   =					self.text_config.eos_token_id

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					initializer_factor
													SCREAMING_SNAKE_CASE__     :				str   =					initializer_range

													SCREAMING_SNAKE_CASE__     :				str   =					self.initializer_range
													SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					self.initializer_range

													SCREAMING_SNAKE_CASE__     :				List[Any]   =					is_vqa

							@classmethod
							def      A_  (      cls				:     Dict							,	a				:     Optional[Any]							,	a				:     int							,	**a				:     Union[str, Any]    )	->List[str]:
													return cls(text_config=text_config.to_dict()							,	vision_config=vision_config.to_dict()							,	**snake_case_    )






							def      A_  (      self				:     Optional[Any]    )	->Any:
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					copy.deepcopy(self.__dict__    )
													SCREAMING_SNAKE_CASE__     :				str   =					self.text_config.to_dict()
													SCREAMING_SNAKE_CASE__     :				Any   =					self.vision_config.to_dict()
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					self.__class__.model_type
													return output






from __future__ import annotations

from fractions import Fraction







def       UpperCAmelCase							(     _lowerCamelCase      :  int			,   _lowerCamelCase      :  int     ):





						'''simple docstring'''


						return (
						    num != den and num % 10 == den // 10 and (num // 10) / (den % 10) == num / den
						)







def       UpperCAmelCase							(     _lowerCamelCase      :  int     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				int   =					[]
						SCREAMING_SNAKE_CASE__     :				str   =					11
						SCREAMING_SNAKE_CASE__     :				Any   =					int("1" + "0" * digit_len     )
						for num in range(_lowerCamelCase			,   _lowerCamelCase     ):
												while den <= 99:
																		if (num != den) and (num % 10 == den // 10) and (den % 10 != 0):
																								if is_digit_cancelling(_lowerCamelCase			,   _lowerCamelCase     ):
																														solutions.append(f"""{num}/{den}"""     )
																		den += 1
												num += 1
												SCREAMING_SNAKE_CASE__     :				str   =					10
						return solutions







def       UpperCAmelCase							(     _lowerCamelCase      :  int = 2     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					1.0
						for fraction in fraction_list(_lowerCamelCase     ):
												SCREAMING_SNAKE_CASE__     :				Any   =					Fraction(_lowerCamelCase     )
												result *= frac.denominator / frac.numerator
						return int(_lowerCamelCase     )


if __name__ == "__main__":
				print(solution())