



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


__snake_case				:  Dict =       logging.get_logger(__name__)

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



class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'instructblip_vision_model'

	def __init__(	self:						str			,     _SCREAMING_SNAKE_CASE:						Tuple=1408			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=6144			,     _SCREAMING_SNAKE_CASE:						List[Any]=39			,     _SCREAMING_SNAKE_CASE:						int=16			,     _SCREAMING_SNAKE_CASE:						List[Any]=224			,     _SCREAMING_SNAKE_CASE:						List[str]=14			,     _SCREAMING_SNAKE_CASE:						List[Any]="gelu"			,     _SCREAMING_SNAKE_CASE:						List[str]=1e-6			,     _SCREAMING_SNAKE_CASE:						Tuple=0.0			,     _SCREAMING_SNAKE_CASE:						Any=1e-10			,     _SCREAMING_SNAKE_CASE:						int=True			,     **_SCREAMING_SNAKE_CASE:						Any			,     )							->			str:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

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







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

				"""simple docstring"""

				cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase		,      __lowerCAmelCase :    Optional[Any]				=			cls.get_config_dict(_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

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






class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'instructblip_qformer'

	def __init__(	self:						Optional[Any]			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=3_0522			,     _SCREAMING_SNAKE_CASE:						str=768			,     _SCREAMING_SNAKE_CASE:						str=12			,     _SCREAMING_SNAKE_CASE:						Any=12			,     _SCREAMING_SNAKE_CASE:						List[str]=3072			,     _SCREAMING_SNAKE_CASE:						List[Any]="gelu"			,     _SCREAMING_SNAKE_CASE:						Optional[int]=0.1			,     _SCREAMING_SNAKE_CASE:						List[Any]=0.1			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=512			,     _SCREAMING_SNAKE_CASE:						Dict=0.02			,     _SCREAMING_SNAKE_CASE:						Tuple=1e-12			,     _SCREAMING_SNAKE_CASE:						Dict=0			,     _SCREAMING_SNAKE_CASE:						int="absolute"			,     _SCREAMING_SNAKE_CASE:						List[Any]=2			,     _SCREAMING_SNAKE_CASE:						Optional[Any]=1408			,     **_SCREAMING_SNAKE_CASE:						int			,     )							->			Union[str, Any]:

				"""simple docstring"""

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

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







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

				"""simple docstring"""

				cls._set_token_in_kwargs(_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase		,      __lowerCAmelCase :    str				=			cls.get_config_dict(_SCREAMING_SNAKE_CASE			,     **_SCREAMING_SNAKE_CASE)

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






class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	SCREAMING_SNAKE_CASE        =      'instructblip'
	SCREAMING_SNAKE_CASE        =      True

	def __init__(	self:						int			,     _SCREAMING_SNAKE_CASE:						int=None			,     _SCREAMING_SNAKE_CASE:						List[str]=None			,     _SCREAMING_SNAKE_CASE:						Tuple=None			,     _SCREAMING_SNAKE_CASE:						Tuple=32			,     **_SCREAMING_SNAKE_CASE:						Tuple)							->			Optional[Any]:

				"""simple docstring"""

				super().__init__(**_SCREAMING_SNAKE_CASE)

				if vision_config is None:
							__lowerCAmelCase :    Union[str, Any]				=			{}
							logger.info("vision_config is None. initializing the InstructBlipVisionConfig with default values.")

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

				if text_config is None:
							__lowerCAmelCase :    Optional[Any]				=			{}
							logger.info("text_config is None. Initializing the text config with default values (`OPTConfig`).")

				__lowerCAmelCase :    int				=			InstructBlipVisionConfig(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    List[str]				=			InstructBlipQFormerConfig(**_SCREAMING_SNAKE_CASE)
				__lowerCAmelCase :    Union[str, Any]				=			text_config["model_type"] if "model_type" in text_config else "opt"
				__lowerCAmelCase :    Any				=			CONFIG_MAPPING[text_model_type](**_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase :    int				=			self.text_config.tie_word_embeddings
				__lowerCAmelCase :    Any				=			self.text_config.is_encoder_decoder

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

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

				"""simple docstring"""

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







	def 				_SCREAMING_SNAKE_CASE  (	self:						Tuple)							->			Optional[int]:

				"""simple docstring"""

				__lowerCAmelCase :    str				=			copy.deepcopy(self.__dict__)
				__lowerCAmelCase :    str				=			self.vision_config.to_dict()
				__lowerCAmelCase :    str				=			self.qformer_config.to_dict()
				__lowerCAmelCase :    str				=			self.text_config.to_dict()
				__lowerCAmelCase :    Tuple				=			self.__class__.model_type
				return output




"""simple docstring"""






from abc import ABC, abstractmethod
from argparse import ArgumentParser



class      A__  (    __SCREAMING_SNAKE_CASE				):




	'''simple docstring'''





	@staticmethod
	@abstractmethod
	def 				_SCREAMING_SNAKE_CASE  (	_SCREAMING_SNAKE_CASE:						ArgumentParser)							->			Optional[int]:

				"""simple docstring"""

				raise NotImplementedError()







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

				"""simple docstring"""

				raise NotImplementedError()