


"""simple docstring"""


import copy
import os
from typing import Union

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


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

A  :     Tuple    					=    {
    "google/pix2struct-textcaps-base": (
        "https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"
    ),
}
class 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					int          ="""pix2struct_text_model"""
							__UpperCAmelCase		:					int          =["""past_key_values"""]
							__UpperCAmelCase		:					int          ={
							    """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					,     ):
										__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     snake_case       (  cls					,     __a					,     **__a			):
										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 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					Any          ="""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-1_0					,     __a=1.0					,     __a=40_96					,     __a=32					,     __a=1_28					,     **__a					,     ):
										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     snake_case       (  cls					,     __a					,     **__a			):
										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 						_UpperCamelCase						(     lowerCAmelCase__	):
							'''simple docstring'''







							__UpperCAmelCase		:					Optional[int]          ="""pix2struct"""
							__UpperCAmelCase		:					Optional[int]          =True

							def __init__(  self					,     __a=None					,     __a=None					,     __a=1.0					,     __a=0.0_2					,     __a=False					,     __a=False					,     __a=True					,     **__a					,     ):
										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     snake_case       (  cls					,     __a					,     __a					,     **__a			):
										return cls(text_config=text_config.to_dict()					,     vision_config=vision_config.to_dict()					,     **__a			)



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








"""simple docstring"""


from itertools import product


def _lowerCamelCase			(	_UpperCamelCase					,				_UpperCamelCase   ):

			'''simple docstring'''




			__lowerCAmelCase       					=    sides_number
			__lowerCAmelCase       					=    max_face_number * dice_number
			__lowerCAmelCase       					=    [0] * (max_total + 1)

			__lowerCAmelCase       					=    1
			__lowerCAmelCase       					=    range(_UpperCamelCase					,				max_face_number + 1   )
			for dice_numbers in product(_UpperCamelCase					,				repeat=_UpperCamelCase   ):
						__lowerCAmelCase       					=    sum(_UpperCamelCase   )
						totals_frequencies[total] += 1

			return totals_frequencies


def _lowerCamelCase			(	):

			'''simple docstring'''




			__lowerCAmelCase       					=    total_frequency_distribution(
			    sides_number=4					,				dice_number=9   )
			__lowerCAmelCase       					=    total_frequency_distribution(
			    sides_number=6					,				dice_number=6   )

			__lowerCAmelCase       					=    0
			__lowerCAmelCase       					=    9
			__lowerCAmelCase       					=    4 * 9
			__lowerCAmelCase       					=    6
			for peter_total in range(_UpperCamelCase					,				max_peter_total + 1   ):
						peter_wins_count += peter_totals_frequencies[peter_total] * sum(
						    colin_totals_frequencies[min_colin_total:peter_total]   )

			__lowerCAmelCase       					=    (4**9) * (6**6)
			__lowerCAmelCase       					=    peter_wins_count / total_games_number

			__lowerCAmelCase       					=    round(_UpperCamelCase					,				ndigits=7   )

			return rounded_peter_win_probability


if __name__ == "__main__":
	print(f'''{solution() = }''')




