






'''simple docstring'''


import copy
import os
from typing import Union

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


lowerCamelCase_				: Union[str, Any]    	=							logging.get_logger(__name__)

lowerCamelCase_				: Optional[Any]    	=							{
    '''BAAI/AltCLIP''': '''https://huggingface.co/BAAI/AltCLIP/resolve/main/config.json''',
    # See all AltCLIP models at https://huggingface.co/models?filter=altclip
}
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							Union[str, Any]					     =					"altclip_text_model"






			def __init__(   self							:						Optional[Any] ,      lowercase							:						List[Any]=2_5_0_0_0_2 ,      lowercase							:						Dict=1_0_2_4 ,      lowercase							:						Tuple=2_4 ,      lowercase							:						Dict=1_6 ,      lowercase							:						str=4_0_9_6 ,      lowercase							:						int="gelu" ,      lowercase							:						Optional[Any]=0.1 ,      lowercase							:						Any=0.1 ,      lowercase							:						str=5_1_4 ,      lowercase							:						Optional[Any]=1 ,      lowercase							:						Optional[Any]=0.0_2 ,      lowercase							:						int=0.0_2 ,      lowercase							:						Union[str, Any]=1e-05 ,      lowercase							:						Tuple=1 ,      lowercase							:						Optional[int]=0 ,      lowercase							:						str=2 ,      lowercase							:						List[Any]="absolute" ,      lowercase							:						str=True ,      lowercase							:						Union[str, Any]=7_6_8 ,      **lowercase							:						Any ,      )							->    Union[str, Any]:

									'''simple docstring'''







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

									UpperCamelCase__         = vocab_size
									UpperCamelCase__         = hidden_size
									UpperCamelCase__         = num_hidden_layers
									UpperCamelCase__         = num_attention_heads
									UpperCamelCase__         = hidden_act
									UpperCamelCase__         = intermediate_size
									UpperCamelCase__         = hidden_dropout_prob
									UpperCamelCase__         = attention_probs_dropout_prob
									UpperCamelCase__         = max_position_embeddings
									UpperCamelCase__         = type_vocab_size
									UpperCamelCase__         = initializer_range
									UpperCamelCase__         = initializer_factor
									UpperCamelCase__         = layer_norm_eps
									UpperCamelCase__         = position_embedding_type
									UpperCamelCase__         = use_cache
									UpperCamelCase__         = project_dim
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			__a							:							Union[str, Any]					     =					"altclip_vision_model"






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

									'''simple docstring'''







									super().__init__(**lowercase			)

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







			@classmethod
			def 				A      (   cls							:						str ,      lowercase							:						Union[str, os.PathLike] ,      **lowercase							:						Any			)							->    "PretrainedConfig":

									'''simple docstring'''







									cls._set_token_in_kwargs(lowercase			)

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

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


			'''simple docstring'''





			__a							:							str					     =					"altclip"
			__a							:							Dict					     =					True






			def __init__(   self							:						List[Any] ,      lowercase							:						Union[str, Any]=None ,      lowercase							:						str=None ,      lowercase							:						List[str]=7_6_8 ,      lowercase							:						List[str]=2.6_5_9_2 ,      **lowercase							:						List[Any]			)							->    List[Any]:

									'''simple docstring'''







									UpperCamelCase__         = kwargs.pop("""text_config_dict""" ,      lowercase			)
									UpperCamelCase__         = 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:
																					UpperCamelCase__         = {}

															# This is the complete result when using `text_config_dict`.
															UpperCamelCase__         = 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:
																																	UpperCamelCase__         = (
																																	    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__         = (
																																	    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:
																					UpperCamelCase__         = {}

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

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

									UpperCamelCase__         = AltCLIPTextConfig(**lowercase			)
									UpperCamelCase__         = AltCLIPVisionConfig(**lowercase			)

									UpperCamelCase__         = projection_dim
									UpperCamelCase__         = logit_scale_init_value
									UpperCamelCase__         = 1.0






			@classmethod
			def 				A      (   cls							:						Dict ,      lowercase							:						AltCLIPTextConfig ,      lowercase							:						AltCLIPVisionConfig ,      **lowercase							:						Union[str, Any]			)							->    Optional[Any]:

									'''simple docstring'''







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







			def 				A      (   self							:						List[Any]			)							->    Optional[Any]:

									'''simple docstring'''







									UpperCamelCase__         = copy.deepcopy(self.__dict__			)
									UpperCamelCase__         = self.text_config.to_dict()
									UpperCamelCase__         = self.vision_config.to_dict()
									UpperCamelCase__         = self.__class__.model_type
									return output








'''simple docstring'''


from __future__ import annotations

from typing import Any
class    _SCREAMING_SNAKE_CASE							:


			'''simple docstring'''





			def __init__(   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									UpperCamelCase__         = num_of_nodes
									UpperCamelCase__         = []
									UpperCamelCase__         = {}






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						int ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									self.m_edges.append([u_node, v_node, weight]			)






			def 				A      (   self							:						str ,      lowercase							:						int			)							->    int:

									'''simple docstring'''







									if self.m_component[u_node] == u_node:
															return u_node
									return self.find_component(self.m_component[u_node]			)






			def 				A      (   self							:						Union[str, Any] ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									if self.m_component[u_node] != u_node:
															for k in self.m_component:
																					UpperCamelCase__         = self.find_component(lowercase			)






			def 				A      (   self							:						Tuple ,      lowercase							:						list[int] ,      lowercase							:						int ,      lowercase							:						int			)							->    None:

									'''simple docstring'''







									if component_size[u_node] <= component_size[v_node]:
															UpperCamelCase__         = v_node
															component_size[v_node] += component_size[u_node]
															self.set_component(lowercase			)

									elif component_size[u_node] >= component_size[v_node]:
															UpperCamelCase__         = self.find_component(lowercase			)
															component_size[u_node] += component_size[v_node]
															self.set_component(lowercase			)







			def 				A      (   self							:						int			)							->    None:

									'''simple docstring'''







									UpperCamelCase__         = []
									UpperCamelCase__         = 0

									UpperCamelCase__         = [-1] * self.m_num_of_nodes

									# A list of components (initialized to all of the nodes)
									for node in range(self.m_num_of_nodes			):
															self.m_component.update({node: node}			)
															component_size.append(1			)

									UpperCamelCase__         = self.m_num_of_nodes

									while num_of_components > 1:
															for edge in self.m_edges:
																					UpperCamelCase__    ,   UpperCamelCase__    ,   UpperCamelCase__         = edge

																					UpperCamelCase__         = self.m_component[u]
																					UpperCamelCase__         = self.m_component[v]

																					if u_component != v_component:

																											for component in (u_component, v_component):
																																	if (
																																	    minimum_weight_edge[component] == -1
																																	    or minimum_weight_edge[component][2] > w
																																	):
																																							UpperCamelCase__         = [u, v, w]

															for edge in minimum_weight_edge:
																					if isinstance(lowercase ,      lowercase			):
																											UpperCamelCase__    ,   UpperCamelCase__    ,   UpperCamelCase__         = edge

																											UpperCamelCase__         = self.m_component[u]
																											UpperCamelCase__         = self.m_component[v]

																											if u_component != v_component:
																																	mst_weight += w
																																	self.union(lowercase ,      lowercase ,      lowercase			)
																																	print(f"Added edge [{u} - {v}]\nAdded weight: {w}\n"			)
																																	num_of_components -= 1

															UpperCamelCase__         = [-1] * self.m_num_of_nodes
									print(f"The total weight of the minimal spanning tree is: {mst_weight}"			)







def 	__magic_name__( ):
						'''simple docstring'''







if __name__ == "__main__":
					import doctest

					doctest.testmod()
