


'''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


UpperCamelCase__    					=      logging.get_logger(__name__)

UpperCamelCase__    					=      {
    "Salesforce/instruct-blip-flan-t5": "https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json",
}




class 			lowerCamelCase_   (	lowerCAmelCase__      ):
      lowerCAmelCase__		     =     """instructblip_vision_model"""






      def __init__(					self				:    List[str]						,						_A				:    Optional[int]=1_408						,						_A				:    List[Any]=6_144						,						_A				:    Dict=39						,						_A				:    Optional[Any]=16						,						_A				:    Tuple=224						,						_A				:    Union[str, Any]=14						,						_A				:    List[Any]="gelu"						,						_A				:    Tuple=1e-6						,						_A				:    Optional[Any]=0.0						,						_A				:    int=1e-10						,						_A				:    Optional[Any]=True						,						**_A				:    List[Any]						,						):


          '''simple docstring'''


          super().__init__(**__a )

          UpperCAmelCase__			:		str													=				hidden_size
          UpperCAmelCase__			:		Any													=				intermediate_size
          UpperCAmelCase__			:		List[str]													=				num_hidden_layers
          UpperCAmelCase__			:		List[str]													=				num_attention_heads
          UpperCAmelCase__			:		Dict													=				patch_size
          UpperCAmelCase__			:		List[Any]													=				image_size
          UpperCAmelCase__			:		List[str]													=				initializer_range
          UpperCAmelCase__			:		Any													=				attention_dropout
          UpperCAmelCase__			:		Dict													=				layer_norm_eps
          UpperCAmelCase__			:		Optional[Any]													=				hidden_act
          UpperCAmelCase__			:		Optional[Any]													=				qkv_bias






      @classmethod
      def lowercase_							(					cls				:    Optional[int]						,						_A				:    Optional[int]						,						**_A				:    Union[str, Any] ):


          '''simple docstring'''


          cls._set_token_in_kwargs(__a )

          UpperCAmelCase__						,						UpperCAmelCase__			:		Optional[Any]													=				cls.get_config_dict(__a						,						**__a )

          # get the vision config dict if we are loading from InstructBlipConfig
          if config_dict.get('''model_type''' ) == "instructblip":
              UpperCAmelCase__			:		Optional[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(__a						,						**__a )




class 			lowerCamelCase_   (	lowerCAmelCase__      ):
      lowerCAmelCase__		     =     """instructblip_qformer"""






      def __init__(					self				:    str						,						_A				:    List[str]=30_522						,						_A				:    Optional[int]=768						,						_A				:    List[Any]=12						,						_A				:    int=12						,						_A				:    Tuple=3_072						,						_A				:    List[str]="gelu"						,						_A				:    List[str]=0.1						,						_A				:    Optional[int]=0.1						,						_A				:    Tuple=512						,						_A				:    int=0.0_2						,						_A				:    Tuple=1e-12						,						_A				:    str=0						,						_A				:    int="absolute"						,						_A				:    str=2						,						_A				:    Union[str, Any]=1_408						,						**_A				:    Any						,						):


          '''simple docstring'''


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

          UpperCAmelCase__			:		Union[str, Any]													=				vocab_size
          UpperCAmelCase__			:		Union[str, Any]													=				hidden_size
          UpperCAmelCase__			:		List[str]													=				num_hidden_layers
          UpperCAmelCase__			:		Dict													=				num_attention_heads
          UpperCAmelCase__			:		str													=				hidden_act
          UpperCAmelCase__			:		List[Any]													=				intermediate_size
          UpperCAmelCase__			:		Dict													=				hidden_dropout_prob
          UpperCAmelCase__			:		Optional[int]													=				attention_probs_dropout_prob
          UpperCAmelCase__			:		Tuple													=				max_position_embeddings
          UpperCAmelCase__			:		List[str]													=				initializer_range
          UpperCAmelCase__			:		Any													=				layer_norm_eps
          UpperCAmelCase__			:		Dict													=				position_embedding_type
          UpperCAmelCase__			:		List[Any]													=				cross_attention_frequency
          UpperCAmelCase__			:		List[str]													=				encoder_hidden_size






      @classmethod
      def lowercase_							(					cls				:    int						,						_A				:    List[Any]						,						**_A				:    Dict ):


          '''simple docstring'''


          cls._set_token_in_kwargs(__a )

          UpperCAmelCase__						,						UpperCAmelCase__			:		Union[str, Any]													=				cls.get_config_dict(__a						,						**__a )

          # get the qformer config dict if we are loading from InstructBlipConfig
          if config_dict.get('''model_type''' ) == "instructblip":
              UpperCAmelCase__			:		str													=				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(__a						,						**__a )




class 			lowerCamelCase_   (	lowerCAmelCase__      ):
      lowerCAmelCase__		     =     """instructblip"""
      lowerCAmelCase__		     =     True






      def __init__(					self				:    Dict						,						_A				:    Optional[int]=None						,						_A				:    List[Any]=None						,						_A				:    Union[str, Any]=None						,						_A				:    Optional[int]=32						,						**_A				:    Optional[int] ):


          '''simple docstring'''


          super().__init__(**__a )

          if vision_config is None:
              UpperCAmelCase__			:		List[str]													=				{}
              logger.info('''vision_config is None. initializing the InstructBlipVisionConfig with default values.''' )

          if qformer_config is None:
              UpperCAmelCase__			:		Union[str, Any]													=				{}
              logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.''' )

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

          UpperCAmelCase__			:		Optional[int]													=				InstructBlipVisionConfig(**__a )
          UpperCAmelCase__			:		Optional[int]													=				InstructBlipQFormerConfig(**__a )
          UpperCAmelCase__			:		Optional[Any]													=				text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
          UpperCAmelCase__			:		List[str]													=				CONFIG_MAPPING[text_model_type](**__a )

          UpperCAmelCase__			:		str													=				self.text_config.tie_word_embeddings
          UpperCAmelCase__			:		int													=				self.text_config.is_encoder_decoder

          UpperCAmelCase__			:		List[Any]													=				num_query_tokens
          UpperCAmelCase__			:		str													=				self.vision_config.hidden_size
          UpperCAmelCase__			:		Optional[Any]													=				self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
          UpperCAmelCase__			:		Dict													=				1.0
          UpperCAmelCase__			:		Optional[Any]													=				0.0_2






      @classmethod
      def lowercase_							(					cls				:    List[Any]						,						_A				:    str						,						_A				:    Dict						,						_A				:    str						,						**_A				:    List[str]						,						):


          '''simple docstring'''


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






      def lowercase_							(					self				:    Union[str, Any] ):


          '''simple docstring'''


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




"""simple docstring"""


from diffusers.utils.testing_utils import require_onnxruntime
@require_onnxruntime
class   _UpperCamelCase  :
							'''simple docstring'''







							pass




