"""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__						:						str		  =			logging.get_logger(__name__)

lowerCAmelCase__						:						str		  =			{
    'Salesforce/instruct-blip-flan-t5': 'https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json',
}
class        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"instructblip_vision_model"







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

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







					@classmethod
					def 	__lowerCAmelCase		(       cls     :			Optional[Any]					,lowerCamelCase__     :			Union[str, os.PathLike]					,**lowerCamelCase__     :			List[Any]    ):
									cls._set_token_in_kwargs(lowerCamelCase__    )

									UpperCAmelCase__   ,			UpperCAmelCase__    =							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__    =							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        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"instructblip_qformer"







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

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







					@classmethod
					def 	__lowerCAmelCase		(       cls     :			Union[str, Any]					,lowerCamelCase__     :			Union[str, os.PathLike]					,**lowerCamelCase__     :			Union[str, Any]    ):
									cls._set_token_in_kwargs(lowerCamelCase__    )

									UpperCAmelCase__   ,			UpperCAmelCase__    =							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__    =							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        snake_case (				__UpperCAmelCase       ):




					"""simple docstring"""

					snake_case__       					=				"instructblip"
					snake_case__       					=				True







					def __init__(       self     :			int					,lowerCamelCase__     :			str=None					,lowerCamelCase__     :			Dict=None					,lowerCamelCase__     :			Tuple=None					,lowerCamelCase__     :			str=32					,**lowerCamelCase__     :			Tuple    ):
									super().__init__(**lowerCamelCase__    )

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

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

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

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

									UpperCAmelCase__    =							self.text_config.tie_word_embeddings
									UpperCAmelCase__    =							self.text_config.is_encoder_decoder

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







					@classmethod
					def 	__lowerCAmelCase		(       cls     :			Tuple					,lowerCamelCase__     :			InstructBlipVisionConfig					,lowerCamelCase__     :			InstructBlipQFormerConfig					,lowerCamelCase__     :			PretrainedConfig					,**lowerCamelCase__     :			int					,):
									return cls(
									    vision_config=vision_config.to_dict()					,qformer_config=qformer_config.to_dict()					,text_config=text_config.to_dict()					,**lowerCamelCase__					,)







					def 	__lowerCAmelCase		(       self     :			List[str]    ):
									UpperCAmelCase__    =							copy.deepcopy(self.__dict__    )
									UpperCAmelCase__    =							self.vision_config.to_dict()
									UpperCAmelCase__    =							self.qformer_config.to_dict()
									UpperCAmelCase__    =							self.text_config.to_dict()
									UpperCAmelCase__    =							self.__class__.model_type
									return output




"""simple docstring"""






import os
import sys
from contextlib import contextmanager


# Windows only
if os.name == "nt":
						import ctypes
						import msvcrt  # noqa
						class        snake_case (				ctypes.Structure       ):




											"""simple docstring"""

											snake_case__       					=				[("size", ctypes.c_int), ("visible", ctypes.c_byte)]



def 						a_		(      ):
				if os.name == "nt":
								UpperCAmelCase__    =							CursorInfo()
								UpperCAmelCase__    =							ctypes.windll.kernelaa.GetStdHandle(-1_1 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
								UpperCAmelCase__    =							False
								ctypes.windll.kernelaa.SetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
				elif os.name == "posix":
								sys.stdout.write('\033[?25l' )
								sys.stdout.flush()



def 						a_		(      ):
				if os.name == "nt":
								UpperCAmelCase__    =							CursorInfo()
								UpperCAmelCase__    =							ctypes.windll.kernelaa.GetStdHandle(-1_1 )
								ctypes.windll.kernelaa.GetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
								UpperCAmelCase__    =							True
								ctypes.windll.kernelaa.SetConsoleCursorInfo(lowerCamelCase      ,    ctypes.byref(lowerCamelCase ) )
				elif os.name == "posix":
								sys.stdout.write('\033[?25h' )
								sys.stdout.flush()







@contextmanager
def 						a_		(      ):
				try:
								hide_cursor()
								yield
				finally:
								show_cursor()



