



'''simple docstring'''





from __future__ import annotations
def        _SCREAMING_SNAKE_CASE  (	UpperCamelCase      ):



    """simple docstring"""





    if not nums:
        raise ValueError("""List is empty"""      )
    return sum(UpperCamelCase      ) / len(UpperCamelCase      )


if __name__ == "__main__":
 import doctest

 doctest.testmod()








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


_lowerCAmelCase										=     logging.get_logger(__name__)

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






class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				Optional[Any]           =				'''instructblip_vision_model'''




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

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






  @classmethod
  def 							UpperCAmelCase_     (   cls  ,__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		"PretrainedConfig":
      cls._set_token_in_kwargs(__UpperCAmelCase				)

      lowerCAmelCase__				,       lowerCAmelCase__			:  Tuple											= cls.get_config_dict(__UpperCAmelCase  ,**__UpperCAmelCase				)

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







class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				int           =				'''instructblip_qformer'''




  def __init__(   self  ,__UpperCAmelCase=3_0522  ,__UpperCAmelCase=768  ,__UpperCAmelCase=12  ,__UpperCAmelCase=12  ,__UpperCAmelCase=3072  ,__UpperCAmelCase="gelu"  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=0.1  ,__UpperCAmelCase=512  ,__UpperCAmelCase=0.0_2  ,__UpperCAmelCase=1E-12  ,__UpperCAmelCase=0  ,__UpperCAmelCase="absolute"  ,__UpperCAmelCase=2  ,__UpperCAmelCase=1408  ,**__UpperCAmelCase  ,)   ->		Tuple:
      super().__init__(pad_token_id=__UpperCAmelCase  ,**__UpperCAmelCase				)

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






  @classmethod
  def 							UpperCAmelCase_     (   cls  ,__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		"PretrainedConfig":
      cls._set_token_in_kwargs(__UpperCAmelCase				)

      lowerCAmelCase__				,       lowerCAmelCase__			:  Any											= cls.get_config_dict(__UpperCAmelCase  ,**__UpperCAmelCase				)

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







class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				Any           =				'''instructblip'''
  __lowercase							:				str           =				True




  def __init__(   self  ,__UpperCAmelCase=None  ,__UpperCAmelCase=None  ,__UpperCAmelCase=None  ,__UpperCAmelCase=32  ,**__UpperCAmelCase				)   ->		Any:
      super().__init__(**__UpperCAmelCase				)

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

      if qformer_config is None:
          lowerCAmelCase__			:  List[str]											= {}
          logger.info("""qformer_config is None. Initializing the InstructBlipQFormerConfig with default values."""				)

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

      lowerCAmelCase__			:  Any											= InstructBlipVisionConfig(**__UpperCAmelCase				)
      lowerCAmelCase__			:  Tuple											= InstructBlipQFormerConfig(**__UpperCAmelCase				)
      lowerCAmelCase__			:  Tuple											= text_config["""model_type"""] if """model_type""" in text_config else """opt"""
      lowerCAmelCase__			:  Any											= CONFIG_MAPPING[text_model_type](**__UpperCAmelCase				)

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

      lowerCAmelCase__			:  int											= num_query_tokens
      lowerCAmelCase__			:  List[str]											= self.vision_config.hidden_size
      lowerCAmelCase__			:  Optional[int]											= self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
      lowerCAmelCase__			:  Optional[Any]											= 1.0
      lowerCAmelCase__			:  Dict											= 0.0_2




  @classmethod
  def 							UpperCAmelCase_     (   cls  ,__UpperCAmelCase  ,__UpperCAmelCase  ,__UpperCAmelCase  ,**__UpperCAmelCase  ,)   ->		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				)   ->		str:
      lowerCAmelCase__			:  List[Any]											= copy.deepcopy(self.__dict__				)
      lowerCAmelCase__			:  str											= self.vision_config.to_dict()
      lowerCAmelCase__			:  Union[str, Any]											= self.qformer_config.to_dict()
      lowerCAmelCase__			:  Union[str, Any]											= self.text_config.to_dict()
      lowerCAmelCase__			:  str											= self.__class__.model_type
      return output


