




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

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






class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = "instructblip_vision_model"


 def __init__(    self:		List[Any],				a_:		str=1_408,				a_:		int=6_144,				a_:		int=39,				a_:		int=16,				a_:		Optional[int]=224,				a_:		Any=14,				a_:		List[Any]="gelu",				a_:		List[str]=1E-6,				a_:		int=0.0,				a_:		Any=1E-10,				a_:		str=True,				**a_:		int,				):




   '''simple docstring'''



   super().__init__(**a_		)

   _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							:		int								=  patch_size
   _snake_case							:		List[str]								=  image_size
   _snake_case							:		int								=  initializer_range
   _snake_case							:		List[Any]								=  attention_dropout
   _snake_case							:		List[Any]								=  layer_norm_eps
   _snake_case							:		Tuple								=  hidden_act
   _snake_case							:		Tuple								=  qkv_bias


 @classmethod
 def 			UpperCamelCase_       (    cls:		Tuple,				a_:		Union[str, os.PathLike],				**a_:		Union[str, Any]		):




   '''simple docstring'''



   cls._set_token_in_kwargs(a_		)

   _snake_case		, _snake_case							:		Dict								=  cls.get_config_dict(a_,				**a_		)

   # get the vision config dict if we are loading from InstructBlipConfig
   if config_dict.get("""model_type"""		) == "instructblip":
     _snake_case							:		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(a_,				**a_		)







class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = "instructblip_qformer"


 def __init__(    self:		Dict,				a_:		Optional[int]=30_522,				a_:		Optional[Any]=768,				a_:		Optional[int]=12,				a_:		List[str]=12,				a_:		Optional[Any]=3_072,				a_:		int="gelu",				a_:		List[str]=0.1,				a_:		Union[str, Any]=0.1,				a_:		List[Any]=512,				a_:		int=0.02,				a_:		Tuple=1E-12,				a_:		Tuple=0,				a_:		Dict="absolute",				a_:		str=2,				a_:		str=1_408,				**a_:		int,				):




   '''simple docstring'''



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

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


 @classmethod
 def 			UpperCamelCase_       (    cls:		int,				a_:		Union[str, os.PathLike],				**a_:		Optional[Any]		):




   '''simple docstring'''



   cls._set_token_in_kwargs(a_		)

   _snake_case		, _snake_case							:		int								=  cls.get_config_dict(a_,				**a_		)

   # get the qformer config dict if we are loading from InstructBlipConfig
   if config_dict.get("""model_type"""		) == "instructblip":
     _snake_case							:		List[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(a_,				**a_		)







class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = "instructblip"
 lowercase__			 = True


 def __init__(    self:		Optional[Any],				a_:		List[Any]=None,				a_:		List[Any]=None,				a_:		Any=None,				a_:		Dict=32,				**a_:		Dict		):




   '''simple docstring'''



   super().__init__(**a_		)

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

   if qformer_config is None:
     _snake_case							:		Optional[Any]								=  {}
     logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values."""		)

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

   _snake_case							:		List[str]								=  InstructBlipVisionConfig(**a_		)
   _snake_case							:		Tuple								=  InstructBlipQFormerConfig(**a_		)
   _snake_case							:		List[Any]								=  text_config["""model_type"""] if """model_type""" in text_config else """opt"""
   _snake_case							:		Any								=  CONFIG_MAPPING[text_model_type](**a_		)

   _snake_case							:		Dict								=  self.text_config.tie_word_embeddings
   _snake_case							:		List[Any]								=  self.text_config.is_encoder_decoder

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


 @classmethod
 def 			UpperCamelCase_       (    cls:		int,				a_:		InstructBlipVisionConfig,				a_:		InstructBlipQFormerConfig,				a_:		PretrainedConfig,				**a_:		List[Any],				):




   '''simple docstring'''



   return cls(
       vision_config=vision_config.to_dict(),				qformer_config=qformer_config.to_dict(),				text_config=text_config.to_dict(),				**a_,				)


 def 			UpperCamelCase_       (    self:		List[str]		):




   '''simple docstring'''



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








"""simple docstring"""


from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


A_      =    logging.get_logger(__name__)

A_      =    {
    '''microsoft/swin-tiny-patch4-window7-224''': (
        '''https://huggingface.co/microsoft/swin-tiny-patch4-window7-224/resolve/main/config.json'''
    ),
    # See all Swin models at https://huggingface.co/models?filter=swin
}






class  lowercase(					__a	,      __a			):







 '''simple docstring'''





 lowercase__			 = "swin"

 lowercase__			 = {
     "num_attention_heads": "num_heads",
     "num_hidden_layers": "num_layers",
 }


 def __init__(    self:		Any,				a_:		List[str]=224,				a_:		List[Any]=4,				a_:		List[Any]=3,				a_:		Dict=96,				a_:		List[str]=[2, 2, 6, 2],				a_:		int=[3, 6, 12, 24],				a_:		int=7,				a_:		str=4.0,				a_:		Optional[Any]=True,				a_:		Dict=0.0,				a_:		List[Any]=0.0,				a_:		List[str]=0.1,				a_:		Union[str, Any]="gelu",				a_:		Dict=False,				a_:		Union[str, Any]=0.02,				a_:		Optional[int]=1E-5,				a_:		Optional[int]=32,				a_:		Tuple=None,				a_:		Union[str, Any]=None,				**a_:		Any,				):




   '''simple docstring'''



   super().__init__(**a_		)

   _snake_case							:		Any								=  image_size
   _snake_case							:		List[Any]								=  patch_size
   _snake_case							:		Tuple								=  num_channels
   _snake_case							:		str								=  embed_dim
   _snake_case							:		Union[str, Any]								=  depths
   _snake_case							:		int								=  len(a_		)
   _snake_case							:		Union[str, Any]								=  num_heads
   _snake_case							:		List[str]								=  window_size
   _snake_case							:		str								=  mlp_ratio
   _snake_case							:		Union[str, Any]								=  qkv_bias
   _snake_case							:		Dict								=  hidden_dropout_prob
   _snake_case							:		str								=  attention_probs_dropout_prob
   _snake_case							:		Union[str, Any]								=  drop_path_rate
   _snake_case							:		Optional[int]								=  hidden_act
   _snake_case							:		str								=  use_absolute_embeddings
   _snake_case							:		Tuple								=  layer_norm_eps
   _snake_case							:		List[Any]								=  initializer_range
   _snake_case							:		Optional[Any]								=  encoder_stride
   # we set the hidden_size attribute in order to make Swin work with VisionEncoderDecoderModel
   # this indicates the channel dimension after the last stage of the model
   _snake_case							:		Any								=  int(embed_dim * 2 ** (len(a_		) - 1)		)
   _snake_case							:		Any								=  ["""stem"""] + [f"stage{idx}" for idx in range(1,				len(a_		) + 1		)]
   _snake_case		, _snake_case							:		List[str]								=  get_aligned_output_features_output_indices(
       out_features=a_,				out_indices=a_,				stage_names=self.stage_names		)







class  lowercase(					__a			):







 '''simple docstring'''





 lowercase__			 = version.parse("1.11"			)


 @property
 def 			UpperCamelCase_       (    self:		Any		):




   '''simple docstring'''



   return OrderedDict(
       [
           ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
       ]		)


 @property
 def 			UpperCamelCase_       (    self:		List[str]		):




   '''simple docstring'''



   return 1E-4


