


"""simple docstring"""



import copy
import os
from typing import Union

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


__snake_case       =       logging.get_logger(__name__)

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







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			Optional[Any]				    =    '''pix2struct_text_model'''
   __UpperCAmelCase					:			List[Any]				    =    ['''past_key_values''']
   __UpperCAmelCase					:			Dict				    =    {
       '''hidden_size''': '''hidden_size''',
       '''num_attention_heads''': '''num_heads''',
       '''num_hidden_layers''': '''num_layers''',
   }







   def __init__(      self		,      UpperCamelCase__=5_0244		,      UpperCamelCase__=768		,      UpperCamelCase__=64		,      UpperCamelCase__=2048		,      UpperCamelCase__=12		,      UpperCamelCase__=12		,      UpperCamelCase__=32		,      UpperCamelCase__=128		,      UpperCamelCase__=0.1		,      UpperCamelCase__=1e-6		,      UpperCamelCase__=1.0		,      UpperCamelCase__="gelu_new"		,      UpperCamelCase__=0		,      UpperCamelCase__=False		,      UpperCamelCase__=0		,      UpperCamelCase__=1		,      UpperCamelCase__=False		,      UpperCamelCase__=True		,      **UpperCamelCase__		,      )      ->						List[Any]:

       '''simple docstring'''




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

       snake_case       : Tuple    =       eos_token_id
       snake_case       : str    =       decoder_start_token_id

       # for backwards compatibility
       snake_case       : Any    =       dense_act_fn

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







   @classmethod
   def 					lowerCamelCase						(      cls		,      UpperCamelCase__		,      **UpperCamelCase__		)      ->						"PretrainedConfig":

       '''simple docstring'''




       cls._set_token_in_kwargs(UpperCamelCase__		)

       snake_case   ,snake_case       : Any    =       cls.get_config_dict(UpperCamelCase__		,      **UpperCamelCase__		)

       # get the text config dict if we are loading from Pix2StructConfig
       if config_dict.get("model_type"		) == "pix2struct":
           snake_case       : Dict    =       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(UpperCamelCase__		,      **UpperCamelCase__		)







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			Union[str, Any]				    =    '''pix2struct_vision_model'''







   def __init__(      self		,      UpperCamelCase__=768		,      UpperCamelCase__=768		,      UpperCamelCase__=2048		,      UpperCamelCase__=64		,      UpperCamelCase__=12		,      UpperCamelCase__=12		,      UpperCamelCase__="gelu_new"		,      UpperCamelCase__=1e-6		,      UpperCamelCase__=0.0		,      UpperCamelCase__=0.0		,      UpperCamelCase__=1e-10		,      UpperCamelCase__=1.0		,      UpperCamelCase__=4096		,      UpperCamelCase__=32		,      UpperCamelCase__=128		,      **UpperCamelCase__		,      )      ->						Dict:

       '''simple docstring'''




       super().__init__(**UpperCamelCase__		)

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







   @classmethod
   def 					lowerCamelCase						(      cls		,      UpperCamelCase__		,      **UpperCamelCase__		)      ->						"PretrainedConfig":

       '''simple docstring'''




       cls._set_token_in_kwargs(UpperCamelCase__		)

       snake_case   ,snake_case       : Optional[Any]    =       cls.get_config_dict(UpperCamelCase__		,      **UpperCamelCase__		)

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







class _lowerCAmelCase							( snake_case_      ):
   __UpperCAmelCase					:			Optional[Any]				    =    '''pix2struct'''
   __UpperCAmelCase					:			Dict				    =    True







   def __init__(      self		,      UpperCamelCase__=None		,      UpperCamelCase__=None		,      UpperCamelCase__=1.0		,      UpperCamelCase__=0.02		,      UpperCamelCase__=False		,      UpperCamelCase__=False		,      UpperCamelCase__=True		,      **UpperCamelCase__		,      )      ->						Any:

       '''simple docstring'''




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

       if text_config is None:
           snake_case       : List[str]    =       {}
           logger.info("text_config is None. Initializing the Pix2StructTextConfig with default values."		)

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

       snake_case       : Optional[Any]    =       PixaStructTextConfig(**UpperCamelCase__		)
       snake_case       : Tuple    =       PixaStructVisionConfig(**UpperCamelCase__		)

       snake_case       : List[str]    =       self.text_config.decoder_start_token_id
       snake_case       : List[Any]    =       self.text_config.pad_token_id
       snake_case       : Tuple    =       self.text_config.eos_token_id

       snake_case       : Optional[int]    =       initializer_factor
       snake_case       : Tuple    =       initializer_range

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

       snake_case       : Optional[Any]    =       is_vqa







   @classmethod
   def 					lowerCamelCase						(      cls		,      UpperCamelCase__		,      UpperCamelCase__		,      **UpperCamelCase__		)      ->						Tuple:

       '''simple docstring'''




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







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

       '''simple docstring'''




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









"""simple docstring"""



from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


__snake_case       =       {
    """configuration_bigbird_pegasus""": [
        """BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """BigBirdPegasusConfig""",
        """BigBirdPegasusOnnxConfig""",
    ],
}

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  __snake_case       =       [
      """BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST""",
      """BigBirdPegasusForCausalLM""",
      """BigBirdPegasusForConditionalGeneration""",
      """BigBirdPegasusForQuestionAnswering""",
      """BigBirdPegasusForSequenceClassification""",
      """BigBirdPegasusModel""",
      """BigBirdPegasusPreTrainedModel""",
  ]


if TYPE_CHECKING:
  from .configuration_bigbird_pegasus import (
      BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP,
      BigBirdPegasusConfig,
      BigBirdPegasusOnnxConfig,
  )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_bigbird_pegasus import (
        BIGBIRD_PEGASUS_PRETRAINED_MODEL_ARCHIVE_LIST,
        BigBirdPegasusForCausalLM,
        BigBirdPegasusForConditionalGeneration,
        BigBirdPegasusForQuestionAnswering,
        BigBirdPegasusForSequenceClassification,
        BigBirdPegasusModel,
        BigBirdPegasusPreTrainedModel,
    )


else:
  import sys

  __snake_case       =       _LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)





