"""simple docstring"""






import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...models.auto.modeling_auto import MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
from ...utils import logging
from ..auto import CONFIG_MAPPING


__lowerCAmelCase					: Optional[Any]        =logging.get_logger(__name__)

__lowerCAmelCase					: List[Any]        ={
    """Salesforce/instruct-blip-flan-t5""": """https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json""",
}





class 				_A		( lowerCAmelCase			):
      snake_case__    :     int													=			'instructblip_vision_model'

      def __init__(		self	, __lowerCAmelCase=1408	, __lowerCAmelCase=6144	, __lowerCAmelCase=39	, __lowerCAmelCase=16	, __lowerCAmelCase=224	, __lowerCAmelCase=14	, __lowerCAmelCase="gelu"	, __lowerCAmelCase=1E-6	, __lowerCAmelCase=0.0	, __lowerCAmelCase=1E-10	, __lowerCAmelCase=True	, **__lowerCAmelCase	, ):







            """simple docstring"""



            super().__init__(**__lowerCAmelCase		)

            lowercase														=			hidden_size
            lowercase														=			intermediate_size
            lowercase														=			num_hidden_layers
            lowercase														=			num_attention_heads
            lowercase														=			patch_size
            lowercase														=			image_size
            lowercase														=			initializer_range
            lowercase														=			attention_dropout
            lowercase														=			layer_norm_eps
            lowercase														=			hidden_act
            lowercase														=			qkv_bias







      @classmethod
      def        A__ (		cls	, __lowerCAmelCase	, **__lowerCAmelCase		):







            """simple docstring"""



            cls._set_token_in_kwargs(__lowerCAmelCase		)

            lowercase							,							lowercase														=			cls.get_config_dict(__lowerCAmelCase	, **__lowerCAmelCase		)

            # get the vision config dict if we are loading from InstructBlipConfig
            if config_dict.get("""model_type"""		) == "instructblip":
                  lowercase														=			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		( lowerCAmelCase			):
      snake_case__    :     Tuple													=			'instructblip_qformer'

      def __init__(		self	, __lowerCAmelCase=3_0522	, __lowerCAmelCase=768	, __lowerCAmelCase=12	, __lowerCAmelCase=12	, __lowerCAmelCase=3072	, __lowerCAmelCase="gelu"	, __lowerCAmelCase=0.1	, __lowerCAmelCase=0.1	, __lowerCAmelCase=512	, __lowerCAmelCase=0.0_2	, __lowerCAmelCase=1E-12	, __lowerCAmelCase=0	, __lowerCAmelCase="absolute"	, __lowerCAmelCase=2	, __lowerCAmelCase=1408	, **__lowerCAmelCase	, ):







            """simple docstring"""



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

            lowercase														=			vocab_size
            lowercase														=			hidden_size
            lowercase														=			num_hidden_layers
            lowercase														=			num_attention_heads
            lowercase														=			hidden_act
            lowercase														=			intermediate_size
            lowercase														=			hidden_dropout_prob
            lowercase														=			attention_probs_dropout_prob
            lowercase														=			max_position_embeddings
            lowercase														=			initializer_range
            lowercase														=			layer_norm_eps
            lowercase														=			position_embedding_type
            lowercase														=			cross_attention_frequency
            lowercase														=			encoder_hidden_size







      @classmethod
      def        A__ (		cls	, __lowerCAmelCase	, **__lowerCAmelCase		):







            """simple docstring"""



            cls._set_token_in_kwargs(__lowerCAmelCase		)

            lowercase							,							lowercase														=			cls.get_config_dict(__lowerCAmelCase	, **__lowerCAmelCase		)

            # get the qformer config dict if we are loading from InstructBlipConfig
            if config_dict.get("""model_type"""		) == "instructblip":
                  lowercase														=			config_dict["""qformer_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		( lowerCAmelCase			):
      snake_case__    :     Dict													=			'instructblip'
      snake_case__    :     List[Any]													=			True

      def __init__(		self	, __lowerCAmelCase=None	, __lowerCAmelCase=None	, __lowerCAmelCase=None	, __lowerCAmelCase=32	, **__lowerCAmelCase		):







            """simple docstring"""



            super().__init__(**__lowerCAmelCase		)

            if vision_config is None:
                  lowercase														=			{}
                  logger.info("""vision_config is None. initializing the InstructBlipVisionConfig with default values."""		)

            if qformer_config is None:
                  lowercase														=			{}
                  logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values."""		)

            if text_config is None:
                  lowercase														=			{}
                  logger.info("""text_config is None. Initializing the text config with default values (`OPTConfig`)."""		)

            lowercase														=			InstructBlipVisionConfig(**__lowerCAmelCase		)
            lowercase														=			InstructBlipQFormerConfig(**__lowerCAmelCase		)
            lowercase														=			text_config["""model_type"""] if """model_type""" in text_config else """opt"""
            lowercase														=			CONFIG_MAPPING[text_model_type](**__lowerCAmelCase		)

            lowercase														=			self.text_config.tie_word_embeddings
            lowercase														=			self.text_config.is_encoder_decoder

            lowercase														=			num_query_tokens
            lowercase														=			self.vision_config.hidden_size
            lowercase														=			self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
            lowercase														=			1.0
            lowercase														=			0.0_2

      @classmethod
      def        A__ (		cls	, __lowerCAmelCase	, __lowerCAmelCase	, __lowerCAmelCase	, **__lowerCAmelCase	, ):







            """simple docstring"""



            return cls(
                vision_config=vision_config.to_dict()	, qformer_config=qformer_config.to_dict()	, text_config=text_config.to_dict()	, **__lowerCAmelCase	, )







      def        A__ (		self		):







            """simple docstring"""



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




"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tf_available, is_torch_available


__lowerCAmelCase					: Dict        ={
    """configuration_xlm""": ["""XLM_PRETRAINED_CONFIG_ARCHIVE_MAP""", """XLMConfig""", """XLMOnnxConfig"""],
    """tokenization_xlm""": ["""XLMTokenizer"""],
}

try:
       if not is_torch_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCAmelCase					: int        =[
           """XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """XLMForMultipleChoice""",
           """XLMForQuestionAnswering""",
           """XLMForQuestionAnsweringSimple""",
           """XLMForSequenceClassification""",
           """XLMForTokenClassification""",
           """XLMModel""",
           """XLMPreTrainedModel""",
           """XLMWithLMHeadModel""",
       ]

try:
       if not is_tf_available():
              raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
       pass
else:
       __lowerCAmelCase					: Union[str, Any]        =[
           """TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST""",
           """TFXLMForMultipleChoice""",
           """TFXLMForQuestionAnsweringSimple""",
           """TFXLMForSequenceClassification""",
           """TFXLMForTokenClassification""",
           """TFXLMMainLayer""",
           """TFXLMModel""",
           """TFXLMPreTrainedModel""",
           """TFXLMWithLMHeadModel""",
       ]


if TYPE_CHECKING:
       from .configuration_xlm import XLM_PRETRAINED_CONFIG_ARCHIVE_MAP, XLMConfig, XLMOnnxConfig
       from .tokenization_xlm import XLMTokenizer

       try:
              if not is_torch_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_xlm import (
                  XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  XLMForMultipleChoice,
                  XLMForQuestionAnswering,
                  XLMForQuestionAnsweringSimple,
                  XLMForSequenceClassification,
                  XLMForTokenClassification,
                  XLMModel,
                  XLMPreTrainedModel,
                  XLMWithLMHeadModel,
              )

       try:
              if not is_tf_available():
                     raise OptionalDependencyNotAvailable()
       except OptionalDependencyNotAvailable:
              pass
       else:
              from .modeling_tf_xlm import (
                  TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
                  TFXLMForMultipleChoice,
                  TFXLMForQuestionAnsweringSimple,
                  TFXLMForSequenceClassification,
                  TFXLMForTokenClassification,
                  TFXLMMainLayer,
                  TFXLMModel,
                  TFXLMPreTrainedModel,
                  TFXLMWithLMHeadModel,
              )

else:
       import sys

       __lowerCAmelCase					: Optional[int]        =_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



