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

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







class     lowercase		( SCREAMING_SNAKE_CASE__		):
							lowercase_	:	Optional[int]	 ='''instructblip_vision_model'''




							def __init__(    self       ,A__=1_4_0_8       ,A__=6_1_4_4       ,A__=3_9       ,A__=1_6       ,A__=2_2_4       ,A__=1_4       ,A__="gelu"       ,A__=1E-6       ,A__=0.0       ,A__=1E-10       ,A__=True       ,**A__       ,):
												super().__init__(**A__)

												lowercase						     =						hidden_size
												lowercase						     =						intermediate_size
												lowercase						     =						num_hidden_layers
												lowercase						     =						num_attention_heads
												lowercase						     =						patch_size
												lowercase						     =						image_size
												lowercase						     =						initializer_range
												lowercase						     =						attention_dropout
												lowercase						     =						layer_norm_eps
												lowercase						     =						hidden_act
												lowercase						     =						qkv_bias





							@classmethod
							def 			A__				(    cls       ,A__       ,**A__):
												cls._set_token_in_kwargs(A__)

												lowercase     ,						lowercase						     =						cls.get_config_dict(A__       ,**A__)

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




							def __init__(    self       ,A__=3_0_5_2_2       ,A__=7_6_8       ,A__=1_2       ,A__=1_2       ,A__=3_0_7_2       ,A__="gelu"       ,A__=0.1       ,A__=0.1       ,A__=5_1_2       ,A__=0.02       ,A__=1E-12       ,A__=0       ,A__="absolute"       ,A__=2       ,A__=1_4_0_8       ,**A__       ,):
												super().__init__(pad_token_id=A__       ,**A__)

												lowercase						     =						vocab_size
												lowercase						     =						hidden_size
												lowercase						     =						num_hidden_layers
												lowercase						     =						num_attention_heads
												lowercase						     =						hidden_act
												lowercase						     =						intermediate_size
												lowercase						     =						hidden_dropout_prob
												lowercase						     =						attention_probs_dropout_prob
												lowercase						     =						max_position_embeddings
												lowercase						     =						initializer_range
												lowercase						     =						layer_norm_eps
												lowercase						     =						position_embedding_type
												lowercase						     =						cross_attention_frequency
												lowercase						     =						encoder_hidden_size





							@classmethod
							def 			A__				(    cls       ,A__       ,**A__):
												cls._set_token_in_kwargs(A__)

												lowercase     ,						lowercase						     =						cls.get_config_dict(A__       ,**A__)

												# get the qformer config dict if we are loading from InstructBlipConfig
												if config_dict.get('''model_type''') == "instructblip":
																	lowercase						     =						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		( SCREAMING_SNAKE_CASE__		):
							lowercase_	:	str	 ='''instructblip'''
							lowercase_	:	str	 =True




							def __init__(    self       ,A__=None       ,A__=None       ,A__=None       ,A__=3_2       ,**A__):
												super().__init__(**A__)

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

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

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

												lowercase						     =						InstructBlipVisionConfig(**A__)
												lowercase						     =						InstructBlipQFormerConfig(**A__)
												lowercase						     =						text_config['''model_type'''] if '''model_type''' in text_config else '''opt'''
												lowercase						     =						CONFIG_MAPPING[text_model_type](**A__)

												lowercase						     =						self.text_config.tie_word_embeddings
												lowercase						     =						self.text_config.is_encoder_decoder

												lowercase						     =						num_query_tokens
												lowercase						     =						self.vision_config.hidden_size
												lowercase						     =						self.text_config.model_type in MODEL_FOR_CAUSAL_LM_MAPPING_NAMES
												lowercase						     =						1.0
												lowercase						     =						0.02




							@classmethod
							def 			A__				(    cls       ,A__       ,A__       ,A__       ,**A__       ,):
												return cls(
												    vision_config=vision_config.to_dict()       ,qformer_config=qformer_config.to_dict()       ,text_config=text_config.to_dict()       ,**A__       ,)





							def 			A__				(    self):
												lowercase						     =						copy.deepcopy(self.__dict__)
												lowercase						     =						self.vision_config.to_dict()
												lowercase						     =						self.qformer_config.to_dict()
												lowercase						     =						self.text_config.to_dict()
												lowercase						     =						self.__class__.model_type
												return output






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_flax_available,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowercase__		:Any			  =   {
    "configuration_distilbert": [
        "DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "DistilBertConfig",
        "DistilBertOnnxConfig",
    ],
    "tokenization_distilbert": ["DistilBertTokenizer"],
}

try:
							if not is_tokenizers_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase__		:Tuple			  =   ["DistilBertTokenizerFast"]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase__		:Union[str, Any]			  =   [
							    "DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "DistilBertForMaskedLM",
							    "DistilBertForMultipleChoice",
							    "DistilBertForQuestionAnswering",
							    "DistilBertForSequenceClassification",
							    "DistilBertForTokenClassification",
							    "DistilBertModel",
							    "DistilBertPreTrainedModel",
							]

try:
							if not is_tf_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase__		:Optional[int]			  =   [
							    "TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "TFDistilBertForMaskedLM",
							    "TFDistilBertForMultipleChoice",
							    "TFDistilBertForQuestionAnswering",
							    "TFDistilBertForSequenceClassification",
							    "TFDistilBertForTokenClassification",
							    "TFDistilBertMainLayer",
							    "TFDistilBertModel",
							    "TFDistilBertPreTrainedModel",
							]

try:
							if not is_flax_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							lowercase__		:Union[str, Any]			  =   [
							    "FlaxDistilBertForMaskedLM",
							    "FlaxDistilBertForMultipleChoice",
							    "FlaxDistilBertForQuestionAnswering",
							    "FlaxDistilBertForSequenceClassification",
							    "FlaxDistilBertForTokenClassification",
							    "FlaxDistilBertModel",
							    "FlaxDistilBertPreTrainedModel",
							]


if TYPE_CHECKING:
							from .configuration_distilbert import (
							    DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    DistilBertConfig,
							    DistilBertOnnxConfig,
							)
							from .tokenization_distilbert import DistilBertTokenizer

							try:
														if not is_tokenizers_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .tokenization_distilbert_fast import DistilBertTokenizerFast

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_distilbert import (
														    DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    DistilBertForMaskedLM,
														    DistilBertForMultipleChoice,
														    DistilBertForQuestionAnswering,
														    DistilBertForSequenceClassification,
														    DistilBertForTokenClassification,
														    DistilBertModel,
														    DistilBertPreTrainedModel,
														)

							try:
														if not is_tf_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_tf_distilbert import (
														    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
														    TFDistilBertForMaskedLM,
														    TFDistilBertForMultipleChoice,
														    TFDistilBertForQuestionAnswering,
														    TFDistilBertForSequenceClassification,
														    TFDistilBertForTokenClassification,
														    TFDistilBertMainLayer,
														    TFDistilBertModel,
														    TFDistilBertPreTrainedModel,
														)

							try:
														if not is_flax_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flax_distilbert import (
														    FlaxDistilBertForMaskedLM,
														    FlaxDistilBertForMultipleChoice,
														    FlaxDistilBertForQuestionAnswering,
														    FlaxDistilBertForSequenceClassification,
														    FlaxDistilBertForTokenClassification,
														    FlaxDistilBertModel,
														    FlaxDistilBertPreTrainedModel,
														)

else:
							import sys

							lowercase__		:List[str]			  =   _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)




