


"""simple docstring"""







import copy
import os
from typing import Union

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


lowerCAmelCase__      				=   logging.get_logger(__name__)

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


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				Tuple   ="pix2struct_text_model"
       a  :				Optional[int]   =["past_key_values"]
       a  :				Union[str, Any]   ={
           "hidden_size": "hidden_size",
           "num_attention_heads": "num_heads",
           "num_hidden_layers": "num_layers",
       }

       def __init__(						self		,     snake_case__=50_244		,     snake_case__=768		,     snake_case__=64		,     snake_case__=2_048		,     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     :     List[str]								=							hidden_size
         lowerCAmelCase     :     List[Any]								=							d_kv
         lowerCAmelCase     :     str								=							d_ff
         lowerCAmelCase     :     Union[str, Any]								=							num_layers
         lowerCAmelCase     :     Dict								=							num_heads
         lowerCAmelCase     :     Optional[int]								=							relative_attention_num_buckets
         lowerCAmelCase     :     Union[str, Any]								=							relative_attention_max_distance
         lowerCAmelCase     :     str								=							dropout_rate
         lowerCAmelCase     :     Union[str, Any]								=							layer_norm_epsilon
         lowerCAmelCase     :     List[Any]								=							initializer_factor
         lowerCAmelCase     :     int								=							use_cache

         lowerCAmelCase     :     List[Any]								=							eos_token_id
         lowerCAmelCase     :     Tuple								=							decoder_start_token_id

         # for backwards compatibility
         lowerCAmelCase     :     int								=							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        lowercase__							(						cls		,     snake_case__		,     **snake_case__						):






         """simple docstring"""





         cls._set_token_in_kwargs(snake_case__						)

         lowerCAmelCase						,  lowerCAmelCase     :     int								=							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     :     List[Any]								=							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       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				Optional[Any]   ="pix2struct_vision_model"

       def __init__(						self		,     snake_case__=768		,     snake_case__=768		,     snake_case__=2_048		,     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__=4_096		,     snake_case__=32		,     snake_case__=128		,     **snake_case__		,     ):






         """simple docstring"""





         super().__init__(**snake_case__						)

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







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






         """simple docstring"""





         cls._set_token_in_kwargs(snake_case__						)

         lowerCAmelCase						,  lowerCAmelCase     :     Dict								=							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     :     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(snake_case__		,     **snake_case__						)


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				Optional[Any]   ="pix2struct"
       a  :				Union[str, Any]   =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     :     Any								=							{}
           logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."						)

         if vision_config is None:
           lowerCAmelCase     :     List[Any]								=							{}
           logger.info("vision_config is None. Initializing the Pix2StructVisionConfig with default values."						)

         lowerCAmelCase     :     Union[str, Any]								=							PixaStructTextConfig(**snake_case__						)
         lowerCAmelCase     :     Optional[Any]								=							PixaStructVisionConfig(**snake_case__						)

         lowerCAmelCase     :     str								=							self.text_config.decoder_start_token_id
         lowerCAmelCase     :     Optional[Any]								=							self.text_config.pad_token_id
         lowerCAmelCase     :     str								=							self.text_config.eos_token_id

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

         lowerCAmelCase     :     Optional[Any]								=							self.initializer_range
         lowerCAmelCase     :     Optional[Any]								=							self.initializer_range

         lowerCAmelCase     :     List[Any]								=							is_vqa

       @classmethod
       def        lowercase__							(						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        lowercase__							(						self						):






         """simple docstring"""





         lowerCAmelCase     :     Tuple								=							copy.deepcopy(self.__dict__						)
         lowerCAmelCase     :     Tuple								=							self.text_config.to_dict()
         lowerCAmelCase     :     Union[str, Any]								=							self.vision_config.to_dict()
         lowerCAmelCase     :     str								=							self.__class__.model_type
         return output









"""simple docstring"""







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


lowerCAmelCase__      				=   logging.get_logger(__name__)

lowerCAmelCase__      				=   {
    '''facebook/dpr-ctx_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-single-nq-base''': (
        '''https://huggingface.co/facebook/dpr-reader-single-nq-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-ctx_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-ctx_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-question_encoder-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-question_encoder-multiset-base/resolve/main/config.json'''
    ),
    '''facebook/dpr-reader-multiset-base''': (
        '''https://huggingface.co/facebook/dpr-reader-multiset-base/resolve/main/config.json'''
    ),
}


class       SCREAMING_SNAKE_CASE__				(		lowercase				):
       """simple docstring"""


       a  :				int   ="dpr"

       def __init__(						self		,     snake_case__=30_522		,     snake_case__=768		,     snake_case__=12		,     snake_case__=12		,     snake_case__=3_072		,     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__=0		,     snake_case__="absolute"		,     snake_case__ = 0		,     **snake_case__		,     ):






         """simple docstring"""





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

         lowerCAmelCase     :     Union[str, Any]								=							vocab_size
         lowerCAmelCase     :     str								=							hidden_size
         lowerCAmelCase     :     Any								=							num_hidden_layers
         lowerCAmelCase     :     Optional[int]								=							num_attention_heads
         lowerCAmelCase     :     Union[str, Any]								=							hidden_act
         lowerCAmelCase     :     Dict								=							intermediate_size
         lowerCAmelCase     :     Union[str, Any]								=							hidden_dropout_prob
         lowerCAmelCase     :     Dict								=							attention_probs_dropout_prob
         lowerCAmelCase     :     Dict								=							max_position_embeddings
         lowerCAmelCase     :     Tuple								=							type_vocab_size
         lowerCAmelCase     :     Any								=							initializer_range
         lowerCAmelCase     :     Any								=							layer_norm_eps
         lowerCAmelCase     :     Dict								=							projection_dim
         lowerCAmelCase     :     Dict								=							position_embedding_type





