
"""simple docstring"""

import copy
import os
from typing import Union

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


UpperCamelCase			:       Dict									=				logging.get_logger(__name__)

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

class __lowerCAmelCase	(   _snake_case    ):
					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			,  __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			,  ):

						'''simple docstring'''




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

						__UpperCamelCase       						= eos_token_id
						__UpperCamelCase       						= decoder_start_token_id

						# for backwards compatibility
						__UpperCamelCase       						= 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 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  **__UpperCAmelCase   ):

						'''simple docstring'''




						cls._set_token_in_kwargs(snake_case_   )

						__UpperCamelCase       						= 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":
							__UpperCamelCase       						= 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 __lowerCAmelCase	(   _snake_case    ):
					lowercase		     =		"""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			,  ):

						'''simple docstring'''




						super().__init__(**snake_case_   )

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







					@classmethod
					def 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  **__UpperCAmelCase   ):

						'''simple docstring'''




						cls._set_token_in_kwargs(snake_case_   )

						__UpperCamelCase       						= 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":
							__UpperCamelCase       						= 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 __lowerCAmelCase	(   _snake_case    ):
					lowercase		     =		"""pix2struct"""
					lowercase		     =		True





					def __init__(			self			,  __UpperCAmelCase=None			,  __UpperCAmelCase=None			,  __UpperCAmelCase=1.0			,  __UpperCAmelCase=0.0_2			,  __UpperCAmelCase=False			,  __UpperCAmelCase=False			,  __UpperCAmelCase=True			,  **__UpperCAmelCase			,  ):

						'''simple docstring'''




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

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

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

						__UpperCamelCase       						= PixaStructTextConfig(**snake_case_   )
						__UpperCamelCase       						= PixaStructVisionConfig(**snake_case_   )

						__UpperCamelCase       						= self.text_config.decoder_start_token_id
						__UpperCamelCase       						= self.text_config.pad_token_id
						__UpperCamelCase       						= self.text_config.eos_token_id

						__UpperCamelCase       						= initializer_factor
						__UpperCamelCase       						= initializer_range

						__UpperCamelCase       						= self.initializer_range
						__UpperCamelCase       						= self.initializer_range

						__UpperCamelCase       						= is_vqa





					@classmethod
					def 		UpperCAmelCase      (			cls			,  __UpperCAmelCase			,  __UpperCAmelCase			,  **__UpperCAmelCase   ):

						'''simple docstring'''




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







					def 		UpperCAmelCase      (			self   ):

						'''simple docstring'''




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





"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


UpperCamelCase			:       Dict									=				{
    "configuration_lxmert": ["LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP", "LxmertConfig"],
    "tokenization_lxmert": ["LxmertTokenizer"],
}

try:
      if not is_tokenizers_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[str]									=				["LxmertTokenizerFast"]

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       Optional[Any]									=				[
          "LxmertEncoder",
          "LxmertForPreTraining",
          "LxmertForQuestionAnswering",
          "LxmertModel",
          "LxmertPreTrainedModel",
          "LxmertVisualFeatureEncoder",
          "LxmertXLayer",
      ]

try:
      if not is_tf_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCamelCase			:       List[Any]									=				[
          "TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST",
          "TFLxmertForPreTraining",
          "TFLxmertMainLayer",
          "TFLxmertModel",
          "TFLxmertPreTrainedModel",
          "TFLxmertVisualFeatureEncoder",
      ]


if TYPE_CHECKING:
      from .configuration_lxmert import LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP, LxmertConfig
      from .tokenization_lxmert import LxmertTokenizer

      try:
            if not is_tokenizers_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .tokenization_lxmert_fast import LxmertTokenizerFast

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_lxmert import (
                LxmertEncoder,
                LxmertForPreTraining,
                LxmertForQuestionAnswering,
                LxmertModel,
                LxmertPreTrainedModel,
                LxmertVisualFeatureEncoder,
                LxmertXLayer,
            )

      try:
            if not is_tf_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_tf_lxmert import (
                TF_LXMERT_PRETRAINED_MODEL_ARCHIVE_LIST,
                TFLxmertForPreTraining,
                TFLxmertMainLayer,
                TFLxmertModel,
                TFLxmertPreTrainedModel,
                TFLxmertVisualFeatureEncoder,
            )

else:
      import sys

      UpperCamelCase			:       Any									=				_LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)



