


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

a__    :							Any            =					{
    '''salesforce/blip2-opt-2.7b''': '''https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json''',
}




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  Optional[int]    =      "blip_2_vision_model"




	def __init__(			self      :    Union[str, Any]      ,      UpperCAmelCase__      :    Optional[int]=1_4_0_8      ,      UpperCAmelCase__      :    str=6_1_4_4      ,      UpperCAmelCase__      :    int=3_9      ,      UpperCAmelCase__      :    List[Any]=1_6      ,      UpperCAmelCase__      :    Tuple=2_2_4      ,      UpperCAmelCase__      :    Any=1_4      ,      UpperCAmelCase__      :    List[str]="gelu"      ,      UpperCAmelCase__      :    Union[str, Any]=0.00_001      ,      UpperCAmelCase__      :    Dict=0.0      ,      UpperCAmelCase__      :    Dict=1E-10      ,      UpperCAmelCase__      :    Dict=True      ,      **UpperCAmelCase__      :    List[Any]      ,      )	->     List[str]:
						super().__init__(**UpperCAmelCase__       )

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




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

						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    cls.get_config_dict(UpperCAmelCase__      ,      **UpperCAmelCase__       )

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




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  int    =      "blip_2_qformer"




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

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




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

						__SCREAMING_SNAKE_CASE       ,  __SCREAMING_SNAKE_CASE						       =    cls.get_config_dict(UpperCAmelCase__      ,      **UpperCAmelCase__       )

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




class 			UpperCamelCase_     (			UpperCamelCase):

	"""simple docstring"""





	snake_case__    :  Dict    =      "blip-2"
	snake_case__    :  Dict    =      True




	def __init__(			self      :    str      ,      UpperCAmelCase__      :    List[str]=None      ,      UpperCAmelCase__      :    List[str]=None      ,      UpperCAmelCase__      :    Dict=None      ,      UpperCAmelCase__      :    Any=3_2      ,      **UpperCAmelCase__      :    Union[str, Any]       )	->     Tuple:
						super().__init__(**UpperCAmelCase__       )

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

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

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

						__SCREAMING_SNAKE_CASE						       =    BlipaVisionConfig(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    BlipaQFormerConfig(**UpperCAmelCase__       )
						__SCREAMING_SNAKE_CASE						       =    text_config["model_type"] if "model_type" in text_config else "opt"
						__SCREAMING_SNAKE_CASE						       =    CONFIG_MAPPING[text_model_type](**UpperCAmelCase__       )

						__SCREAMING_SNAKE_CASE						       =    self.text_config.tie_word_embeddings
						__SCREAMING_SNAKE_CASE						       =    self.text_config.is_encoder_decoder

						__SCREAMING_SNAKE_CASE						       =    num_query_tokens
						__SCREAMING_SNAKE_CASE						       =    self.vision_config.hidden_size
						__SCREAMING_SNAKE_CASE						       =    self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
						__SCREAMING_SNAKE_CASE						       =    1.0
						__SCREAMING_SNAKE_CASE						       =    0.02




	@classmethod
	def   UpperCAmelCase_				(			cls      :    Optional[int]      ,      UpperCAmelCase__      :    BlipaVisionConfig      ,      UpperCAmelCase__      :    BlipaQFormerConfig      ,      UpperCAmelCase__      :    PretrainedConfig      ,      **UpperCAmelCase__      :    Union[str, Any]      ,      )	->     Union[str, Any]:
						return cls(
						    vision_config=vision_config.to_dict()      ,      qformer_config=qformer_config.to_dict()      ,      text_config=text_config.to_dict()      ,      **UpperCAmelCase__      ,      )




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




"""simple docstring"""







from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
		if not (is_transformers_available() and is_torch_available()):
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		from ...utils.dummy_torch_and_transformers_objects import KandinskyPipeline, KandinskyPriorPipeline
else:
		from .pipeline_kandinsky import KandinskyPipeline
		from .pipeline_kandinsky_imgaimg import KandinskyImgaImgPipeline
		from .pipeline_kandinsky_inpaint import KandinskyInpaintPipeline
		from .pipeline_kandinsky_prior import KandinskyPriorPipeline, KandinskyPriorPipelineOutput
		from .text_encoder import MultilingualCLIP
