
"""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__			:							Optional[int]      =      logging.get_logger(__name__)

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




class 					lowercase__(					a_ ):
	'''simple docstring'''

	UpperCamelCase				=	'''instructblip_vision_model'''





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







			'''simple docstring'''




			super().__init__(**_lowercase       )

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







	@classmethod
	def 	__lowerCAmelCase			(    cls     :int		,			lowerCamelCase_     :List[Any]		,			**lowerCamelCase_     :Any       )				->      "PretrainedConfig":







			'''simple docstring'''




			cls._set_token_in_kwargs(_lowercase       )

			SCREAMING_SNAKE_CASE							:  int					=			cls.get_config_dict(_lowercase		,			**_lowercase       )

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





class 					lowercase__(					a_ ):
	'''simple docstring'''

	UpperCamelCase				=	'''instructblip_qformer'''





	def __init__(    self     :List[str]		,			lowerCamelCase_     :Dict=3_05_22		,			lowerCamelCase_     :int=7_68		,			lowerCamelCase_     :List[Any]=12		,			lowerCamelCase_     :List[Any]=12		,			lowerCamelCase_     :List[str]=30_72		,			lowerCamelCase_     :Dict="gelu"		,			lowerCamelCase_     :Union[str, Any]=0.1		,			lowerCamelCase_     :List[str]=0.1		,			lowerCamelCase_     :Any=5_12		,			lowerCamelCase_     :Optional[int]=0.0_2		,			lowerCamelCase_     :int=1E-12		,			lowerCamelCase_     :List[str]=0		,			lowerCamelCase_     :Union[str, Any]="absolute"		,			lowerCamelCase_     :Optional[int]=2		,			lowerCamelCase_     :Optional[Any]=14_08		,			**lowerCamelCase_     :Tuple		,			)				->      Optional[int]:







			'''simple docstring'''




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

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







	@classmethod
	def 	__lowerCAmelCase			(    cls     :List[str]		,			lowerCamelCase_     :int		,			**lowerCamelCase_     :List[str]       )				->      "PretrainedConfig":







			'''simple docstring'''




			cls._set_token_in_kwargs(_lowercase       )

			SCREAMING_SNAKE_CASE							:  str					=			cls.get_config_dict(_lowercase		,			**_lowercase       )

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





class 					lowercase__(					a_ ):
	'''simple docstring'''

	UpperCamelCase				=	'''instructblip'''
	UpperCamelCase				=	True





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







			'''simple docstring'''




			super().__init__(**_lowercase       )

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

			if qformer_config is None:
					SCREAMING_SNAKE_CASE							:  List[str]					=			{}
					logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'''       )

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

			SCREAMING_SNAKE_CASE							:  Any					=			InstructBlipVisionConfig(**_lowercase       )
			SCREAMING_SNAKE_CASE							:  str					=			InstructBlipQFormerConfig(**_lowercase       )
			SCREAMING_SNAKE_CASE							:  str					=			text_config["""model_type"""] if """model_type""" in text_config else """opt"""
			SCREAMING_SNAKE_CASE							:  Dict					=			CONFIG_MAPPING[text_model_type](**_lowercase       )

			SCREAMING_SNAKE_CASE							:  Dict					=			self.text_config.tie_word_embeddings
			SCREAMING_SNAKE_CASE							:  int					=			self.text_config.is_encoder_decoder

			SCREAMING_SNAKE_CASE							:  Optional[Any]					=			num_query_tokens
			SCREAMING_SNAKE_CASE							:  Optional[Any]					=			self.vision_config.hidden_size
			SCREAMING_SNAKE_CASE							:  Tuple					=			self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
			SCREAMING_SNAKE_CASE							:  Tuple					=			1.0
			SCREAMING_SNAKE_CASE							:  Dict					=			0.0_2





	@classmethod
	def 	__lowerCAmelCase			(    cls     :int		,			lowerCamelCase_     :Union[str, Any]		,			lowerCamelCase_     :Any		,			lowerCamelCase_     :Optional[Any]		,			**lowerCamelCase_     :List[Any]		,			)				->      List[Any]:







			'''simple docstring'''




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







	def 	__lowerCAmelCase			(    self     :int       )				->      Union[str, Any]:







			'''simple docstring'''




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








from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_tokenizers_available,
    is_torch_available,
)


__snake_case				:      int   		=			{
    """configuration_llama""": ["""LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP""", """LlamaConfig"""],
}

try:
	if not is_sentencepiece_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case				:      int   		=			["""LlamaTokenizer"""]

try:
	if not is_tokenizers_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case				:      int   		=			["""LlamaTokenizerFast"""]

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	__snake_case				:      Union[str, Any]   		=			[
	    """LlamaForCausalLM""",
	    """LlamaModel""",
	    """LlamaPreTrainedModel""",
	    """LlamaForSequenceClassification""",
	]


if TYPE_CHECKING:
	from .configuration_llama import LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP, LlamaConfig

	try:
		if not is_sentencepiece_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_llama import LlamaTokenizer

	try:
		if not is_tokenizers_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .tokenization_llama_fast import LlamaTokenizerFast

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_llama import LlamaForCausalLM, LlamaForSequenceClassification, LlamaModel, LlamaPreTrainedModel


else:
	import sys

	__snake_case				:      Dict   		=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)


