
import copy
import os
from typing import Union

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


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

lowercase    :   List[str]						=			{
    'BAAI/AltCLIP': 'https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}




class 					lowerCamelCase__				(							__lowercase):




	'''simple docstring'''




	_A								=	'altclip_text_model'







	def __init__(   self						:Optional[int]	,  a						:Union[str, Any]=2_5_0_0_0_2	,  a						:Any=1_0_2_4	,  a						:Tuple=2_4	,  a						:Optional[int]=1_6	,  a						:Dict=4_0_9_6	,  a						:List[Any]="gelu"	,  a						:List[Any]=0.1	,  a						:Optional[int]=0.1	,  a						:Any=5_1_4	,  a						:List[str]=1	,  a						:Dict=0.02	,  a						:Dict=0.02	,  a						:Optional[Any]=1E-0_5	,  a						:Optional[int]=1	,  a						:List[str]=0	,  a						:Optional[Any]=2	,  a						:int="absolute"	,  a						:Union[str, Any]=True	,  a						:Union[str, Any]=7_6_8	,  **a						:int	,  )						->					List[Any]:
								super().__init__(pad_token_id=a	,  bos_token_id=a	,  eos_token_id=a	,  **a		)

								__UpperCamelCase      :  Optional[Any]       =   vocab_size
								__UpperCamelCase      :  int       =   hidden_size
								__UpperCamelCase      :  Tuple       =   num_hidden_layers
								__UpperCamelCase      :  Optional[Any]       =   num_attention_heads
								__UpperCamelCase      :  Union[str, Any]       =   hidden_act
								__UpperCamelCase      :  Tuple       =   intermediate_size
								__UpperCamelCase      :  Optional[Any]       =   hidden_dropout_prob
								__UpperCamelCase      :  Tuple       =   attention_probs_dropout_prob
								__UpperCamelCase      :  Any       =   max_position_embeddings
								__UpperCamelCase      :  List[str]       =   type_vocab_size
								__UpperCamelCase      :  Any       =   initializer_range
								__UpperCamelCase      :  Tuple       =   initializer_factor
								__UpperCamelCase      :  Union[str, Any]       =   layer_norm_eps
								__UpperCamelCase      :  str       =   position_embedding_type
								__UpperCamelCase      :  List[str]       =   use_cache
								__UpperCamelCase      :  Optional[int]       =   project_dim




class 					lowerCamelCase__				(							__lowercase):




	'''simple docstring'''




	_A								=	'altclip_vision_model'







	def __init__(   self						:Dict	,  a						:Optional[int]=7_6_8	,  a						:Union[str, Any]=3_0_7_2	,  a						:int=5_1_2	,  a						:Optional[Any]=1_2	,  a						:Dict=1_2	,  a						:Tuple=3	,  a						:Tuple=2_2_4	,  a						:Optional[int]=3_2	,  a						:str="quick_gelu"	,  a						:List[Any]=1E-5	,  a						:Optional[int]=0.0	,  a						:Any=0.02	,  a						:List[Any]=1.0	,  **a						:List[Any]	,  )						->					Dict:
								super().__init__(**a		)

								__UpperCamelCase      :  Optional[int]       =   hidden_size
								__UpperCamelCase      :  str       =   intermediate_size
								__UpperCamelCase      :  Optional[int]       =   projection_dim
								__UpperCamelCase      :  Union[str, Any]       =   num_hidden_layers
								__UpperCamelCase      :  Union[str, Any]       =   num_attention_heads
								__UpperCamelCase      :  List[Any]       =   num_channels
								__UpperCamelCase      :  Optional[Any]       =   patch_size
								__UpperCamelCase      :  Union[str, Any]       =   image_size
								__UpperCamelCase      :  Dict       =   initializer_range
								__UpperCamelCase      :  List[str]       =   initializer_factor
								__UpperCamelCase      :  List[Any]       =   attention_dropout
								__UpperCamelCase      :  Union[str, Any]       =   layer_norm_eps
								__UpperCamelCase      :  Optional[Any]       =   hidden_act







	@classmethod
	def   _lowerCamelCase							(   cls						:List[str]	,  a						:Union[str, os.PathLike]	,  **a						:Dict		)						->					"PretrainedConfig":
								cls._set_token_in_kwargs(a		)

								__UpperCamelCase  ,		__UpperCamelCase      :  Union[str, Any]       =   cls.get_config_dict(a	,  **a		)

								# get the vision config dict if we are loading from AltCLIPConfig
								if config_dict.get("model_type"		) == "altclip":
															__UpperCamelCase      :  List[str]       =   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__				(							__lowercase):




	'''simple docstring'''




	_A								=	'altclip'
	_A								=	True







	def __init__(   self						:Dict	,  a						:List[Any]=None	,  a						:List[Any]=None	,  a						:Optional[int]=7_6_8	,  a						:Optional[int]=2.6592	,  **a						:int		)						->					Optional[Any]:
								# If `_config_dict` exist, we use them for the backward compatibility.
								# We pop out these 2 attributes before calling `super().__init__` to avoid them being saved (which causes a lot
								# of confusion!).
								__UpperCamelCase      :  Union[str, Any]       =   kwargs.pop("text_config_dict"	,  a		)
								__UpperCamelCase      :  Union[str, Any]       =   kwargs.pop("vision_config_dict"	,  a		)

								super().__init__(**a		)

								# 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:
																						__UpperCamelCase      :  str       =   {}

															# This is the complete result when using `text_config_dict`.
															__UpperCamelCase      :  List[str]       =   AltCLIPTextConfig(**a		).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:
																																				__UpperCamelCase      :  Optional[int]       =   (
																																				    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:
																																				__UpperCamelCase      :  int       =   (
																																				    f'`text_config_dict` is provided which will be used to initialize `AltCLIPTextConfig`. The '
																																				    f'value `text_config["{key}"]` will be overriden.'
																																				)
																													logger.warning(a		)

            # 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:
																						__UpperCamelCase      :  List[Any]       =   {}

															# This is the complete result when using `vision_config_dict`.
															__UpperCamelCase      :  int       =   AltCLIPVisionConfig(**a		).to_dict()
															# convert keys to string instead of integer
															if "id2label" in _vision_config_dict:
																						__UpperCamelCase      :  Tuple       =   {
																						    str(a		): 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:
																																				__UpperCamelCase      :  Union[str, Any]       =   (
																																				    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:
																																				__UpperCamelCase      :  str       =   (
																																				    f'`vision_config_dict` is provided which will be used to initialize `AltCLIPVisionConfig`. '
																																				    f'The value `vision_config["{key}"]` will be overriden.'
																																				)
																													logger.warning(a		)

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

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

								if vision_config is None:
															__UpperCamelCase      :  Optional[int]       =   {}
															logger.info("`vision_config` is `None`. initializing the `AltCLIPVisionConfig` with default values."		)

								__UpperCamelCase      :  int       =   AltCLIPTextConfig(**a		)
								__UpperCamelCase      :  Any       =   AltCLIPVisionConfig(**a		)

								__UpperCamelCase      :  Any       =   projection_dim
								__UpperCamelCase      :  List[Any]       =   logit_scale_init_value
								__UpperCamelCase      :  List[str]       =   1.0







	@classmethod
	def   _lowerCamelCase							(   cls						:Dict	,  a						:AltCLIPTextConfig	,  a						:AltCLIPVisionConfig	,  **a						:Optional[int]		)						->					Dict:
								return cls(text_config=text_config.to_dict()	,  vision_config=vision_config.to_dict()	,  **a		)







	def   _lowerCamelCase							(   self						:List[str]		)						->					str:
								__UpperCamelCase      :  Any       =   copy.deepcopy(self.__dict__		)
								__UpperCamelCase      :  Any       =   self.text_config.to_dict()
								__UpperCamelCase      :  int       =   self.vision_config.to_dict()
								__UpperCamelCase      :  Optional[int]       =   self.__class__.model_type
								return output

from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


lowercase    :   Optional[int]						=			{
    'configuration_mobilevit': ['MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'MobileViTConfig', 'MobileViTOnnxConfig'],
}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase    :   List[str]						=			['MobileViTFeatureExtractor']
		lowercase    :   Tuple						=			['MobileViTImageProcessor']

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase    :   List[Any]						=			[
		    'MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'MobileViTForImageClassification',
		    'MobileViTForSemanticSegmentation',
		    'MobileViTModel',
		    'MobileViTPreTrainedModel',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		lowercase    :   List[Any]						=			[
		    'TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'TFMobileViTForImageClassification',
		    'TFMobileViTForSemanticSegmentation',
		    'TFMobileViTModel',
		    'TFMobileViTPreTrainedModel',
		]

if TYPE_CHECKING:
		from .configuration_mobilevit import MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP, MobileViTConfig, MobileViTOnnxConfig

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .feature_extraction_mobilevit import MobileViTFeatureExtractor
				from .image_processing_mobilevit import MobileViTImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_mobilevit import (
				    MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    MobileViTForImageClassification,
				    MobileViTForSemanticSegmentation,
				    MobileViTModel,
				    MobileViTPreTrainedModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_mobilevit import (
				    TF_MOBILEVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFMobileViTForImageClassification,
				    TFMobileViTForSemanticSegmentation,
				    TFMobileViTModel,
				    TFMobileViTPreTrainedModel,
				)


else:
		import sys

		lowercase    :   Optional[int]						=			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)