



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


lowercase__					:						Optional[int]												=						logging.get_logger(__name__)

lowercase__					:						Union[str, Any]												=						{
    '''Salesforce/instruct-blip-flan-t5''': '''https://huggingface.co/Salesforce/instruct-blip-flan-t5/resolve/main/config.json''',
}




class  _UpperCAmelCase (    lowerCAmelCase__):
 _lowerCAmelCase     :    Optional[int]	      =	"""instructblip_vision_model"""

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

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






 @classmethod
 def 		_snake_case      (  cls	: List[Any]						,  lowercase_	: Union[str, os.PathLike]						,  **lowercase_	: Optional[int]       ):
     cls._set_token_in_kwargs(lowercase_       )

     snake_case_				:  List[str]       =			cls.get_config_dict(lowercase_						,  **lowercase_       )

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

 def __init__(  self	: Any						,  lowercase_	: Dict=30522						,  lowercase_	: str=768						,  lowercase_	: Optional[int]=12						,  lowercase_	: Union[str, Any]=12						,  lowercase_	: Any=3072						,  lowercase_	: Any="gelu"						,  lowercase_	: List[Any]=0.1						,  lowercase_	: Optional[int]=0.1						,  lowercase_	: Optional[Any]=512						,  lowercase_	: int=0.02						,  lowercase_	: Optional[Any]=1E-12						,  lowercase_	: Union[str, Any]=0						,  lowercase_	: int="absolute"						,  lowercase_	: int=2						,  lowercase_	: List[Any]=1408						,  **lowercase_	: List[str]						,  ):
     super().__init__(pad_token_id=lowercase_						,  **lowercase_       )

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






 @classmethod
 def 		_snake_case      (  cls	: List[str]						,  lowercase_	: Union[str, os.PathLike]						,  **lowercase_	: str       ):
     cls._set_token_in_kwargs(lowercase_       )

     snake_case_				:  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":
         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  _UpperCAmelCase (    lowerCAmelCase__):
 _lowerCAmelCase     :    int	      =	"""instructblip"""
 _lowerCAmelCase     :    List[Any]	      =	True

 def __init__(  self	: int						,  lowercase_	: Any=None						,  lowercase_	: str=None						,  lowercase_	: Optional[Any]=None						,  lowercase_	: Tuple=32						,  **lowercase_	: Optional[Any]       ):
     super().__init__(**lowercase_       )

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

     if qformer_config is None:
         snake_case_				:  Dict       =			{}
         logger.info('''qformer_config is None. Initializing the InstructBlipQFormerConfig with default values.'''       )

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

     snake_case_				:  str       =			InstructBlipVisionConfig(**lowercase_       )
     snake_case_				:  Union[str, Any]       =			InstructBlipQFormerConfig(**lowercase_       )
     snake_case_				:  Union[str, Any]       =			text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
     snake_case_				:  List[Any]       =			CONFIG_MAPPING[text_model_type](**lowercase_       )

     snake_case_				:  Union[str, Any]       =			self.text_config.tie_word_embeddings
     snake_case_				:  List[str]       =			self.text_config.is_encoder_decoder

     snake_case_				:  Dict       =			num_query_tokens
     snake_case_				:  Dict       =			self.vision_config.hidden_size
     snake_case_				:  Optional[Any]       =			self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
     snake_case_				:  List[str]       =			1.0
     snake_case_				:  List[str]       =			0.02

 @classmethod
 def 		_snake_case      (  cls	: List[str]						,  lowercase_	: InstructBlipVisionConfig						,  lowercase_	: InstructBlipQFormerConfig						,  lowercase_	: PretrainedConfig						,  **lowercase_	: Optional[Any]						,  ):
     return cls(
         vision_config=vision_config.to_dict()						,  qformer_config=qformer_config.to_dict()						,  text_config=text_config.to_dict()						,  **lowercase_						,  )






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










"""simple docstring"""

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

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available




@dataclass
class  _UpperCAmelCase (    lowerCAmelCase__):
 _lowerCAmelCase     :    Union[List[PIL.Image.Image], np.ndarray]
 _lowerCAmelCase     :    Optional[List[bool]]


if is_transformers_available() and is_torch_available():
     from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline





