

import copy
import os
from typing import Union

from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowerCAmelCase__		      =       logging.get_logger(__name__)

lowerCAmelCase__		      =       {
    """BAAI/AltCLIP""": """https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json""",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}

class     a__  (    snake_case	):
			"""simple docstring"""







			__lowerCamelCase       				=				'altclip_text_model'


			def __init__(			self					,					lowercase=250002					,					lowercase=1024					,					lowercase=24					,					lowercase=16					,					lowercase=4096					,					lowercase="gelu"					,					lowercase=0.1					,					lowercase=0.1					,					lowercase=514					,					lowercase=1					,					lowercase=0.02					,					lowercase=0.02					,					lowercase=1e-05					,					lowercase=1					,					lowercase=0					,					lowercase=2					,					lowercase="absolute"					,					lowercase=True					,					lowercase=768					,					**lowercase					,					)     ->  Optional[Any]:
							'''simple docstring'''






							super().__init__(pad_token_id=lowercase					,					bos_token_id=lowercase					,					eos_token_id=lowercase					,					**lowercase				)

							A__						=	vocab_size
							A__						=	hidden_size
							A__						=	num_hidden_layers
							A__						=	num_attention_heads
							A__						=	hidden_act
							A__						=	intermediate_size
							A__						=	hidden_dropout_prob
							A__						=	attention_probs_dropout_prob
							A__						=	max_position_embeddings
							A__						=	type_vocab_size
							A__						=	initializer_range
							A__						=	initializer_factor
							A__						=	layer_norm_eps
							A__						=	position_embedding_type
							A__						=	use_cache
							A__						=	project_dim

class     a__  (    snake_case	):
			"""simple docstring"""







			__lowerCamelCase       				=				'altclip_vision_model'


			def __init__(			self					,					lowercase=768					,					lowercase=3072					,					lowercase=512					,					lowercase=12					,					lowercase=12					,					lowercase=3					,					lowercase=224					,					lowercase=32					,					lowercase="quick_gelu"					,					lowercase=1e-5					,					lowercase=0.0					,					lowercase=0.02					,					lowercase=1.0					,					**lowercase					,					)     ->  Tuple:
							'''simple docstring'''






							super().__init__(**lowercase				)

							A__						=	hidden_size
							A__						=	intermediate_size
							A__						=	projection_dim
							A__						=	num_hidden_layers
							A__						=	num_attention_heads
							A__						=	num_channels
							A__						=	patch_size
							A__						=	image_size
							A__						=	initializer_range
							A__						=	initializer_factor
							A__						=	attention_dropout
							A__						=	layer_norm_eps
							A__						=	hidden_act


			@classmethod
			def    UpperCamelCase						(			cls					,					lowercase					,					**lowercase				)     ->  "PretrainedConfig":
							'''simple docstring'''






							cls._set_token_in_kwargs(lowercase				)

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

							# get the vision config dict if we are loading from AltCLIPConfig
							if config_dict.get("model_type"				) == "altclip":
											A__						=	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(lowercase					,					**lowercase				)

class     a__  (    snake_case	):
			"""simple docstring"""







			__lowerCamelCase       				=				'altclip'
			__lowerCamelCase       				=				True


			def __init__(			self					,					lowercase=None					,					lowercase=None					,					lowercase=768					,					lowercase=2.6592					,					**lowercase				)     ->  List[str]:
							'''simple docstring'''






							A__						=	kwargs.pop("text_config_dict"					,					lowercase				)
							A__						=	kwargs.pop("vision_config_dict"					,					lowercase				)

							super().__init__(**lowercase				)

							# Instead of simply assigning `[text|vision]_config_dict` to `[text|vision]_config`, we use the values in
							# `[text|vision]_config_dict` to update the values in `[text|vision]_config`. The values should be same in most
							# cases, but we don't want to break anything regarding `_config_dict` that existed before commit `8827e1b2`.
							if text_config_dict is not None:
											if text_config is None:
															A__						=	{}

											# This is the complete result when using `text_config_dict`.
											A__						=	AltCLIPTextConfig(**lowercase				).to_dict()

											# Give a warning if the values exist in both `_text_config_dict` and `text_config` but being different.
											for key, value in _text_config_dict.items():
															if key in text_config and value != text_config[key] and key not in ["transformers_version"]:
																			# If specified in `text_config_dict`
																			if key in text_config_dict:
																							A__						=	(
																							    F'`{key}` is found in both `text_config_dict` and `text_config` but with different values. '
																							    F'The value `text_config_dict["{key}"]` will be used instead.'
																							)
																			# If inferred from default argument values (just to be super careful)
																			else:
																							A__						=	(
																							    F'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
																							    F'value `text_config["{key}"]` will be overriden.'
																							)
																			logger.warning(lowercase				)

            # Update all values in `text_config` with the ones in `_text_config_dict`.
											text_config.update(_text_config_dict				)

							if vision_config_dict is not None:
											if vision_config is None:
															A__						=	{}

											# This is the complete result when using `vision_config_dict`.
											A__						=	AltCLIPVisionConfig(**lowercase				).to_dict()
											# convert keys to string instead of integer
											if "id2label" in _vision_config_dict:
															A__						=	{
															    str(lowercase				): value for key, value in _vision_config_dict["id2label"].items()
															}

											# Give a warning if the values exist in both `_vision_config_dict` and `vision_config` but being different.
											for key, value in _vision_config_dict.items():
															if key in vision_config and value != vision_config[key] and key not in ["transformers_version"]:
																			# If specified in `vision_config_dict`
																			if key in vision_config_dict:
																							A__						=	(
																							    F'`{key}` is found in both `vision_config_dict` and `vision_config` but with different '
																							    F'values. The value `vision_config_dict["{key}"]` will be used instead.'
																							)
																			# If inferred from default argument values (just to be super careful)
																			else:
																							A__						=	(
																							    F'`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '
																							    F'The value `vision_config["{key}"]` will be overriden.'
																							)
																			logger.warning(lowercase				)

            # Update all values in `vision_config` with the ones in `_vision_config_dict`.
											vision_config.update(_vision_config_dict				)

							if text_config is None:
											A__						=	{}
											logger.info("`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."				)

							if vision_config is None:
											A__						=	{}
											logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."				)

							A__						=	AltCLIPTextConfig(**lowercase				)
							A__						=	AltCLIPVisionConfig(**lowercase				)

							A__						=	projection_dim
							A__						=	logit_scale_init_value
							A__						=	1.0


			@classmethod
			def    UpperCamelCase						(			cls					,					lowercase					,					lowercase					,					**lowercase				)     ->  Union[str, Any]:
							'''simple docstring'''






							return cls(text_config=text_config.to_dict()					,					vision_config=vision_config.to_dict()					,					**lowercase				)


			def    UpperCamelCase						(			self				)     ->  Tuple:
							'''simple docstring'''






							A__						=	copy.deepcopy(self.__dict__				)
							A__						=	self.text_config.to_dict()
							A__						=	self.vision_config.to_dict()
							A__						=	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,
)


A     :	str    = {
    'configuration_blenderbot': [
        'BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'BlenderbotConfig',
        'BlenderbotOnnxConfig',
    ],
    'tokenization_blenderbot': ['BlenderbotTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A     :	Optional[Any]    = ['BlenderbotTokenizerFast']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A     :	Optional[Any]    = [
					    'BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'BlenderbotForCausalLM',
					    'BlenderbotForConditionalGeneration',
					    'BlenderbotModel',
					    'BlenderbotPreTrainedModel',
					]


try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A     :	Dict    = [
					    'TFBlenderbotForConditionalGeneration',
					    'TFBlenderbotModel',
					    'TFBlenderbotPreTrainedModel',
					]


try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					A     :	Dict    = [
					    'FlaxBlenderbotForConditionalGeneration',
					    'FlaxBlenderbotModel',
					    'FlaxBlenderbotPreTrainedModel',
					]


if TYPE_CHECKING:
					from .configuration_blenderbot import (
					    BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP,
					    BlenderbotConfig,
					    BlenderbotOnnxConfig,
					)
					from .tokenization_blenderbot import BlenderbotTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_blenderbot_fast import BlenderbotTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_blenderbot import (
										    BLENDERBOT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BlenderbotForCausalLM,
										    BlenderbotForConditionalGeneration,
										    BlenderbotModel,
										    BlenderbotPreTrainedModel,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_blenderbot import (
										    TFBlenderbotForConditionalGeneration,
										    TFBlenderbotModel,
										    TFBlenderbotPreTrainedModel,
										)

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_blenderbot import (
										    FlaxBlenderbotForConditionalGeneration,
										    FlaxBlenderbotModel,
										    FlaxBlenderbotPreTrainedModel,
										)

else:
					import sys

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