





import importlib
import inspect
import os
import re


# All paths are set with the intent you should run this script from the root of the repo with the command
# python utils/check_config_docstrings.py
__UpperCamelCase:	List[Any] = """src/transformers"""


# This is to make sure the transformers module imported is the one in the repo.
__UpperCamelCase:	Optional[int] = importlib.util.spec_from_file_location(
    """transformers""",
    os.path.join(PATH_TO_TRANSFORMERS, """__init__.py"""),
    submodule_search_locations=[PATH_TO_TRANSFORMERS],
)
__UpperCamelCase:	List[Any] = spec.loader.load_module()

__UpperCamelCase:	int = transformers.models.auto.configuration_auto.CONFIG_MAPPING

# Regex pattern used to find the checkpoint mentioned in the docstring of `config_class`.
# For example, `[bert-base-uncased](https://huggingface.co/bert-base-uncased)`
__UpperCamelCase:	List[Any] = re.compile("""\[(.+?)\]\((https://huggingface\.co/.+?)\)""")


__UpperCamelCase:	Dict = {
    """CLIPConfigMixin""",
    """DecisionTransformerConfigMixin""",
    """EncoderDecoderConfigMixin""",
    """RagConfigMixin""",
    """SpeechEncoderDecoderConfigMixin""",
    """VisionEncoderDecoderConfigMixin""",
    """VisionTextDualEncoderConfigMixin""",
}


def       SCREAMING_SNAKE_CASE__  (       )   ->							Tuple:




		'''simple docstring'''
		lowercase__					:      Union[str, Any]      =		[]

		for config_class in list(CONFIG_MAPPING.values()			):
				lowercase__					:      Tuple      =		False

				# source code of `config_class`
				lowercase__					:      Union[str, Any]      =		inspect.getsource(_lowercase			)
				lowercase__					:      str      =		_re_checkpoint.findall(_lowercase			)

				for checkpoint in checkpoints:
						# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
						# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
						lowercase__   ,				lowercase__					:      str      =		checkpoint

						# verify the checkpoint name corresponds to the checkpoint link
						lowercase__					:      Optional[Any]      =		f"""https://huggingface.co/{ckpt_name}"""
						if ckpt_link == ckpt_link_from_name:
								lowercase__					:      str      =		True
								break

				lowercase__					:      List[Any]      =		config_class.__name__
				if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
						configs_without_checkpoint.append(_lowercase			)

		if len(_lowercase			) > 0:
				lowercase__					:      Union[str, Any]      =		'\n'.join(sorted(_lowercase			)			)
				raise ValueError(f"""The following configurations don't contain any valid checkpoint:\n{message}"""			)


if __name__ == "__main__":
			check_config_docstrings_have_checkpoints()









__UpperCamelCase:	str = {0: [2, 3], 1: [0], 2: [1], 3: [4], 4: []}

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


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]   ,    _lowercase     : int   ,    _lowercase     : list[bool]			)   ->							list[int]:




		'''simple docstring'''
		lowercase__					:      str      =		True
		lowercase__					:      int      =		[]

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

		order.append(_lowercase			)

		return order


def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]   ,    _lowercase     : int   ,    _lowercase     : list[bool]			)   ->							list[int]:




		'''simple docstring'''
		lowercase__					:      Union[str, Any]      =		True
		lowercase__					:      Optional[Any]      =		[vert]

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

		return component





def       SCREAMING_SNAKE_CASE__  (       _lowercase     : dict[int, list[int]]			)   ->							list[list[int]]:




		'''simple docstring'''
		lowercase__					:      Optional[int]      =		len(_lowercase			) * [False]
		lowercase__					:      dict[int, list[int]]      =		{vert: [] for vert in range(len(_lowercase			)			)}

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

		lowercase__					:      Dict      =		[]
		for i, was_visited in enumerate(_lowercase			):
				if not was_visited:
						order += topology_sort(_lowercase   ,    _lowercase   ,    _lowercase			)

		lowercase__					:      Dict      =		[]
		lowercase__					:      Optional[Any]      =		len(_lowercase			) * [False]

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

		return components_list


