




'''simple docstring'''


import copy
import os
from typing import Union

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


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

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

class     A					(	_a					):
							lowercase_           =       'pix2struct_text_model'
							lowercase_           =       ['past_key_values']
							lowercase_           =       {
							    'hidden_size': 'hidden_size',
							    'num_attention_heads': 'num_heads',
							    'num_hidden_layers': 'num_layers',
							}







							def __init__(						self :						Any							,    lowerCAmelCase_ :						Optional[int]=5_02_44							,    lowerCAmelCase_ :						Optional[int]=7_68							,    lowerCAmelCase_ :						Tuple=64							,    lowerCAmelCase_ :						Dict=20_48							,    lowerCAmelCase_ :						str=12							,    lowerCAmelCase_ :						Any=12							,    lowerCAmelCase_ :						List[Any]=32							,    lowerCAmelCase_ :						int=1_28							,    lowerCAmelCase_ :						List[Any]=0.1							,    lowerCAmelCase_ :						int=1e-6							,    lowerCAmelCase_ :						Union[str, Any]=1.0							,    lowerCAmelCase_ :						Optional[Any]="gelu_new"							,    lowerCAmelCase_ :						Union[str, Any]=0							,    lowerCAmelCase_ :						Tuple=False							,    lowerCAmelCase_ :						str=0							,    lowerCAmelCase_ :						Dict=1							,    lowerCAmelCase_ :						Any=False							,    lowerCAmelCase_ :						Dict=True							,    **lowerCAmelCase_ :						List[str]							,    )    ->							List[str]:


														"""simple docstring"""


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

														_a			  =       eos_token_id
														_a			  =       decoder_start_token_id

														# for backwards compatibility
														_a			  =       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 :						List[str]							,    lowerCAmelCase_ :						Union[str, os.PathLike]							,    **lowerCAmelCase_ :						Union[str, Any]      )    ->							"PretrainedConfig":


														"""simple docstring"""


														cls._set_token_in_kwargs(lowerCAmelCase_      )

														_a  ,							_a			  =       cls.get_config_dict(lowerCAmelCase_							,    **lowerCAmelCase_      )

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







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


														"""simple docstring"""


														super().__init__(**lowerCAmelCase_      )

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







							@classmethod
							def      __lowerCAmelCase    (						cls :						Dict							,    lowerCAmelCase_ :						Union[str, os.PathLike]							,    **lowerCAmelCase_ :						Any      )    ->							"PretrainedConfig":


														"""simple docstring"""


														cls._set_token_in_kwargs(lowerCAmelCase_      )

														_a  ,							_a			  =       cls.get_config_dict(lowerCAmelCase_							,    **lowerCAmelCase_      )

														# get the vision config dict if we are loading from Pix2StructConfig
														if config_dict.get('''model_type'''      ) == "pix2struct":
																					_a			  =       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     A					(	_a					):
							lowercase_           =       'pix2struct'
							lowercase_           =       True







							def __init__(						self :						List[Any]							,    lowerCAmelCase_ :						Union[str, Any]=None							,    lowerCAmelCase_ :						List[Any]=None							,    lowerCAmelCase_ :						Optional[Any]=1.0							,    lowerCAmelCase_ :						List[Any]=0.0_2							,    lowerCAmelCase_ :						Any=False							,    lowerCAmelCase_ :						Any=False							,    lowerCAmelCase_ :						Dict=True							,    **lowerCAmelCase_ :						str							,    )    ->							Optional[int]:


														"""simple docstring"""


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

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

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

														_a			  =       PixaStructTextConfig(**lowerCAmelCase_      )
														_a			  =       PixaStructVisionConfig(**lowerCAmelCase_      )

														_a			  =       self.text_config.decoder_start_token_id
														_a			  =       self.text_config.pad_token_id
														_a			  =       self.text_config.eos_token_id

														_a			  =       initializer_factor
														_a			  =       initializer_range

														_a			  =       self.initializer_range
														_a			  =       self.initializer_range

														_a			  =       is_vqa







							@classmethod
							def      __lowerCAmelCase    (						cls :						Optional[int]							,    lowerCAmelCase_ :						PixaStructTextConfig							,    lowerCAmelCase_ :						PixaStructVisionConfig							,    **lowerCAmelCase_ :						Optional[int]      )    ->							Optional[int]:


														"""simple docstring"""


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







							def      __lowerCAmelCase    (						self :						Union[str, Any]      )    ->							int:


														"""simple docstring"""


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







'''simple docstring'''


import unittest

from transformers import load_tool

from .test_tools_common import ToolTesterMixin


_snake_case   :   str     							=	'\nHugging Face was founded in 2016 by French entrepreneurs Clément Delangue, Julien Chaumond, and Thomas Wolf originally as a company that developed a chatbot app targeted at teenagers.[2] After open-sourcing the model behind the chatbot, the company pivoted to focus on being a platform for machine learning.\n\nIn March 2021, Hugging Face raised $40 million in a Series B funding round.[3]\n\nOn April 28, 2021, the company launched the BigScience Research Workshop in collaboration with several other research groups to release an open large language model.[4] In 2022, the workshop concluded with the announcement of BLOOM, a multilingual large language model with 176 billion parameters.[5]\n'

class     A					(	unittest.TestCase  ,_a					):







							def      __lowerCAmelCase    (						self :						Any      )    ->							Dict:


														"""simple docstring"""


														_a			  =       load_tool('''text-question-answering'''      )
														self.tool.setup()
														_a			  =       load_tool('''text-question-answering'''							,    remote=lowerCAmelCase_      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							Optional[int]:


														"""simple docstring"""


														_a			  =       self.tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						Union[str, Any]      )    ->							Dict:


														"""simple docstring"""


														_a			  =       self.remote_tool(lowerCAmelCase_							,    '''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						List[Any]      )    ->							List[str]:


														"""simple docstring"""


														_a			  =       self.tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )







							def      __lowerCAmelCase    (						self :						int      )    ->							List[Any]:


														"""simple docstring"""


														_a			  =       self.remote_tool(text=lowerCAmelCase_							,    question='''What did Hugging Face do in April 2021?'''      )
														self.assertEqual(lowerCAmelCase_							,    '''launched the BigScience Research Workshop'''      )

