



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


a     :    List[Any]      						=					logging.get_logger(__name__)

a     :    List[Any]      						=					{
    """salesforce/blip2-opt-2.7b""": """https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json""",
}

class     UpperCamelCase_				(							__magic_name__    ):
	lowercase    =				'blip_2_vision_model'





	def __init__(						self	,	A=1408	,	A=6144	,	A=39	,	A=16	,	A=224	,	A=14	,	A="gelu"	,	A=0.0_0_0_0_1	,	A=0.0	,	A=1e-10	,	A=True	,	**A	,	)    ->    str:
								super().__init__(**A					)

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






	@classmethod
	def 				_lowercase(						cls	,	A	,	**A					)    ->    "PretrainedConfig":
								cls._set_token_in_kwargs(A					)

								UpperCAmelCase  ,  UpperCAmelCase  :	int							  =	cls.get_config_dict(A	,	**A					)

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




class     UpperCamelCase_				(							__magic_name__    ):
	lowercase    =				'blip_2_qformer'





	def __init__(						self	,	A=30522	,	A=768	,	A=12	,	A=12	,	A=3072	,	A="gelu"	,	A=0.1	,	A=0.1	,	A=512	,	A=0.0_2	,	A=1e-12	,	A=0	,	A="absolute"	,	A=2	,	A=1408	,	**A	,	)    ->    List[str]:
								super().__init__(pad_token_id=A	,	**A					)

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






	@classmethod
	def 				_lowercase(						cls	,	A	,	**A					)    ->    "PretrainedConfig":
								cls._set_token_in_kwargs(A					)

								UpperCAmelCase  ,  UpperCAmelCase  :	List[str]							  =	cls.get_config_dict(A	,	**A					)

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




class     UpperCamelCase_				(							__magic_name__    ):
	lowercase    =				'blip-2'
	lowercase    =				True





	def __init__(						self	,	A=None	,	A=None	,	A=None	,	A=32	,	**A					)    ->    Union[str, Any]:
								super().__init__(**A					)

								if vision_config is None:
															UpperCAmelCase  :	int							  =	{}
															logger.info("""vision_config is None. initializing the Blip2VisionConfig with default values."""					)

								if qformer_config is None:
															UpperCAmelCase  :	Any							  =	{}
															logger.info("""qformer_config is None. Initializing the Blip2QFormerConfig with default values."""					)

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

								UpperCAmelCase  :	str							  =	BlipaVisionConfig(**A					)
								UpperCAmelCase  :	Dict							  =	BlipaQFormerConfig(**A					)
								UpperCAmelCase  :	Any							  =	text_config["""model_type"""] if """model_type""" in text_config else """opt"""
								UpperCAmelCase  :	List[Any]							  =	CONFIG_MAPPING[text_model_type](**A					)

								UpperCAmelCase  :	int							  =	self.text_config.tie_word_embeddings
								UpperCAmelCase  :	Tuple							  =	self.text_config.is_encoder_decoder

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





	@classmethod
	def 				_lowercase(						cls	,	A	,	A	,	A	,	**A	,	)    ->    Union[str, Any]:
								return cls(
								    vision_config=vision_config.to_dict()	,	qformer_config=qformer_config.to_dict()	,	text_config=text_config.to_dict()	,	**A	,	)






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






'''simple docstring'''




def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							UpperCAmelCase  :	Union[str, Any]							  =	set()

							# Replace all the whitespace in our sentence
							UpperCAmelCase  :	List[str]							  =	input_str.replace(""" """			,       """"""	)
							for alpha in input_str:
														if "a" <= alpha.lower() <= "z":
																					frequency.add(alpha.lower()	)
							return len(_lowercase	) == 2_6



def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							UpperCAmelCase  :	Tuple							  =	[False] * 2_6
							for char in input_str:
														if char.islower():
																					UpperCAmelCase  :	Any							  =	True
														elif char.isupper():
																					UpperCAmelCase  :	Union[str, Any]							  =	True
							return all(_lowercase	)



def    __lowerCamelCase						(      _lowercase = "The quick brown fox jumps over the lazy dog"			,       )   ->    bool:
							return len({char for char in input_str.lower() if char.isalpha()}	) == 2_6



def    __lowerCamelCase						(      )   ->    None:
							from timeit import timeit

							UpperCAmelCase  :	str							  =	"""from __main__ import is_pangram, is_pangram_faster, is_pangram_fastest"""
							print(timeit("""is_pangram()"""			,       setup=_lowercase	)	)
							print(timeit("""is_pangram_faster()"""			,       setup=_lowercase	)	)
							print(timeit("""is_pangram_fastest()"""			,       setup=_lowercase	)	)
							# 5.348480500048026, 2.6477354579837993, 1.8470395830227062
							# 5.036091582966037, 2.644472333951853,  1.8869528750656173


if __name__ == "__main__":
							import doctest

							doctest.testmod()
							benchmark()

