




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


UpperCamelCase__						=			logging.get_logger(__name__)

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




class   a__			(       _UpperCAmelCase  ):
						snake_case__             = '''instructblip_vision_model'''





						def __init__(							self      :	Union[str, Any]     ,a__      :	List[str]=1408     ,a__      :	Dict=6144     ,a__      :	Optional[int]=39     ,a__      :	Dict=16     ,a__      :	Tuple=224     ,a__      :	int=14     ,a__      :	Optional[int]="gelu"     ,a__      :	Dict=1E-6     ,a__      :	List[Any]=0.0     ,a__      :	Tuple=1E-10     ,a__      :	Union[str, Any]=True     ,**a__      :	Optional[Any]     ,)						->       Any:




											"""simple docstring"""







											super().__init__(**lowercase_)

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







						@classmethod
						def       __UpperCamelCase     (							cls      :	List[str]     ,a__      :	Union[str, os.PathLike]     ,**a__      :	List[Any])						->       Any:




											"""simple docstring"""







											cls._set_token_in_kwargs(lowercase_)

											_lowerCAmelCase:List[Any]									=  cls.get_config_dict(lowercase_     ,**lowercase_)

											# get the vision config dict if we are loading from InstructBlipConfig
											if config_dict.get('''model_type''') == "instructblip":
																_lowerCAmelCase:List[str]									=  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   a__			(       _UpperCAmelCase  ):
						snake_case__             = '''instructblip_qformer'''





						def __init__(							self      :	Any     ,a__      :	Optional[Any]=3_0522     ,a__      :	List[str]=768     ,a__      :	int=12     ,a__      :	List[Any]=12     ,a__      :	int=3072     ,a__      :	str="gelu"     ,a__      :	Union[str, Any]=0.1     ,a__      :	Optional[int]=0.1     ,a__      :	str=512     ,a__      :	Union[str, Any]=0.02     ,a__      :	Dict=1E-12     ,a__      :	Optional[int]=0     ,a__      :	Union[str, Any]="absolute"     ,a__      :	Union[str, Any]=2     ,a__      :	Dict=1408     ,**a__      :	int     ,)						->       str:




											"""simple docstring"""







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

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







						@classmethod
						def       __UpperCamelCase     (							cls      :	List[str]     ,a__      :	Union[str, os.PathLike]     ,**a__      :	Optional[Any])						->       Optional[int]:




											"""simple docstring"""







											cls._set_token_in_kwargs(lowercase_)

											_lowerCAmelCase:List[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":
																_lowerCAmelCase:Dict									=  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   a__			(       _UpperCAmelCase  ):
						snake_case__             = '''instructblip'''
						snake_case__             = True





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




											"""simple docstring"""







											super().__init__(**lowercase_)

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

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

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

											_lowerCAmelCase:Any									=  InstructBlipVisionConfig(**lowercase_)
											_lowerCAmelCase:Optional[Any]									=  InstructBlipQFormerConfig(**lowercase_)
											_lowerCAmelCase:Dict									=  text_config["""model_type"""] if """model_type""" in text_config else """opt"""
											_lowerCAmelCase:Tuple									=  CONFIG_MAPPING[text_model_type](**lowercase_)

											_lowerCAmelCase:Any									=  self.text_config.tie_word_embeddings
											_lowerCAmelCase:List[str]									=  self.text_config.is_encoder_decoder

											_lowerCAmelCase:int									=  num_query_tokens
											_lowerCAmelCase:Tuple									=  self.vision_config.hidden_size
											_lowerCAmelCase:List[Any]									=  self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
											_lowerCAmelCase:List[str]									=  1.0
											_lowerCAmelCase:Union[str, Any]									=  0.02





						@classmethod
						def       __UpperCamelCase     (							cls      :	str     ,a__      :	InstructBlipVisionConfig     ,a__      :	InstructBlipQFormerConfig     ,a__      :	PretrainedConfig     ,**a__      :	int     ,)						->       Union[str, 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       __UpperCamelCase     (							self      :	List[Any])						->       Dict:




											"""simple docstring"""







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












"""simple docstring"""






from dataclasses import dataclass
from typing import List, Optional, Union

import numpy as np
import torch

from ...utils import BaseOutput, OptionalDependencyNotAvailable, is_torch_available, is_transformers_available




@dataclass
class   a__			(       UpperCamelCase_  ):
						snake_case__             = 42


try:
				if not (is_transformers_available() and is_torch_available()):
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
				from .pipeline_text_to_video_synth import TextToVideoSDPipeline
				from .pipeline_text_to_video_synth_imgaimg import VideoToVideoSDPipeline  # noqa: F401
				from .pipeline_text_to_video_zero import TextToVideoZeroPipeline






