


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   :					int	=      logging.get_logger(__name__)

A   :					int	=      {
    "salesforce/blip2-opt-2.7b": "https://huggingface.co/salesforce/blip2-opt-2.7b/resolve/main/config.json",
}







class     _lowercase				(							lowercase__):


       """simple docstring"""




       A__      		=    "blip_2_vision_model"





       def __init__(     self							:    Optional[Any]      ,   __lowerCamelCase							:    str=1408      ,   __lowerCamelCase							:    Optional[Any]=6144      ,   __lowerCamelCase							:    int=39      ,   __lowerCamelCase							:    List[Any]=16      ,   __lowerCamelCase							:    Optional[int]=224      ,   __lowerCamelCase							:    Any=14      ,   __lowerCamelCase							:    Dict="gelu"      ,   __lowerCamelCase							:    Optional[Any]=0.0_0_0_0_1      ,   __lowerCamelCase							:    Union[str, Any]=0.0      ,   __lowerCamelCase							:    Optional[int]=1E-1_0      ,   __lowerCamelCase							:    Union[str, Any]=True      ,   **__lowerCamelCase							:    Dict      ,   ):


        '''simple docstring'''



        super().__init__(**__lowerCAmelCase )

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





       @classmethod
       def 		lowerCAmelCase  (     cls							:    Union[str, Any]      ,   __lowerCamelCase							:    Any      ,   **__lowerCamelCase							:    str ):


        '''simple docstring'''



        cls._set_token_in_kwargs(__lowerCAmelCase )

        lowerCamelCase__					,     lowerCamelCase__	:       str					=						cls.get_config_dict(__lowerCAmelCase      ,   **__lowerCAmelCase )

        # get the vision config dict if we are loading from Blip2Config
        if config_dict.get("model_type" ) == "blip-2":
         lowerCamelCase__	:       Any					=						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(__lowerCAmelCase      ,   **__lowerCAmelCase )







class     _lowercase				(							lowercase__):


       """simple docstring"""




       A__      		=    "blip_2_qformer"





       def __init__(     self							:    str      ,   __lowerCamelCase							:    Tuple=30522      ,   __lowerCamelCase							:    Dict=768      ,   __lowerCamelCase							:    Tuple=12      ,   __lowerCamelCase							:    str=12      ,   __lowerCamelCase							:    str=3072      ,   __lowerCamelCase							:    Union[str, Any]="gelu"      ,   __lowerCamelCase							:    Optional[int]=0.1      ,   __lowerCamelCase							:    Union[str, Any]=0.1      ,   __lowerCamelCase							:    str=512      ,   __lowerCamelCase							:    Optional[Any]=0.0_2      ,   __lowerCamelCase							:    Union[str, Any]=1E-1_2      ,   __lowerCamelCase							:    str=0      ,   __lowerCamelCase							:    List[str]="absolute"      ,   __lowerCamelCase							:    List[str]=2      ,   __lowerCamelCase							:    int=1408      ,   **__lowerCamelCase							:    int      ,   ):


        '''simple docstring'''



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

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





       @classmethod
       def 		lowerCAmelCase  (     cls							:    Optional[Any]      ,   __lowerCamelCase							:    List[str]      ,   **__lowerCamelCase							:    str ):


        '''simple docstring'''



        cls._set_token_in_kwargs(__lowerCAmelCase )

        lowerCamelCase__					,     lowerCamelCase__	:       Optional[int]					=						cls.get_config_dict(__lowerCAmelCase      ,   **__lowerCAmelCase )

        # get the qformer config dict if we are loading from Blip2Config
        if config_dict.get("model_type" ) == "blip-2":
         lowerCamelCase__	:       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(__lowerCAmelCase      ,   **__lowerCAmelCase )







class     _lowercase				(							lowercase__):


       """simple docstring"""




       A__      		=    "blip-2"
       A__      		=    True





       def __init__(     self							:    str      ,   __lowerCamelCase							:    List[Any]=None      ,   __lowerCamelCase							:    List[Any]=None      ,   __lowerCamelCase							:    str=None      ,   __lowerCamelCase							:    List[str]=32      ,   **__lowerCamelCase							:    Any ):


        '''simple docstring'''



        super().__init__(**__lowerCAmelCase )

        if vision_config is None:
         lowerCamelCase__	:       List[Any]					=						{}
         logger.info("vision_config is None. initializing the Blip2VisionConfig with default values." )

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

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

        lowerCamelCase__	:       Optional[Any]					=						BlipaVisionConfig(**__lowerCAmelCase )
        lowerCamelCase__	:       List[Any]					=						BlipaQFormerConfig(**__lowerCAmelCase )
        lowerCamelCase__	:       Any					=						text_config["model_type"] if "model_type" in text_config else "opt"
        lowerCamelCase__	:       Tuple					=						CONFIG_MAPPING[text_model_type](**__lowerCAmelCase )

        lowerCamelCase__	:       Dict					=						self.text_config.tie_word_embeddings
        lowerCamelCase__	:       str					=						self.text_config.is_encoder_decoder

        lowerCamelCase__	:       Union[str, Any]					=						num_query_tokens
        lowerCamelCase__	:       Any					=						self.vision_config.hidden_size
        lowerCamelCase__	:       List[Any]					=						self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
        lowerCamelCase__	:       Dict					=						1.0
        lowerCamelCase__	:       List[Any]					=						0.0_2





       @classmethod
       def 		lowerCAmelCase  (     cls							:    int      ,   __lowerCamelCase							:    str      ,   __lowerCamelCase							:    List[Any]      ,   __lowerCamelCase							:    Optional[int]      ,   **__lowerCamelCase							:    List[str]      ,   ):


        '''simple docstring'''



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





       def 		lowerCAmelCase  (     self							:    Union[str, Any] ):


        '''simple docstring'''



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






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_sentencepiece_available,
    is_torch_available,
)


A   :					Optional[int]	=      {
    "configuration_speecht5": [
        "SPEECHT5_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "SPEECHT5_PRETRAINED_HIFIGAN_CONFIG_ARCHIVE_MAP",
        "SpeechT5Config",
        "SpeechT5HifiGanConfig",
    ],
    "feature_extraction_speecht5": ["SpeechT5FeatureExtractor"],
    "processing_speecht5": ["SpeechT5Processor"],
}

try:
    if not is_sentencepiece_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A   :					List[Any]	=      ["SpeechT5Tokenizer"]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    A   :					List[str]	=      [
        "SPEECHT5_PRETRAINED_MODEL_ARCHIVE_LIST",
        "SpeechT5ForSpeechToText",
        "SpeechT5ForSpeechToSpeech",
        "SpeechT5ForTextToSpeech",
        "SpeechT5Model",
        "SpeechT5PreTrainedModel",
        "SpeechT5HifiGan",
    ]

if TYPE_CHECKING:
    from .configuration_speechta import (
        SPEECHT5_PRETRAINED_CONFIG_ARCHIVE_MAP,
        SPEECHT5_PRETRAINED_HIFIGAN_CONFIG_ARCHIVE_MAP,
        SpeechTaConfig,
        SpeechTaHifiGanConfig,
    )
    from .feature_extraction_speechta import SpeechTaFeatureExtractor
    from .processing_speechta import SpeechTaProcessor

    try:
        if not is_sentencepiece_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .tokenization_speechta import SpeechTaTokenizer

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_speechta import (
            SPEECHT5_PRETRAINED_MODEL_ARCHIVE_LIST,
            SpeechTaForSpeechToSpeech,
            SpeechTaForSpeechToText,
            SpeechTaForTextToSpeech,
            SpeechTaHifiGan,
            SpeechTaModel,
            SpeechTaPreTrainedModel,
        )

else:
    import sys

    A   :					Any	=      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)


