'''simple docstring'''




import argparse
import json
from pathlib import Path

import requests
import torch
from huggingface_hub import hf_hub_download
from PIL import Image

from transformers import (
    MobileViTConfig,
    MobileViTForImageClassification,
    MobileViTForSemanticSegmentation,
    MobileViTImageProcessor,
)
from transformers.utils import logging


logging.set_verbosity_info()
_lowercase						: str						=						logging.get_logger(__name__)




def 							lowerCamelCase	(      UpperCAmelCase__       :					Dict )			->      Dict:
							lowercase_					:			List[str]										=       MobileViTConfig()

							# size of the architecture
							if "mobilevit_s" in mobilevit_name:
														lowercase_					:			Optional[Any]										=       [144, 192, 240]
														lowercase_					:			int										=       [16, 32, 64, 96, 128, 160, 640]
							elif "mobilevit_xs" in mobilevit_name:
														lowercase_					:			Any										=       [96, 120, 144]
														lowercase_					:			Optional[Any]										=       [16, 32, 48, 64, 80, 96, 384]
							elif "mobilevit_xxs" in mobilevit_name:
														lowercase_					:			str										=       [64, 80, 96]
														lowercase_					:			Tuple										=       [16, 16, 24, 48, 64, 80, 320]
														lowercase_					:			Optional[Any]										=       0.05
														lowercase_					:			Tuple										=       2.0

							if mobilevit_name.startswith("""deeplabv3_""" ):
														lowercase_					:			List[str]										=       512
														lowercase_					:			List[str]										=       16
														lowercase_					:			Union[str, Any]										=       21
														lowercase_					:			Tuple										=       """pascal-voc-id2label.json"""
							else:
														lowercase_					:			int										=       1000
														lowercase_					:			Dict										=       """imagenet-1k-id2label.json"""

							lowercase_					:			Optional[int]										=       """huggingface/label-files"""
							lowercase_					:			List[Any]										=       json.load(open(hf_hub_download(UpperCAmelCase__      ,      UpperCAmelCase__      ,      repo_type="""dataset""" )      ,      """r""" ) )
							lowercase_					:			Optional[int]										=       {int(UpperCAmelCase__ ): v for k, v in idalabel.items()}
							lowercase_					:			Optional[int]										=       idalabel
							lowercase_					:			Any										=       {v: k for k, v in idalabel.items()}

							return config




def 							lowerCamelCase	(      UpperCAmelCase__       :					Union[str, Any]      ,      UpperCAmelCase__       :					Optional[Any]=False )			->      Dict:
							for i in range(1      ,      6 ):
														if F'''layer_{i}.''' in name:
																					lowercase_					:			Optional[Any]										=       name.replace(F'''layer_{i}.'''      ,      F'''encoder.layer.{i - 1}.''' )

							if "conv_1." in name:
														lowercase_					:			Optional[Any]										=       name.replace("""conv_1."""      ,      """conv_stem.""" )
							if ".block." in name:
														lowercase_					:			Tuple										=       name.replace(""".block."""      ,      """.""" )

							if "exp_1x1" in name:
														lowercase_					:			Union[str, Any]										=       name.replace("""exp_1x1"""      ,      """expand_1x1""" )
							if "red_1x1" in name:
														lowercase_					:			int										=       name.replace("""red_1x1"""      ,      """reduce_1x1""" )
							if ".local_rep.conv_3x3." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".local_rep.conv_3x3."""      ,      """.conv_kxk.""" )
							if ".local_rep.conv_1x1." in name:
														lowercase_					:			List[str]										=       name.replace(""".local_rep.conv_1x1."""      ,      """.conv_1x1.""" )
							if ".norm." in name:
														lowercase_					:			List[Any]										=       name.replace(""".norm."""      ,      """.normalization.""" )
							if ".conv." in name:
														lowercase_					:			Optional[int]										=       name.replace(""".conv."""      ,      """.convolution.""" )
							if ".conv_proj." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".conv_proj."""      ,      """.conv_projection.""" )

							for i in range(0      ,      2 ):
														for j in range(0      ,      4 ):
																					if F'''.{i}.{j}.''' in name:
																												lowercase_					:			Tuple										=       name.replace(F'''.{i}.{j}.'''      ,      F'''.{i}.layer.{j}.''' )

							for i in range(2      ,      6 ):
														for j in range(0      ,      4 ):
																					if F'''.{i}.{j}.''' in name:
																												lowercase_					:			Union[str, Any]										=       name.replace(F'''.{i}.{j}.'''      ,      F'''.{i}.''' )
																												if "expand_1x1" in name:
																																			lowercase_					:			int										=       name.replace("""expand_1x1"""      ,      """downsampling_layer.expand_1x1""" )
																												if "conv_3x3" in name:
																																			lowercase_					:			Optional[int]										=       name.replace("""conv_3x3"""      ,      """downsampling_layer.conv_3x3""" )
																												if "reduce_1x1" in name:
																																			lowercase_					:			str										=       name.replace("""reduce_1x1"""      ,      """downsampling_layer.reduce_1x1""" )

							for i in range(2      ,      5 ):
														if F'''.global_rep.{i}.weight''' in name:
																					lowercase_					:			Dict										=       name.replace(F'''.global_rep.{i}.weight'''      ,      """.layernorm.weight""" )
														if F'''.global_rep.{i}.bias''' in name:
																					lowercase_					:			Tuple										=       name.replace(F'''.global_rep.{i}.bias'''      ,      """.layernorm.bias""" )

							if ".global_rep." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".global_rep."""      ,      """.transformer.""" )
							if ".pre_norm_mha.0." in name:
														lowercase_					:			Tuple										=       name.replace(""".pre_norm_mha.0."""      ,      """.layernorm_before.""" )
							if ".pre_norm_mha.1.out_proj." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".pre_norm_mha.1.out_proj."""      ,      """.attention.output.dense.""" )
							if ".pre_norm_ffn.0." in name:
														lowercase_					:			Optional[int]										=       name.replace(""".pre_norm_ffn.0."""      ,      """.layernorm_after.""" )
							if ".pre_norm_ffn.1." in name:
														lowercase_					:			List[Any]										=       name.replace(""".pre_norm_ffn.1."""      ,      """.intermediate.dense.""" )
							if ".pre_norm_ffn.4." in name:
														lowercase_					:			int										=       name.replace(""".pre_norm_ffn.4."""      ,      """.output.dense.""" )
							if ".transformer." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".transformer."""      ,      """.transformer.layer.""" )

							if ".aspp_layer." in name:
														lowercase_					:			Union[str, Any]										=       name.replace(""".aspp_layer."""      ,      """.""" )
							if ".aspp_pool." in name:
														lowercase_					:			List[Any]										=       name.replace(""".aspp_pool."""      ,      """.""" )
							if "seg_head." in name:
														lowercase_					:			str										=       name.replace("""seg_head."""      ,      """segmentation_head.""" )
							if "segmentation_head.classifier.classifier." in name:
														lowercase_					:			str										=       name.replace("""segmentation_head.classifier.classifier."""      ,      """segmentation_head.classifier.""" )

							if "classifier.fc." in name:
														lowercase_					:			Union[str, Any]										=       name.replace("""classifier.fc."""      ,      """classifier.""" )
							elif (not base_model) and ("segmentation_head." not in name):
														lowercase_					:			Optional[int]										=       """mobilevit.""" + name

							return name




def 							lowerCamelCase	(      UpperCAmelCase__       :					Optional[Any]      ,      UpperCAmelCase__       :					str      ,      UpperCAmelCase__       :					Any=False )			->      Union[str, Any]:
							if base_model:
														lowercase_					:			List[Any]										=       """"""
							else:
														lowercase_					:			List[Any]										=       """mobilevit."""

							for key in orig_state_dict.copy().keys():
														lowercase_					:			Any										=       orig_state_dict.pop(UpperCAmelCase__ )

														if key[:8] == "encoder.":
																					lowercase_					:			Any										=       key[8:]

														if "qkv" in key:
																					lowercase_					:			Tuple										=       key.split(""".""" )
																					lowercase_					:			Any										=       int(key_split[0][6:] ) - 1
																					lowercase_					:			Optional[int]										=       int(key_split[3] )
																					lowercase_					:			Any										=       model.get_submodule(F'''{model_prefix}encoder.layer.{layer_num}''' )
																					lowercase_					:			int										=       layer.transformer.layer[transformer_num].attention.attention.all_head_size
																					lowercase_					:			str										=       (
																					    F'''{model_prefix}encoder.layer.{layer_num}.transformer.layer.{transformer_num}.attention.attention.'''
																					)
																					if "weight" in key:
																												lowercase_					:			Optional[Any]										=       val[:dim, :]
																												lowercase_					:			int										=       val[dim : dim * 2, :]
																												lowercase_					:			Optional[int]										=       val[-dim:, :]
																					else:
																												lowercase_					:			Any										=       val[:dim]
																												lowercase_					:			Dict										=       val[dim : dim * 2]
																												lowercase_					:			Dict										=       val[-dim:]
														else:
																					lowercase_					:			Optional[int]										=       val

							return orig_state_dict




def 							lowerCamelCase	(      )			->      Optional[Any]:
							lowercase_					:			Tuple										=       """http://images.cocodataset.org/val2017/000000039769.jpg"""
							lowercase_					:			Union[str, Any]										=       Image.open(requests.get(UpperCAmelCase__      ,      stream=UpperCAmelCase__ ).raw )
							return im




@torch.no_grad()
def 							lowerCamelCase	(      UpperCAmelCase__       :					List[str]      ,      UpperCAmelCase__       :					Tuple      ,      UpperCAmelCase__       :					Optional[int]      ,      UpperCAmelCase__       :					Dict=False )			->      int:
							lowercase_					:			int										=       get_mobilevit_config(UpperCAmelCase__ )

							# load original state_dict
							lowercase_					:			List[Any]										=       torch.load(UpperCAmelCase__      ,      map_location="""cpu""" )

							# load 🤗 model
							if mobilevit_name.startswith("""deeplabv3_""" ):
														lowercase_					:			str										=       MobileViTForSemanticSegmentation(UpperCAmelCase__ ).eval()
							else:
														lowercase_					:			Union[str, Any]										=       MobileViTForImageClassification(UpperCAmelCase__ ).eval()

							lowercase_					:			List[Any]										=       convert_state_dict(UpperCAmelCase__      ,      UpperCAmelCase__ )
							model.load_state_dict(UpperCAmelCase__ )

							# Check outputs on an image, prepared by MobileViTImageProcessor
							lowercase_					:			int										=       MobileViTImageProcessor(crop_size=config.image_size      ,      size=config.image_size + 32 )
							lowercase_					:			Dict										=       image_processor(images=prepare_img()      ,      return_tensors="""pt""" )
							lowercase_					:			int										=       model(**UpperCAmelCase__ )
							lowercase_					:			Tuple										=       outputs.logits

							if mobilevit_name.startswith("""deeplabv3_""" ):
														assert logits.shape == (1, 21, 32, 32)

														if mobilevit_name == "deeplabv3_mobilevit_s":
																					lowercase_					:			Optional[int]										=       torch.tensor(
																					    [
																					        [[6.2065, 6.1292, 6.2070], [6.1079, 6.1254, 6.1747], [6.0042, 6.1071, 6.1034]],
																					        [[-6.9253, -6.8653, -7.0398], [-7.3218, -7.3983, -7.3670], [-7.1961, -7.2482, -7.1569]],
																					        [[-4.4723, -4.4348, -4.3769], [-5.3629, -5.4632, -5.4598], [-5.1587, -5.3402, -5.5059]],
																					    ] )
														elif mobilevit_name == "deeplabv3_mobilevit_xs":
																					lowercase_					:			List[str]										=       torch.tensor(
																					    [
																					        [[5.4449, 5.5733, 5.6314], [5.1815, 5.3930, 5.5963], [5.1656, 5.4333, 5.4853]],
																					        [[-9.4423, -9.7766, -9.6714], [-9.1581, -9.5720, -9.5519], [-9.1006, -9.6458, -9.5703]],
																					        [[-7.7721, -7.3716, -7.1583], [-8.4599, -8.0624, -7.7944], [-8.4172, -7.8366, -7.5025]],
																					    ] )
														elif mobilevit_name == "deeplabv3_mobilevit_xxs":
																					lowercase_					:			Dict										=       torch.tensor(
																					    [
																					        [[6.9811, 6.9743, 7.3123], [7.1777, 7.1931, 7.3938], [7.5633, 7.8050, 7.8901]],
																					        [[-10.5536, -10.2332, -10.2924], [-10.2336, -9.8624, -9.5964], [-10.8840, -10.8158, -10.6659]],
																					        [[-3.4938, -3.0631, -2.8620], [-3.4205, -2.8135, -2.6875], [-3.4179, -2.7945, -2.8750]],
																					    ] )
														else:
																					raise ValueError(F'''Unknown mobilevit_name: {mobilevit_name}''' )

														assert torch.allclose(logits[0, :3, :3, :3]      ,      UpperCAmelCase__      ,      atol=1e-4 )
							else:
														assert logits.shape == (1, 1000)

														if mobilevit_name == "mobilevit_s":
																					lowercase_					:			Optional[Any]										=       torch.tensor([-0.9866, 0.2392, -1.1241] )
														elif mobilevit_name == "mobilevit_xs":
																					lowercase_					:			str										=       torch.tensor([-2.4761, -0.9399, -1.9587] )
														elif mobilevit_name == "mobilevit_xxs":
																					lowercase_					:			Union[str, Any]										=       torch.tensor([-1.9364, -1.2327, -0.4653] )
														else:
																					raise ValueError(F'''Unknown mobilevit_name: {mobilevit_name}''' )

														assert torch.allclose(logits[0, :3]      ,      UpperCAmelCase__      ,      atol=1e-4 )

							Path(UpperCAmelCase__ ).mkdir(exist_ok=UpperCAmelCase__ )
							print(F'''Saving model {mobilevit_name} to {pytorch_dump_folder_path}''' )
							model.save_pretrained(UpperCAmelCase__ )
							print(F'''Saving image processor to {pytorch_dump_folder_path}''' )
							image_processor.save_pretrained(UpperCAmelCase__ )

							if push_to_hub:
														lowercase_					:			List[Any]										=       {
														    """mobilevit_s""": """mobilevit-small""",
														    """mobilevit_xs""": """mobilevit-x-small""",
														    """mobilevit_xxs""": """mobilevit-xx-small""",
														    """deeplabv3_mobilevit_s""": """deeplabv3-mobilevit-small""",
														    """deeplabv3_mobilevit_xs""": """deeplabv3-mobilevit-x-small""",
														    """deeplabv3_mobilevit_xxs""": """deeplabv3-mobilevit-xx-small""",
														}

														print("""Pushing to the hub...""" )
														lowercase_					:			int										=       model_mapping[mobilevit_name]
														image_processor.push_to_hub(UpperCAmelCase__      ,      organization="""apple""" )
														model.push_to_hub(UpperCAmelCase__      ,      organization="""apple""" )


if __name__ == "__main__":
						_lowercase						: str						=						argparse.ArgumentParser()
						# Required parameters
						parser.add_argument(
						    "--mobilevit_name",
						    default="mobilevit_s",
						    type=str,
						    help=(
						        "Name of the MobileViT model you'd like to convert. Should be one of 'mobilevit_s', 'mobilevit_xs',"
						        " 'mobilevit_xxs', 'deeplabv3_mobilevit_s', 'deeplabv3_mobilevit_xs', 'deeplabv3_mobilevit_xxs'."
						    ),
						)
						parser.add_argument(
						    "--checkpoint_path", required=True, type=str, help="Path to the original state dict (.pt file)."
						)
						parser.add_argument(
						    "--pytorch_dump_folder_path", required=True, type=str, help="Path to the output PyTorch model directory."
						)
						parser.add_argument(
						    "--push_to_hub", action="store_true", help="Whether or not to push the converted model to the 🤗 hub."
						)

						_lowercase						: Dict						=						parser.parse_args()
						convert_movilevit_checkpoint(
						    args.mobilevit_name, args.checkpoint_path, args.pytorch_dump_folder_path, args.push_to_hub
						)






'''simple docstring'''




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						: Tuple						=						{
    "BAAI/AltCLIP": "https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json",
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}





class     __magic_name__						(    _UpperCAmelCase):
			UpperCamelCase__				=       '''altclip_text_model'''







			def __init__(	self				:  Union[str, Any]				,			lowercase_				:  str=250002				,			lowercase_				:  Union[str, Any]=1024				,			lowercase_				:  Any=24				,			lowercase_				:  Union[str, Any]=16				,			lowercase_				:  Any=4096				,			lowercase_				:  Union[str, Any]="gelu"				,			lowercase_				:  Union[str, Any]=0.1				,			lowercase_				:  Union[str, Any]=0.1				,			lowercase_				:  int=514				,			lowercase_				:  Union[str, Any]=1				,			lowercase_				:  List[str]=0.02				,			lowercase_				:  Optional[int]=0.02				,			lowercase_				:  str=1E-05				,			lowercase_				:  List[str]=1				,			lowercase_				:  List[Any]=0				,			lowercase_				:  Dict=2				,			lowercase_				:  Union[str, Any]="absolute"				,			lowercase_				:  Any=True				,			lowercase_				:  Union[str, Any]=768				,			**lowercase_				:  Any				,			):
										super().__init__(pad_token_id=lowercase_				,			bos_token_id=lowercase_				,			eos_token_id=lowercase_				,			**lowercase_    )

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





class     __magic_name__						(    _UpperCAmelCase):
			UpperCamelCase__				=       '''altclip_vision_model'''







			def __init__(	self				:  Dict				,			lowercase_				:  Any=768				,			lowercase_				:  Dict=3072				,			lowercase_				:  Optional[Any]=512				,			lowercase_				:  Dict=12				,			lowercase_				:  Optional[int]=12				,			lowercase_				:  Optional[Any]=3				,			lowercase_				:  str=224				,			lowercase_				:  List[Any]=32				,			lowercase_				:  Union[str, Any]="quick_gelu"				,			lowercase_				:  Dict=1E-5				,			lowercase_				:  Optional[int]=0.0				,			lowercase_				:  Optional[Any]=0.02				,			lowercase_				:  Optional[Any]=1.0				,			**lowercase_				:  Dict				,			):
										super().__init__(**lowercase_    )

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







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

										lowercase_						,						lowercase_					:			str										=       cls.get_config_dict(lowercase_				,			**lowercase_    )

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





class     __magic_name__						(    _UpperCAmelCase):
			UpperCamelCase__				=       '''altclip'''
			UpperCamelCase__				=       True







			def __init__(	self				:  Optional[int]				,			lowercase_				:  Dict=None				,			lowercase_				:  List[Any]=None				,			lowercase_				:  Tuple=768				,			lowercase_				:  List[str]=2.65_92				,			**lowercase_				:  List[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!).
										lowercase_					:			Dict										=       kwargs.pop("""text_config_dict"""				,			lowercase_    )
										lowercase_					:			str										=       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:
																								lowercase_					:			Dict										=       {}

																	# This is the complete result when using `text_config_dict`.
																	lowercase_					:			List[str]										=       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:
																																						lowercase_					:			Optional[Any]										=       (
																																						    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:
																																						lowercase_					:			Tuple										=       (
																																						    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:
																								lowercase_					:			int										=       {}

																	# This is the complete result when using `vision_config_dict`.
																	lowercase_					:			List[str]										=       AltCLIPVisionConfig(**lowercase_    ).to_dict()
																	# convert keys to string instead of integer
																	if "id2label" in _vision_config_dict:
																								lowercase_					:			List[str]										=       {
																								    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:
																																						lowercase_					:			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:
																																						lowercase_					:			List[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(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:
																	lowercase_					:			int										=       {}
																	logger.info("""`text_config` is `None`. Initializing the `AltCLIPTextConfig` with default values."""    )

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

										lowercase_					:			Optional[int]										=       AltCLIPTextConfig(**lowercase_    )
										lowercase_					:			Any										=       AltCLIPVisionConfig(**lowercase_    )

										lowercase_					:			List[Any]										=       projection_dim
										lowercase_					:			Optional[Any]										=       logit_scale_init_value
										lowercase_					:			int										=       1.0







			@classmethod
			def 	SCREAMING_SNAKE_CASE_     (	cls				:  Dict				,			lowercase_				:  AltCLIPTextConfig				,			lowercase_				:  AltCLIPVisionConfig				,			**lowercase_				:  Optional[int]    ):
										return cls(text_config=text_config.to_dict()				,			vision_config=vision_config.to_dict()				,			**lowercase_    )







			def 	SCREAMING_SNAKE_CASE_     (	self				:  Optional[int]    ):
										lowercase_					:			Union[str, Any]										=       copy.deepcopy(self.__dict__    )
										lowercase_					:			Optional[int]										=       self.text_config.to_dict()
										lowercase_					:			Any										=       self.vision_config.to_dict()
										lowercase_					:			List[str]										=       self.__class__.model_type
										return output





