
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


__a  			=					logging.get_logger(__name__)

__a  			=					{
    'salesforce/blip2-opt-2.7b': 'https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json',
}
class  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	a			:List[Any]         =	'blip_2_vision_model'
	def __init__(       self  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			int=1_4_0_8       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=6_1_4_4       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=3_9       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=1_6       ,							SCREAMING_SNAKE_CASE_  :			str=2_2_4       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=1_4       ,							SCREAMING_SNAKE_CASE_  :			List[Any]="gelu"       ,							SCREAMING_SNAKE_CASE_  :			str=0.0_00_01       ,							SCREAMING_SNAKE_CASE_  :			Optional[int]=0.0       ,							SCREAMING_SNAKE_CASE_  :			int=1e-10       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=True       ,							**SCREAMING_SNAKE_CASE_  :			int       ,							)       ->     List[Any]:
					super().__init__(**SCREAMING_SNAKE_CASE_       )

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




	@classmethod
	def 						_lowercase  (       cls  :			str       ,							SCREAMING_SNAKE_CASE_  :			Union[str, os.PathLike]       ,							**SCREAMING_SNAKE_CASE_  :			List[str]       )       ->     "PretrainedConfig":
					cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_       )

					lowercase_  ,	lowercase_       =					cls.get_config_dict(SCREAMING_SNAKE_CASE_       ,							**SCREAMING_SNAKE_CASE_       )

					# get the vision config dict if we are loading from Blip2Config
					if config_dict.get('''model_type'''       ) == "blip-2":
									lowercase_       =					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  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	a			:Dict         =	'blip_2_qformer'
	def __init__(       self  :			Optional[Any]       ,							SCREAMING_SNAKE_CASE_  :			Tuple=3_0_5_2_2       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=7_6_8       ,							SCREAMING_SNAKE_CASE_  :			Any=1_2       ,							SCREAMING_SNAKE_CASE_  :			int=1_2       ,							SCREAMING_SNAKE_CASE_  :			str=3_0_7_2       ,							SCREAMING_SNAKE_CASE_  :			Any="gelu"       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=0.1       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=0.1       ,							SCREAMING_SNAKE_CASE_  :			int=5_1_2       ,							SCREAMING_SNAKE_CASE_  :			Any=0.02       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=1e-12       ,							SCREAMING_SNAKE_CASE_  :			Dict=0       ,							SCREAMING_SNAKE_CASE_  :			Tuple="absolute"       ,							SCREAMING_SNAKE_CASE_  :			Union[str, Any]=2       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=1_4_0_8       ,							**SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							)       ->     List[Any]:
					super().__init__(pad_token_id=SCREAMING_SNAKE_CASE_       ,							**SCREAMING_SNAKE_CASE_       )

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




	@classmethod
	def 						_lowercase  (       cls  :			int       ,							SCREAMING_SNAKE_CASE_  :			Union[str, os.PathLike]       ,							**SCREAMING_SNAKE_CASE_  :			Optional[int]       )       ->     "PretrainedConfig":
					cls._set_token_in_kwargs(SCREAMING_SNAKE_CASE_       )

					lowercase_  ,	lowercase_       =					cls.get_config_dict(SCREAMING_SNAKE_CASE_       ,							**SCREAMING_SNAKE_CASE_       )

					# get the qformer config dict if we are loading from Blip2Config
					if config_dict.get('''model_type'''       ) == "blip-2":
									lowercase_       =					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  lowercase__(				UpperCAmelCase							):



	"""simple docstring"""




	a			:str         =	'blip-2'
	a			:int         =	True
	def __init__(       self  :			Dict       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=None       ,							SCREAMING_SNAKE_CASE_  :			Dict=None       ,							SCREAMING_SNAKE_CASE_  :			List[Any]=None       ,							SCREAMING_SNAKE_CASE_  :			Optional[Any]=3_2       ,							**SCREAMING_SNAKE_CASE_  :			str       )       ->     Tuple:
					super().__init__(**SCREAMING_SNAKE_CASE_       )

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

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

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

					lowercase_       =					BlipaVisionConfig(**SCREAMING_SNAKE_CASE_       )
					lowercase_       =					BlipaQFormerConfig(**SCREAMING_SNAKE_CASE_       )
					lowercase_       =					text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
					lowercase_       =					CONFIG_MAPPING[text_model_type](**SCREAMING_SNAKE_CASE_       )

					lowercase_       =					self.text_config.tie_word_embeddings
					lowercase_       =					self.text_config.is_encoder_decoder

					lowercase_       =					num_query_tokens
					lowercase_       =					self.vision_config.hidden_size
					lowercase_       =					self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
					lowercase_       =					1.0
					lowercase_       =					0.02
	@classmethod
	def 						_lowercase  (       cls  :			List[Any]       ,							SCREAMING_SNAKE_CASE_  :			BlipaVisionConfig       ,							SCREAMING_SNAKE_CASE_  :			BlipaQFormerConfig       ,							SCREAMING_SNAKE_CASE_  :			PretrainedConfig       ,							**SCREAMING_SNAKE_CASE_  :			Optional[int]       ,							)       ->     Dict:
					return cls(
					    vision_config=vision_config.to_dict()       ,							qformer_config=qformer_config.to_dict()       ,							text_config=text_config.to_dict()       ,							**SCREAMING_SNAKE_CASE_       ,							)




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






from typing import TYPE_CHECKING

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


__a  			=					{
    'configuration_trocr': ['TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP', 'TrOCRConfig'],
    'processing_trocr': ['TrOCRProcessor'],
}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a  			=					[
						    'TROCR_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'TrOCRForCausalLM',
						    'TrOCRPreTrainedModel',
						]


if TYPE_CHECKING:
						from .configuration_trocr import TROCR_PRETRAINED_CONFIG_ARCHIVE_MAP, TrOCRConfig
						from .processing_trocr import TrOCRProcessor

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_trocr import TROCR_PRETRAINED_MODEL_ARCHIVE_LIST, TrOCRForCausalLM, TrOCRPreTrainedModel

else:
						import sys

						__a  			=					_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




