


'''simple docstring'''
__snake_case											=					{0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

__snake_case											=					{0: [1, 2, 3], 1: [2], 2: [0], 3: [4], 4: [5], 5: [3]}


def       a				(      __a			, __a			, __a       )  ->     list[int]:



					'''simple docstring'''






					UpperCamelCase__       :Union[str, Any]							 =			True
					UpperCamelCase__       :Tuple							 =			[]

					for neighbour in graph[vert]:
										if not visited[neighbour]:
															order += topology_sort(__a			, __a			, __a       )

					order.append(__a       )

					return order


def       a				(      __a			, __a			, __a       )  ->     list[int]:



					'''simple docstring'''






					UpperCamelCase__       :Tuple							 =			True
					UpperCamelCase__       :Union[str, Any]							 =			[vert]

					for neighbour in reversed_graph[vert]:
										if not visited[neighbour]:
															component += find_components(__a			, __a			, __a       )

					return component







def       a				(      __a       )  ->     list[list[int]]:



					'''simple docstring'''






					UpperCamelCase__       :List[str]							 =			len(__a       ) * [False]
					UpperCamelCase__       :dict[int, list[int]]							 =			{vert: [] for vert in range(len(__a       )       )}

					for vert, neighbours in graph.items():
										for neighbour in neighbours:
															reversed_graph[neighbour].append(__a       )

					UpperCamelCase__       :Optional[int]							 =			[]
					for i, was_visited in enumerate(__a       ):
										if not was_visited:
															order += topology_sort(__a			, __a			, __a       )

					UpperCamelCase__       :Tuple							 =			[]
					UpperCamelCase__       :str							 =			len(__a       ) * [False]

					for i in range(len(__a       )       ):
										UpperCamelCase__       :List[Any]							 =			order[len(__a       ) - i - 1]
										if not visited[vert]:
															UpperCamelCase__       :Optional[Any]							 =			find_components(__a			, __a			, __a       )
															components_list.append(__a       )

					return components_list






'''simple docstring'''
from math import ceil


def       a				(      __a			, __a       )  ->     Any:



					'''simple docstring'''






					UpperCamelCase__       :str							 =			list(range(0			, __a       )       )

					UpperCamelCase__       :Optional[int]							 =			[item for sublist in list(device_map.values()       ) for item in sublist]

					# Duplicate check
					UpperCamelCase__       :Optional[int]							 =			[]
					for i in device_map_blocks:
										if device_map_blocks.count(__a       ) > 1 and i not in duplicate_blocks:
															duplicate_blocks.append(__a       )
    # Missing blocks
					UpperCamelCase__       :List[str]							 =			[i for i in blocks if i not in device_map_blocks]
					UpperCamelCase__       :Optional[Any]							 =			[i for i in device_map_blocks if i not in blocks]

					if len(__a       ) != 0:
										raise ValueError(
										    '''Duplicate attention blocks specified in device_map. Attention blocks must be specified to one device.'''
										    ''' These attention blocks were specified more than once: ''' + str(__a       )       )
					if len(__a       ) != 0:
										raise ValueError(
										    '''There are attention blocks for this model that are not specified in the device_map. Add these attention '''
										    '''blocks to a device on the device_map: ''' + str(__a       )       )
					if len(__a       ) != 0:
										raise ValueError(
										    '''The device_map contains more attention blocks than this model has. Remove these from the device_map:'''
										    + str(__a       )       )







def       a				(      __a			, __a       )  ->     Tuple:



					'''simple docstring'''






					UpperCamelCase__       :Optional[Any]							 =			list(range(__a       )       )
					UpperCamelCase__       :Any							 =			int(ceil(n_layers / len(__a       )       )       )
					UpperCamelCase__       :List[Any]							 =			[layers[i : i + n_blocks] for i in range(0			, __a			, __a       )]

					return dict(zip(__a			, __a       )       )