


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


snake_case							:       Any     			=      logging.get_logger(__name__)

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







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    Union[str, Any]          =			'''instructblip_vision_model'''
					def __init__(      self   :Optional[int]			,__snake_case   :List[Any]=14_08			,__snake_case   :int=61_44			,__snake_case   :List[Any]=39			,__snake_case   :Optional[int]=16			,__snake_case   :List[str]=2_24			,__snake_case   :List[Any]=14			,__snake_case   :Tuple="gelu"			,__snake_case   :int=1E-6			,__snake_case   :Dict=0.0			,__snake_case   :Tuple=1E-10			,__snake_case   :Any=True			,**__snake_case   :Any			,)					->    Optional[int]:
												super().__init__(**__snake_case      )

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



					@classmethod
					def  lowerCamelCase__(      cls   :Optional[Any]			,__snake_case   :Union[str, os.PathLike]			,**__snake_case   :Any      )					->    "PretrainedConfig":
												cls._set_token_in_kwargs(__snake_case      )

												a__      ,					a__             =     cls.get_config_dict(__snake_case			,**__snake_case      )

												# get the vision config dict if we are loading from InstructBlipConfig
												if config_dict.get('model_type'      ) == "instructblip":
																			a__             =     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        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    Optional[int]          =			'''instructblip_qformer'''
					def __init__(      self   :Optional[int]			,__snake_case   :Union[str, Any]=3_05_22			,__snake_case   :int=7_68			,__snake_case   :List[str]=12			,__snake_case   :Optional[Any]=12			,__snake_case   :Tuple=30_72			,__snake_case   :Any="gelu"			,__snake_case   :Optional[Any]=0.1			,__snake_case   :Dict=0.1			,__snake_case   :Dict=5_12			,__snake_case   :Optional[int]=0.02			,__snake_case   :str=1E-12			,__snake_case   :List[str]=0			,__snake_case   :Union[str, Any]="absolute"			,__snake_case   :Optional[Any]=2			,__snake_case   :Tuple=14_08			,**__snake_case   :str			,)					->    Tuple:
												super().__init__(pad_token_id=__snake_case			,**__snake_case      )

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



					@classmethod
					def  lowerCamelCase__(      cls   :Optional[Any]			,__snake_case   :Union[str, os.PathLike]			,**__snake_case   :Union[str, Any]      )					->    "PretrainedConfig":
												cls._set_token_in_kwargs(__snake_case      )

												a__      ,					a__             =     cls.get_config_dict(__snake_case			,**__snake_case      )

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







class        snake_case_   (lowerCamelCase_      ):
					UpperCAmelCase__					:    Optional[int]          =			'''instructblip'''
					UpperCAmelCase__					:    Any          =			True
					def __init__(      self   :Any			,__snake_case   :Optional[int]=None			,__snake_case   :Optional[int]=None			,__snake_case   :Optional[Any]=None			,__snake_case   :Any=32			,**__snake_case   :str      )					->    Dict:
												super().__init__(**__snake_case      )

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

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

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

												a__             =     InstructBlipVisionConfig(**__snake_case      )
												a__             =     InstructBlipQFormerConfig(**__snake_case      )
												a__             =     text_config['model_type'] if 'model_type' in text_config else 'opt'
												a__             =     CONFIG_MAPPING[text_model_type](**__snake_case      )

												a__             =     self.text_config.tie_word_embeddings
												a__             =     self.text_config.is_encoder_decoder

												a__             =     num_query_tokens
												a__             =     self.vision_config.hidden_size
												a__             =     self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
												a__             =     1.0
												a__             =     0.02
					@classmethod
					def  lowerCamelCase__(      cls   :Union[str, Any]			,__snake_case   :InstructBlipVisionConfig			,__snake_case   :InstructBlipQFormerConfig			,__snake_case   :PretrainedConfig			,**__snake_case   :Optional[Any]			,)					->    List[str]:
												return cls(
												    vision_config=vision_config.to_dict()			,qformer_config=qformer_config.to_dict()			,text_config=text_config.to_dict()			,**__snake_case			,)



					def  lowerCamelCase__(      self   :Optional[Any]      )					->    int:
												a__             =     copy.deepcopy(self.__dict__      )
												a__             =     self.vision_config.to_dict()
												a__             =     self.qformer_config.to_dict()
												a__             =     self.text_config.to_dict()
												a__             =     self.__class__.model_type
												return output








from abc import ABC, abstractmethod
from argparse import ArgumentParser







class        snake_case_   (lowerCamelCase_      ):
					@staticmethod
					@abstractmethod
					def  lowerCamelCase__(      __snake_case   :ArgumentParser      )					->    Dict:
												raise NotImplementedError()



					@abstractmethod
					def  lowerCamelCase__(      self   :Union[str, Any]      )					->    Dict:
												raise NotImplementedError()




