
import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
   pass

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


lowercase_ 				=			logging.get_logger(__name__)

lowercase_ 				=			{
    """kakaobrain/align-base""": """https://huggingface.co/kakaobrain/align-base/resolve/main/config.json""",
}





class     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''align_text_model'''



     def __init__(				self							:							Optional[int]     ,						_A							:							Union[str, Any]=3_0522     ,						_A							:							List[str]=768     ,						_A							:							List[Any]=12     ,						_A							:							int=12     ,						_A							:							str=3072     ,						_A							:							Optional[Any]="gelu"     ,						_A							:							Union[str, Any]=0.1     ,						_A							:							List[str]=0.1     ,						_A							:							List[str]=512     ,						_A							:							Union[str, Any]=2     ,						_A							:							Optional[int]=0.02     ,						_A							:							Optional[int]=1e-12     ,						_A							:							List[str]=0     ,						_A							:							Optional[Any]="absolute"     ,						_A							:							Tuple=True     ,						**_A							:							str     ,						):







       """simple docstring"""




       super().__init__(**_A )

       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		vocab_size
       __SCREAMING_SNAKE_CASE      :	Dict					=		hidden_size
       __SCREAMING_SNAKE_CASE      :	str					=		num_hidden_layers
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		num_attention_heads
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		hidden_act
       __SCREAMING_SNAKE_CASE      :	Any					=		intermediate_size
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		hidden_dropout_prob
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		attention_probs_dropout_prob
       __SCREAMING_SNAKE_CASE      :	int					=		max_position_embeddings
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		type_vocab_size
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		initializer_range
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		layer_norm_eps
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		position_embedding_type
       __SCREAMING_SNAKE_CASE      :	Tuple					=		use_cache
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		pad_token_id




     @classmethod
     def  UpperCAmelCase__							(				cls							:							int     ,						_A							:							Union[str, os.PathLike]     ,						**_A							:							Union[str, Any] ):







       """simple docstring"""




       cls._set_token_in_kwargs(_A )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Dict					=		cls.get_config_dict(_A     ,						**_A )

       # get the text config dict if we are loading from AlignConfig
       if config_dict.get('''model_type''' ) == "align":
         __SCREAMING_SNAKE_CASE      :	str					=		config_dict['''text_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     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''align_vision_model'''



     def __init__(				self							:							Dict     ,						_A							:							int = 3     ,						_A							:							int = 600     ,						_A							:							float = 2.0     ,						_A							:							float = 3.1     ,						_A							:							int = 8     ,						_A							:							List[int] = [3, 3, 5, 3, 5, 5, 3]     ,						_A							:							List[int] = [32, 16, 24, 40, 80, 112, 192]     ,						_A							:							List[int] = [16, 24, 40, 80, 112, 192, 320]     ,						_A							:							List[int] = []     ,						_A							:							List[int] = [1, 2, 2, 2, 1, 2, 1]     ,						_A							:							List[int] = [1, 2, 2, 3, 3, 4, 1]     ,						_A							:							List[int] = [1, 6, 6, 6, 6, 6, 6]     ,						_A							:							float = 0.25     ,						_A							:							str = "swish"     ,						_A							:							int = 2560     ,						_A							:							str = "mean"     ,						_A							:							float = 0.02     ,						_A							:							float = 0.0_01     ,						_A							:							float = 0.99     ,						_A							:							float = 0.2     ,						**_A							:							Optional[Any]     ,						):







       """simple docstring"""




       super().__init__(**_A )

       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		num_channels
       __SCREAMING_SNAKE_CASE      :	Tuple					=		image_size
       __SCREAMING_SNAKE_CASE      :	Any					=		width_coefficient
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		depth_coefficient
       __SCREAMING_SNAKE_CASE      :	Tuple					=		depth_divisor
       __SCREAMING_SNAKE_CASE      :	Any					=		kernel_sizes
       __SCREAMING_SNAKE_CASE      :	Tuple					=		in_channels
       __SCREAMING_SNAKE_CASE      :	str					=		out_channels
       __SCREAMING_SNAKE_CASE      :	str					=		depthwise_padding
       __SCREAMING_SNAKE_CASE      :	List[Any]					=		strides
       __SCREAMING_SNAKE_CASE      :	List[str]					=		num_block_repeats
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		expand_ratios
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		squeeze_expansion_ratio
       __SCREAMING_SNAKE_CASE      :	int					=		hidden_act
       __SCREAMING_SNAKE_CASE      :	str					=		hidden_dim
       __SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		pooling_type
       __SCREAMING_SNAKE_CASE      :	Any					=		initializer_range
       __SCREAMING_SNAKE_CASE      :	int					=		batch_norm_eps
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		batch_norm_momentum
       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		drop_connect_rate
       __SCREAMING_SNAKE_CASE      :	Optional[Any]					=		sum(_A ) * 4




     @classmethod
     def  UpperCAmelCase__							(				cls							:							Any     ,						_A							:							Union[str, os.PathLike]     ,						**_A							:							Optional[Any] ):







       """simple docstring"""




       cls._set_token_in_kwargs(_A )

       __SCREAMING_SNAKE_CASE,		__SCREAMING_SNAKE_CASE      :	Union[str, Any]					=		cls.get_config_dict(_A     ,						**_A )

       # get the vision config dict if we are loading from AlignConfig
       if config_dict.get('''model_type''' ) == "align":
         __SCREAMING_SNAKE_CASE      :	List[Any]					=		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     __UpperCamelCase (							lowerCAmelCase__       ):






     """simple docstring"""







     lowerCAmelCase_							   =			'''align'''
     lowerCAmelCase_							   =			True



     def __init__(				self							:							str     ,						_A							:							Optional[int]=None     ,						_A							:							Optional[int]=None     ,						_A							:							Dict=640     ,						_A							:							int=1.0     ,						_A							:							Any=0.02     ,						**_A							:							int     ,						):







       """simple docstring"""




       super().__init__(**_A )

       if text_config is None:
         __SCREAMING_SNAKE_CASE      :	Dict					=		{}
         logger.info('''text_config is None. Initializing the AlignTextConfig with default values.''' )

       if vision_config is None:
         __SCREAMING_SNAKE_CASE      :	Any					=		{}
         logger.info('''vision_config is None. Initializing the AlignVisionConfig with default values.''' )

       __SCREAMING_SNAKE_CASE      :	Tuple					=		AlignTextConfig(**_A )
       __SCREAMING_SNAKE_CASE      :	int					=		AlignVisionConfig(**_A )

       __SCREAMING_SNAKE_CASE      :	Optional[int]					=		projection_dim
       __SCREAMING_SNAKE_CASE      :	str					=		temperature_init_value
       __SCREAMING_SNAKE_CASE      :	Any					=		initializer_range



     @classmethod
     def  UpperCAmelCase__							(				cls							:							Dict     ,						_A							:							AlignTextConfig     ,						_A							:							AlignVisionConfig     ,						**_A							:							str ):







       """simple docstring"""




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




     def  UpperCAmelCase__							(				self							:							str ):







       """simple docstring"""




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

from __future__ import annotations

from collections import deque
from collections.abc import Iterator
from dataclasses import dataclass





@dataclass
class     lowerCAmelCase__     :


		'''simple docstring'''






		lowerCAmelCase_     =   42
		lowerCAmelCase_     =   42





class     lowerCAmelCase__     :


		'''simple docstring'''






		def __init__(       self     :     int     ,  snake_case__     :     int		)      ->	Any:
				_lowerCamelCase				   =  [[] for _ in range(snake_case__		)]
				_lowerCamelCase				   =  size
		def __getitem__(       self     :     Dict     ,  snake_case__     :     int		)      ->	Iterator[Edge]:
				return iter(self._graph[vertex]		)
		@property
		def   _snake_case       (       self     :     str		)      ->	int:
				return self._size
		def   _snake_case       (       self     :     List[Any]     ,  snake_case__     :     int     ,  snake_case__     :     int     ,  snake_case__     :     int		)      ->	Tuple:
				if weight not in (0, 1):
						raise ValueError('Edge weight must be either 0 or 1.'		)

				if to_vertex < 0 or to_vertex >= self.size:
						raise ValueError('Vertex indexes must be in [0; size).'		)

				self._graph[from_vertex].append(Edge(snake_case__     ,  snake_case__		)		)



		def   _snake_case       (       self     :     Dict     ,  snake_case__     :     int     ,  snake_case__     :     int		)      ->	int | None:
				_lowerCamelCase				   =  deque([start_vertex]		)
				_lowerCamelCase				   =  [None] * self.size
				_lowerCamelCase				   =  0

				while queue:
						_lowerCamelCase				   =  queue.popleft()
						_lowerCamelCase				   =  distances[current_vertex]
						if current_distance is None:
								continue

						for edge in self[current_vertex]:
								_lowerCamelCase				   =  current_distance + edge.weight
								_lowerCamelCase				   =  distances[edge.destination_vertex]
								if (
								    isinstance(snake_case__     ,  snake_case__		)
								    and new_distance >= dest_vertex_distance
								):
										continue
								_lowerCamelCase				   =  new_distance
								if edge.weight == 0:
										queue.appendleft(edge.destination_vertex		)
								else:
										queue.append(edge.destination_vertex		)

				if distances[finish_vertex] is None:
						raise ValueError('No path from start_vertex to finish_vertex.'		)

				return distances[finish_vertex]


if __name__ == "__main__":
				import doctest

				doctest.testmod()