


'''simple docstring'''







import copy
import os
from typing import Union

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


lowerCAmelCase    :     List[str]					=						logging.get_logger(__name__)

lowerCAmelCase    :     Dict					=						{
    """google/pix2struct-textcaps-base""": (
        """https://huggingface.co/google/pix2struct-textcaps-base/resolve/main/config.json"""
    ),
}
class 	UpperCamelCase__					( SCREAMING_SNAKE_CASE_	):



     """simple docstring"""






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







     def __init__( self      ,	snake_case__=5_0244      ,	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__      ,	):

            '''simple docstring'''

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

            _lowerCAmelCase    :							Optional[int]   			=       eos_token_id
            _lowerCAmelCase    :							Optional[int]   			=       decoder_start_token_id

            # for backwards compatibility
            _lowerCAmelCase    :							Dict   			=       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      ,	snake_case__      ,	**snake_case__   ):

            '''simple docstring'''

            cls._set_token_in_kwargs(snake_case__   )

            _lowerCAmelCase			,     _lowerCAmelCase    :							Optional[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":
                   _lowerCAmelCase    :							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__					( SCREAMING_SNAKE_CASE_	):



     """simple docstring"""






     __magic_name__    			=    "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__      ,	):

            '''simple docstring'''

            super().__init__(**snake_case__   )

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







     @classmethod
     def a	( cls      ,	snake_case__      ,	**snake_case__   ):

            '''simple docstring'''

            cls._set_token_in_kwargs(snake_case__   )

            _lowerCAmelCase			,     _lowerCAmelCase    :							List[Any]   			=       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":
                   _lowerCAmelCase    :							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__					( SCREAMING_SNAKE_CASE_	):



     """simple docstring"""






     __magic_name__    			=    "pix2struct"
     __magic_name__    			=    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__      ,	):

            '''simple docstring'''

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

            if text_config is None:
                   _lowerCAmelCase    :							List[Any]   			=       {}
                   logger.info('text_config is None. Initializing the Pix2StructTextConfig with default values.'   )

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

            _lowerCAmelCase    :							List[Any]   			=       PixaStructTextConfig(**snake_case__   )
            _lowerCAmelCase    :							Optional[Any]   			=       PixaStructVisionConfig(**snake_case__   )

            _lowerCAmelCase    :							Optional[Any]   			=       self.text_config.decoder_start_token_id
            _lowerCAmelCase    :							int   			=       self.text_config.pad_token_id
            _lowerCAmelCase    :							List[str]   			=       self.text_config.eos_token_id

            _lowerCAmelCase    :							Union[str, Any]   			=       initializer_factor
            _lowerCAmelCase    :							Optional[Any]   			=       initializer_range

            _lowerCAmelCase    :							Optional[Any]   			=       self.initializer_range
            _lowerCAmelCase    :							Tuple   			=       self.initializer_range

            _lowerCAmelCase    :							Tuple   			=       is_vqa







     @classmethod
     def a	( cls      ,	snake_case__      ,	snake_case__      ,	**snake_case__   ):

            '''simple docstring'''

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







     def a	( self   ):

            '''simple docstring'''

            _lowerCAmelCase    :							Optional[int]   			=       copy.deepcopy(self.__dict__   )
            _lowerCAmelCase    :							List[Any]   			=       self.text_config.to_dict()
            _lowerCAmelCase    :							Tuple   			=       self.vision_config.to_dict()
            _lowerCAmelCase    :							str   			=       self.__class__.model_type
            return output





'''simple docstring'''







from collections import OrderedDict
from typing import Mapping

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCAmelCase    :     str					=						logging.get_logger(__name__)

lowerCAmelCase    :     int					=						{
    """facebook/data2vec-text-base""": """https://huggingface.co/data2vec/resolve/main/config.json""",
}
class 	UpperCamelCase__					( SCREAMING_SNAKE_CASE_	):



     """simple docstring"""






     __magic_name__    			=    "data2vec-text"







     def __init__( self      ,	snake_case__=3_0522      ,	snake_case__=768      ,	snake_case__=12      ,	snake_case__=12      ,	snake_case__=3072      ,	snake_case__="gelu"      ,	snake_case__=0.1      ,	snake_case__=0.1      ,	snake_case__=512      ,	snake_case__=2      ,	snake_case__=0.02      ,	snake_case__=1E-12      ,	snake_case__=1      ,	snake_case__=0      ,	snake_case__=2      ,	snake_case__="absolute"      ,	snake_case__=True      ,	snake_case__=None      ,	**snake_case__      ,	):

            '''simple docstring'''

            super().__init__(pad_token_id=snake_case__      ,	bos_token_id=snake_case__      ,	eos_token_id=snake_case__      ,	**snake_case__   )

            _lowerCAmelCase    :							List[Any]   			=       vocab_size
            _lowerCAmelCase    :							Tuple   			=       hidden_size
            _lowerCAmelCase    :							Dict   			=       num_hidden_layers
            _lowerCAmelCase    :							int   			=       num_attention_heads
            _lowerCAmelCase    :							str   			=       hidden_act
            _lowerCAmelCase    :							Any   			=       intermediate_size
            _lowerCAmelCase    :							Any   			=       hidden_dropout_prob
            _lowerCAmelCase    :							Optional[int]   			=       attention_probs_dropout_prob
            _lowerCAmelCase    :							str   			=       max_position_embeddings
            _lowerCAmelCase    :							Any   			=       type_vocab_size
            _lowerCAmelCase    :							int   			=       initializer_range
            _lowerCAmelCase    :							List[str]   			=       layer_norm_eps
            _lowerCAmelCase    :							List[Any]   			=       position_embedding_type
            _lowerCAmelCase    :							str   			=       use_cache
            _lowerCAmelCase    :							Union[str, Any]   			=       classifier_dropout
class 	UpperCamelCase__					( SCREAMING_SNAKE_CASE_	):



     """simple docstring"""






     @property
     def a	( self   ):

            '''simple docstring'''

            if self.task == "multiple-choice":
                   _lowerCAmelCase    :							Union[str, Any]   			=       {0: 'batch', 1: 'choice', 2: 'sequence'}
            else:
                   _lowerCAmelCase    :							List[Any]   			=       {0: 'batch', 1: 'sequence'}
            return OrderedDict(
                [
                    ('input_ids', dynamic_axis),
                    ('attention_mask', dynamic_axis),
                ]   )

