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


__SCREAMING_SNAKE_CASE       :     Optional[Any]     =  logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE       :     List[Any]     =  {
    """salesforce/blip2-opt-2.7b""": """https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json""",
}

class 	lowerCamelCase_	(snake_case__    ):
      '''simple docstring'''

      __UpperCamelCase:  int						=						"blip_2_vision_model"




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

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





      @classmethod
      def      _A	(       cls						:				Tuple						,					A						:				Union[str, os.PathLike]						,					**A						:				List[str]       ):
             cls._set_token_in_kwargs(A       )

             _UpperCAmelCase      ,  _UpperCAmelCase     :  List[Any]							      =    cls.get_config_dict(A						,					**A       )

             # get the vision config dict if we are loading from Blip2Config
             if config_dict.get("model_type"       ) == "blip-2":
                    _UpperCAmelCase     :  Dict							      =    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 	lowerCamelCase_	(snake_case__    ):
      '''simple docstring'''

      __UpperCamelCase:  int						=						"blip_2_qformer"




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

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





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

             _UpperCAmelCase      ,  _UpperCAmelCase     :  str							      =    cls.get_config_dict(A						,					**A       )

             # get the qformer config dict if we are loading from Blip2Config
             if config_dict.get("model_type"       ) == "blip-2":
                    _UpperCAmelCase     :  List[str]							      =    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 	lowerCamelCase_	(snake_case__    ):
      '''simple docstring'''

      __UpperCamelCase:  int						=						"blip-2"
      __UpperCamelCase:  List[Any]						=						True




      def __init__(       self						:				str						,					A						:				Optional[Any]=None						,					A						:				List[Any]=None						,					A						:				str=None						,					A						:				Optional[int]=32						,					**A						:				Union[str, Any]       ):
             super().__init__(**A       )

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

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

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

             _UpperCAmelCase     :  Dict							      =    BlipaVisionConfig(**A       )
             _UpperCAmelCase     :  Optional[int]							      =    BlipaQFormerConfig(**A       )
             _UpperCAmelCase     :  str							      =    text_config["model_type"] if "model_type" in text_config else "opt"
             _UpperCAmelCase     :  int							      =    CONFIG_MAPPING[text_model_type](**A       )

             _UpperCAmelCase     :  Any							      =    self.text_config.tie_word_embeddings
             _UpperCAmelCase     :  Any							      =    self.text_config.is_encoder_decoder

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




      @classmethod
      def      _A	(       cls						:				List[Any]						,					A						:				BlipaVisionConfig						,					A						:				BlipaQFormerConfig						,					A						:				PretrainedConfig						,					**A						:				Any						,					):
             return cls(
                 vision_config=vision_config.to_dict()						,					qformer_config=qformer_config.to_dict()						,					text_config=text_config.to_dict()						,					**A						,					)





      def      _A	(       self						:				Optional[Any]       ):
             _UpperCAmelCase     :  Optional[Any]							      =    copy.deepcopy(self.__dict__       )
             _UpperCAmelCase     :  List[Any]							      =    self.vision_config.to_dict()
             _UpperCAmelCase     :  Tuple							      =    self.qformer_config.to_dict()
             _UpperCAmelCase     :  Dict							      =    self.text_config.to_dict()
             _UpperCAmelCase     :  Tuple							      =    self.__class__.model_type
             return output









import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=lowercase__   )
class     a    ( lowercase__   ):



      """simple docstring"""


      a  : str							       =	field(default='automatic-speech-recognition'							,       metadata={'include_in_asdict_even_if_is_default': True}   )
      a  : ClassVar[Features]							       =	Features({'audio': Audio()}   )
      a  : ClassVar[Features]							       =	Features({'transcription': Value('string'   )}   )
      a  : str							       =	"audio"
      a  : str							       =	"transcription"
      def 	UpperCAmelCase      (      self					:			Optional[Any]		,      __lowercase					:			Optional[int]					)							->      str:
        if self.audio_column not in features:
          raise ValueError(f"""Column {self.audio_column} is not present in features."""					)
        if not isinstance(features[self.audio_column]		,      __lowercase					):
          raise ValueError(f"""Column {self.audio_column} is not an Audio type."""					)
        __UpperCAmelCase							:	int           =  copy.deepcopy(self					)
        __UpperCAmelCase							:	str           =  self.input_schema.copy()
        __UpperCAmelCase							:	List[str]           =  features[self.audio_column]
        __UpperCAmelCase							:	Optional[Any]           =  input_schema
        return task_template




      @property
      def 	UpperCAmelCase      (      self					:			Union[str, Any]					)							->      Dict[str, str]:
        return {self.audio_column: "audio", self.transcription_column: "transcription"}


