
"""simple docstring"""






class 			lowercase					:






			def __init__(self  :	Union[str, Any]			)       ->	List[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  0
				lowerCAmelCase												=  0
				lowerCAmelCase												=  {}






			def 					UpperCAmelCase							(self  :	Optional[Any]      ,SCREAMING_SNAKE_CASE_  :	Tuple			)       ->	Optional[int]:





				"""simple docstring"""


				if vertex not in self.adjacency:
					lowerCAmelCase												=  {}
					self.num_vertices += 1






			def 					UpperCAmelCase							(self  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Any      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	Tuple:





				"""simple docstring"""


				self.add_vertex(SCREAMING_SNAKE_CASE_			)
				self.add_vertex(SCREAMING_SNAKE_CASE_			)

				if head == tail:
					return

				lowerCAmelCase												=  weight
				lowerCAmelCase												=  weight






			def 					UpperCAmelCase							(self  :	Any			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  self.get_edges()
				for edge in edges:
					lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase												=  edge
					edges.remove((tail, head, weight)			)
				for i in range(len(SCREAMING_SNAKE_CASE_			)			):
					lowerCAmelCase												=  list(edges[i]			)

				edges.sort(key=lambda SCREAMING_SNAKE_CASE_			: e[2]			)
				for i in range(len(SCREAMING_SNAKE_CASE_			) - 1			):
					if edges[i][2] >= edges[i + 1][2]:
						lowerCAmelCase												=  edges[i][2] + 1
				for edge in edges:
					lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase												=  edge
					lowerCAmelCase												=  weight
					lowerCAmelCase												=  weight






			def __str__(self  :	Dict			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  ''''''
				for tail in self.adjacency:
					for head in self.adjacency[tail]:
						lowerCAmelCase												=  self.adjacency[head][tail]
						string += F"""{head} -> {tail} == {weight}\n"""
				return string.rstrip('''\n'''			)






			def 					UpperCAmelCase							(self  :	Tuple			)       ->	Optional[Any]:





				"""simple docstring"""


				lowerCAmelCase												=  []
				for tail in self.adjacency:
					for head in self.adjacency[tail]:
						output.append((tail, head, self.adjacency[head][tail])			)
				return output






			def 					UpperCAmelCase							(self  :	List[str]			)       ->	Union[str, Any]:





				"""simple docstring"""


				return self.adjacency.keys()






			@staticmethod
			def 					UpperCAmelCase							(SCREAMING_SNAKE_CASE_  :	Any=None      ,SCREAMING_SNAKE_CASE_  :	List[Any]=None			)       ->	str:





				"""simple docstring"""


				lowerCAmelCase												=  Graph()
				if vertices is None:
					lowerCAmelCase												=  []
				if edges is None:
					lowerCAmelCase												=  []
				for vertex in vertices:
					g.add_vertex(SCREAMING_SNAKE_CASE_			)
				for edge in edges:
					g.add_edge(*SCREAMING_SNAKE_CASE_			)
				return g



			class 			lowercase					:






						def __init__(self  :	str			)       ->	List[str]:





							"""simple docstring"""


							lowerCAmelCase												=  {}
							lowerCAmelCase												=  {}






						def __len__(self  :	Optional[int]			)       ->	List[str]:





							"""simple docstring"""


							return len(self.parent			)






						def 					UpperCAmelCase							(self  :	List[str]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]			)       ->	str:





							"""simple docstring"""


							if item in self.parent:
								return self.find(SCREAMING_SNAKE_CASE_			)

							lowerCAmelCase												=  item
							lowerCAmelCase												=  0
							return item






						def 					UpperCAmelCase							(self  :	Dict      ,SCREAMING_SNAKE_CASE_  :	Union[str, Any]			)       ->	Tuple:





							"""simple docstring"""


							if item not in self.parent:
								return self.make_set(SCREAMING_SNAKE_CASE_			)
							if item != self.parent[item]:
								lowerCAmelCase												=  self.find(self.parent[item]			)
							return self.parent[item]






						def 					UpperCAmelCase							(self  :	Optional[int]      ,SCREAMING_SNAKE_CASE_  :	Tuple      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]			)       ->	List[str]:





							"""simple docstring"""


							lowerCAmelCase												=  self.find(SCREAMING_SNAKE_CASE_			)
							lowerCAmelCase												=  self.find(SCREAMING_SNAKE_CASE_			)

							if roota == roota:
								return roota

							if self.rank[roota] > self.rank[roota]:
								lowerCAmelCase												=  roota
								return roota

							if self.rank[roota] < self.rank[roota]:
								lowerCAmelCase												=  roota
								return roota

							if self.rank[roota] == self.rank[roota]:
								self.rank[roota] += 1
								lowerCAmelCase												=  roota
								return roota
							return None






			@staticmethod
			def 					UpperCAmelCase							(SCREAMING_SNAKE_CASE_  :	Any			)       ->	List[str]:





				"""simple docstring"""


				lowerCAmelCase												=  graph.num_vertices

				lowerCAmelCase												=  Graph.UnionFind()
				lowerCAmelCase												=  []
				while num_components > 1:
					lowerCAmelCase												=  {}
					for vertex in graph.get_vertices():
						lowerCAmelCase												=  -1

					lowerCAmelCase												=  graph.get_edges()
					for edge in edges:
						lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase												=  edge
						edges.remove((tail, head, weight)			)
					for edge in edges:
						lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase												=  edge
						lowerCAmelCase												=  union_find.find(SCREAMING_SNAKE_CASE_			)
						lowerCAmelCase												=  union_find.find(SCREAMING_SNAKE_CASE_			)
						if seta != seta:
							if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
								lowerCAmelCase												=  [head, tail, weight]

							if cheap_edge[seta] == -1 or cheap_edge[seta][2] > weight:
								lowerCAmelCase												=  [head, tail, weight]
					for vertex in cheap_edge:
						if cheap_edge[vertex] != -1:
							lowerCAmelCase							,       lowerCAmelCase							,       lowerCAmelCase												=  cheap_edge[vertex]
							if union_find.find(SCREAMING_SNAKE_CASE_			) != union_find.find(SCREAMING_SNAKE_CASE_			):
								union_find.union(SCREAMING_SNAKE_CASE_      ,SCREAMING_SNAKE_CASE_			)
								mst_edges.append(cheap_edge[vertex]			)
								lowerCAmelCase												=  num_components - 1
				lowerCAmelCase												=  Graph.build(edges=SCREAMING_SNAKE_CASE_			)
				return mst




"""simple docstring"""






from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCAmelCase        =				logging.get_logger(__name__)

UpperCAmelCase        =				{
    """shi-labs/nat-mini-in1k-224""": """https://huggingface.co/shi-labs/nat-mini-in1k-224/resolve/main/config.json""",
    # See all Nat models at https://huggingface.co/models?filter=nat
}



class 			lowercase					( lowercase__   ,lowercase__		):
			lowercase        =     '''nat'''

			lowercase        =     {
			    '''num_attention_heads''': '''num_heads''',
			    '''num_hidden_layers''': '''num_layers''',
			}






			def __init__(self  :	Union[str, Any]      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=4      ,SCREAMING_SNAKE_CASE_  :	Dict=3      ,SCREAMING_SNAKE_CASE_  :	int=64      ,SCREAMING_SNAKE_CASE_  :	Tuple=[3, 4, 6, 5]      ,SCREAMING_SNAKE_CASE_  :	Dict=[2, 4, 8, 16]      ,SCREAMING_SNAKE_CASE_  :	Optional[int]=7      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=3.0      ,SCREAMING_SNAKE_CASE_  :	Optional[Any]=True      ,SCREAMING_SNAKE_CASE_  :	Any=0.0      ,SCREAMING_SNAKE_CASE_  :	List[Any]=0.0      ,SCREAMING_SNAKE_CASE_  :	Dict=0.1      ,SCREAMING_SNAKE_CASE_  :	Tuple="gelu"      ,SCREAMING_SNAKE_CASE_  :	str=0.02      ,SCREAMING_SNAKE_CASE_  :	str=1e-5      ,SCREAMING_SNAKE_CASE_  :	int=0.0      ,SCREAMING_SNAKE_CASE_  :	List[Any]=None      ,SCREAMING_SNAKE_CASE_  :	Tuple=None      ,**SCREAMING_SNAKE_CASE_  :	Union[str, Any]      ,)       ->	Tuple:





				"""simple docstring"""


				super().__init__(**SCREAMING_SNAKE_CASE_			)

				lowerCAmelCase												=  patch_size
				lowerCAmelCase												=  num_channels
				lowerCAmelCase												=  embed_dim
				lowerCAmelCase												=  depths
				lowerCAmelCase												=  len(SCREAMING_SNAKE_CASE_			)
				lowerCAmelCase												=  num_heads
				lowerCAmelCase												=  kernel_size
				lowerCAmelCase												=  mlp_ratio
				lowerCAmelCase												=  qkv_bias
				lowerCAmelCase												=  hidden_dropout_prob
				lowerCAmelCase												=  attention_probs_dropout_prob
				lowerCAmelCase												=  drop_path_rate
				lowerCAmelCase												=  hidden_act
				lowerCAmelCase												=  layer_norm_eps
				lowerCAmelCase												=  initializer_range
				# we set the hidden_size attribute in order to make Nat work with VisionEncoderDecoderModel
				# this indicates the channel dimension after the last stage of the model
				lowerCAmelCase												=  int(embed_dim * 2 ** (len(SCREAMING_SNAKE_CASE_			) - 1)			)
				lowerCAmelCase												=  layer_scale_init_value
				lowerCAmelCase												=  ['''stem'''] + [F"""stage{idx}""" for idx in range(1      ,len(SCREAMING_SNAKE_CASE_			) + 1			)]
				lowerCAmelCase							,       lowerCAmelCase												=  get_aligned_output_features_output_indices(
				    out_features=SCREAMING_SNAKE_CASE_      ,out_indices=SCREAMING_SNAKE_CASE_      ,stage_names=self.stage_names			)


