
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__							(     __a	):
				lowercase			    =  '''altclip_text_model'''






				def __init__(						self					:      List[Any]    ,     a					:      List[str]=250_002    ,     a					:      int=1_024    ,     a					:      Tuple=24    ,     a					:      Any=16    ,     a					:      Tuple=4_096    ,     a					:      Dict="gelu"    ,     a					:      List[str]=0.1    ,     a					:      List[str]=0.1    ,     a					:      List[Any]=514    ,     a					:      Any=1    ,     a					:      Any=0.0_2    ,     a					:      Optional[Any]=0.0_2    ,     a					:      Any=1E-05    ,     a					:      List[str]=1    ,     a					:      Optional[int]=0    ,     a					:      List[str]=2    ,     a					:      Any="absolute"    ,     a					:      Optional[Any]=True    ,     a					:      Optional[Any]=768    ,     **a					:      Tuple    ,     ):






							'''simple docstring'''







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

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







class      A__							(     __a	):
				lowercase			    =  '''altclip_vision_model'''






				def __init__(						self					:      str    ,     a					:      Any=768    ,     a					:      str=3_072    ,     a					:      Dict=512    ,     a					:      Tuple=12    ,     a					:      Union[str, Any]=12    ,     a					:      Union[str, Any]=3    ,     a					:      Union[str, Any]=224    ,     a					:      str=32    ,     a					:      Tuple="quick_gelu"    ,     a					:      Optional[Any]=1E-5    ,     a					:      Dict=0.0    ,     a					:      str=0.0_2    ,     a					:      Tuple=1.0    ,     **a					:      Dict    ,     ):






							'''simple docstring'''







							super().__init__(**__a   )

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






				@classmethod
				def 							_lowerCamelCase		(						cls					:      Tuple    ,     a					:      Union[str, os.PathLike]    ,     **a					:      str   ):






							'''simple docstring'''







							cls._set_token_in_kwargs(__a   )

							lowerCAmelCase__      :      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":
										lowerCAmelCase__      :      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      A__							(     __a	):
				lowercase			    =  '''altclip'''
				lowercase			    =  True






				def __init__(						self					:      List[str]    ,     a					:      Dict=None    ,     a					:      Optional[Any]=None    ,     a					:      List[Any]=768    ,     a					:      Union[str, Any]=2.6_5_9_2    ,     **a					:      Union[str, Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[Any]         =		kwargs.pop('text_config_dict'    ,     __a   )
							lowerCAmelCase__      :      Tuple         =		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:
													lowerCAmelCase__      :      Dict         =		{}

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

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

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

							lowerCAmelCase__      :      Any         =		AltCLIPTextConfig(**__a   )
							lowerCAmelCase__      :      int         =		AltCLIPVisionConfig(**__a   )

							lowerCAmelCase__      :      List[Any]         =		projection_dim
							lowerCAmelCase__      :      Dict         =		logit_scale_init_value
							lowerCAmelCase__      :      Optional[Any]         =		1.0






				@classmethod
				def 							_lowerCamelCase		(						cls					:      List[Any]    ,     a					:      AltCLIPTextConfig    ,     a					:      AltCLIPVisionConfig    ,     **a					:      Any   ):






							'''simple docstring'''







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






				def 							_lowerCamelCase		(						self					:      Optional[Any]   ):






							'''simple docstring'''







							lowerCAmelCase__      :      Optional[Any]         =		copy.deepcopy(self.__dict__   )
							lowerCAmelCase__      :      List[str]         =		self.text_config.to_dict()
							lowerCAmelCase__      :      Tuple         =		self.vision_config.to_dict()
							lowerCAmelCase__      :      Dict         =		self.__class__.model_type
							return output







import math

class 						lowerCAmelCase   :

					'''simple docstring'''

					def __init__(     self :		Tuple						,   __a :		int=0							)	->     Optional[Any]:  # a graph with Node 0,1,...,N-1


												"""simple docstring"""

												__lowercase					:							Any			=   n
												__lowercase					:							Optional[int]			=   [
												    [math.inf for j in range(0						,   __a							)] for i in range(0						,   __a							)
												]  # adjacency matrix for weight
												__lowercase					:							Dict			=   [
												    [math.inf for j in range(0						,   __a							)] for i in range(0						,   __a							)
												]  # dp[i][j] stores minimum distance from i to j



					def 					lowerCAmelCase (     self :		int						,   __a :		Optional[int]						,   __a :		Tuple						,   __a :		Dict							)	->     Dict:


												"""simple docstring"""

												__lowercase					:							Any			=   w



					def 					lowerCAmelCase (     self :		List[str]							)	->     Tuple:


												"""simple docstring"""

												for k in range(0						,   self.n							):
																			for i in range(0						,   self.n							):
																										for j in range(0						,   self.n							):
																																	__lowercase					:							List[str]			=   min(self.dp[i][j]						,   self.dp[i][k] + self.dp[k][j]							)



					def 					lowerCAmelCase (     self :		Any						,   __a :		Any						,   __a :		str							)	->     int:


												"""simple docstring"""

												return self.dp[u][v]


if __name__ == "__main__":
	lowerCamelCase       :       int        =				Graph(5)
	graph.add_edge(0, 2, 9)
	graph.add_edge(0, 4, 10)
	graph.add_edge(1, 3, 5)
	graph.add_edge(2, 3, 7)
	graph.add_edge(3, 0, 10)
	graph.add_edge(3, 1, 2)
	graph.add_edge(3, 2, 1)
	graph.add_edge(3, 4, 6)
	graph.add_edge(4, 1, 3)
	graph.add_edge(4, 2, 4)
	graph.add_edge(4, 3, 9)
	graph.floyd_warshall()
	graph.show_min(1, 4)
	graph.show_min(0, 3)