





"""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 			_a						(				_lowerCAmelCase    ):
    UpperCamelCase								=   '''instructblip_vision_model'''






    def __init__(			self		:   Any,			lowerCAmelCase__		:   Tuple=1_4_0_8,			lowerCAmelCase__		:   List[str]=6_1_4_4,			lowerCAmelCase__		:   Optional[int]=3_9,			lowerCAmelCase__		:   str=1_6,			lowerCAmelCase__		:   List[Any]=2_2_4,			lowerCAmelCase__		:   Optional[int]=1_4,			lowerCAmelCase__		:   List[str]="gelu",			lowerCAmelCase__		:   Optional[Any]=1e-6,			lowerCAmelCase__		:   List[str]=0.0,			lowerCAmelCase__		:   Dict=1e-1_0,			lowerCAmelCase__		:   Optional[int]=True,			**lowerCAmelCase__		:   List[str],			)     ->				int:




          '''simple docstring'''



          super().__init__(**lowerCAmelCase__							)

          _UpperCamelCase      : List[Any]         =   hidden_size
          _UpperCamelCase      : str         =   intermediate_size
          _UpperCamelCase      : Union[str, Any]         =   num_hidden_layers
          _UpperCamelCase      : int         =   num_attention_heads
          _UpperCamelCase      : Tuple         =   patch_size
          _UpperCamelCase      : Union[str, Any]         =   image_size
          _UpperCamelCase      : Optional[int]         =   initializer_range
          _UpperCamelCase      : Dict         =   attention_dropout
          _UpperCamelCase      : Any         =   layer_norm_eps
          _UpperCamelCase      : List[str]         =   hidden_act
          _UpperCamelCase      : Optional[int]         =   qkv_bias






    @classmethod
    def     snake_case     (			cls		:   Dict,			lowerCAmelCase__		:   Union[str, os.PathLike],			**lowerCAmelCase__		:   Tuple							)     ->				"PretrainedConfig":




          '''simple docstring'''



          cls._set_token_in_kwargs(lowerCAmelCase__							)

          _UpperCamelCase      : int         =   cls.get_config_dict(lowerCAmelCase__,			**lowerCAmelCase__							)

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




class 			_a						(				_lowerCAmelCase    ):
    UpperCamelCase								=   '''instructblip_qformer'''






    def __init__(			self		:   Optional[Any],			lowerCAmelCase__		:   Optional[int]=3_0_5_2_2,			lowerCAmelCase__		:   List[str]=7_6_8,			lowerCAmelCase__		:   Tuple=1_2,			lowerCAmelCase__		:   Optional[Any]=1_2,			lowerCAmelCase__		:   List[str]=3_0_7_2,			lowerCAmelCase__		:   List[Any]="gelu",			lowerCAmelCase__		:   int=0.1,			lowerCAmelCase__		:   Union[str, Any]=0.1,			lowerCAmelCase__		:   List[Any]=5_1_2,			lowerCAmelCase__		:   int=0.02,			lowerCAmelCase__		:   Optional[Any]=1e-1_2,			lowerCAmelCase__		:   int=0,			lowerCAmelCase__		:   Union[str, Any]="absolute",			lowerCAmelCase__		:   Union[str, Any]=2,			lowerCAmelCase__		:   int=1_4_0_8,			**lowerCAmelCase__		:   List[Any],			)     ->				int:




          '''simple docstring'''



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

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






    @classmethod
    def     snake_case     (			cls		:   Any,			lowerCAmelCase__		:   Union[str, os.PathLike],			**lowerCAmelCase__		:   Optional[int]							)     ->				"PretrainedConfig":




          '''simple docstring'''



          cls._set_token_in_kwargs(lowerCAmelCase__							)

          _UpperCamelCase      : List[Any]         =   cls.get_config_dict(lowerCAmelCase__,			**lowerCAmelCase__							)

          # get the qformer config dict if we are loading from InstructBlipConfig
          if config_dict.get('''model_type'''							) == "instructblip":
                _UpperCamelCase      : Any         =   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    ):
    UpperCamelCase								=   '''instructblip'''
    UpperCamelCase								=   True






    def __init__(			self		:   str,			lowerCAmelCase__		:   List[Any]=None,			lowerCAmelCase__		:   str=None,			lowerCAmelCase__		:   int=None,			lowerCAmelCase__		:   List[Any]=3_2,			**lowerCAmelCase__		:   int							)     ->				Union[str, Any]:




          '''simple docstring'''



          super().__init__(**lowerCAmelCase__							)

          if vision_config is None:
                _UpperCamelCase      : Any         =   {}
                logger.info('''vision_config is None. initializing the InstructBlipVisionConfig with default values.'''							)

          if qformer_config is None:
                _UpperCamelCase      : Optional[int]         =   {}
                logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'''							)

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

          _UpperCamelCase      : Optional[Any]         =   InstructBlipVisionConfig(**lowerCAmelCase__							)
          _UpperCamelCase      : Optional[Any]         =   InstructBlipQFormerConfig(**lowerCAmelCase__							)
          _UpperCamelCase      : Dict         =   text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
          _UpperCamelCase      : Dict         =   CONFIG_MAPPING[text_model_type](**lowerCAmelCase__							)

          _UpperCamelCase      : str         =   self.text_config.tie_word_embeddings
          _UpperCamelCase      : Tuple         =   self.text_config.is_encoder_decoder

          _UpperCamelCase      : Union[str, Any]         =   num_query_tokens
          _UpperCamelCase      : List[Any]         =   self.vision_config.hidden_size
          _UpperCamelCase      : List[str]         =   self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
          _UpperCamelCase      : str         =   1.0
          _UpperCamelCase      : str         =   0.02






    @classmethod
    def     snake_case     (			cls		:   str,			lowerCAmelCase__		:   InstructBlipVisionConfig,			lowerCAmelCase__		:   InstructBlipQFormerConfig,			lowerCAmelCase__		:   PretrainedConfig,			**lowerCAmelCase__		:   Union[str, Any],			)     ->				Optional[int]:




          '''simple docstring'''



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






    def     snake_case     (			self		:   str							)     ->				str:




          '''simple docstring'''



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










"""simple docstring"""




import logging

from transformers.configuration_utils import PretrainedConfig


UpperCamelCase_									=logging.getLogger(__name__)




class 			_a						(				_lowerCAmelCase    ):
				UpperCamelCase								=   '''masked_bert'''






				def __init__(			self		:   Optional[Any],			lowerCAmelCase__		:   Dict=3_0_5_2_2,			lowerCAmelCase__		:   int=7_6_8,			lowerCAmelCase__		:   Tuple=1_2,			lowerCAmelCase__		:   Optional[Any]=1_2,			lowerCAmelCase__		:   Tuple=3_0_7_2,			lowerCAmelCase__		:   Optional[int]="gelu",			lowerCAmelCase__		:   Tuple=0.1,			lowerCAmelCase__		:   Tuple=0.1,			lowerCAmelCase__		:   Any=5_1_2,			lowerCAmelCase__		:   Optional[int]=2,			lowerCAmelCase__		:   Optional[int]=0.02,			lowerCAmelCase__		:   Union[str, Any]=1e-1_2,			lowerCAmelCase__		:   Union[str, Any]=0,			lowerCAmelCase__		:   Dict="topK",			lowerCAmelCase__		:   Union[str, Any]="constant",			lowerCAmelCase__		:   Union[str, Any]=0.0,			**lowerCAmelCase__		:   Any,			)     ->				List[Any]:




										'''simple docstring'''



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

										_UpperCamelCase      : Optional[Any]         =   vocab_size
										_UpperCamelCase      : int         =   hidden_size
										_UpperCamelCase      : List[Any]         =   num_hidden_layers
										_UpperCamelCase      : Any         =   num_attention_heads
										_UpperCamelCase      : List[str]         =   hidden_act
										_UpperCamelCase      : Tuple         =   intermediate_size
										_UpperCamelCase      : int         =   hidden_dropout_prob
										_UpperCamelCase      : str         =   attention_probs_dropout_prob
										_UpperCamelCase      : Optional[int]         =   max_position_embeddings
										_UpperCamelCase      : str         =   type_vocab_size
										_UpperCamelCase      : Optional[Any]         =   initializer_range
										_UpperCamelCase      : List[str]         =   layer_norm_eps
										_UpperCamelCase      : int         =   pruning_method
										_UpperCamelCase      : Union[str, Any]         =   mask_init
										_UpperCamelCase      : Any         =   mask_scale



