



import inspect
import re

from transformers.utils import direct_transformers_import


# 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__     = "src/transformers"


# This is to make sure the transformers module imported is the one in the repo.
UpperCAmelCase__     = direct_transformers_import(PATH_TO_TRANSFORMERS)

UpperCAmelCase__     = 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__     = re.compile(r"\[(.+?)\]\((https://huggingface\.co/.+?)\)")


UpperCAmelCase__     = {
    "DecisionTransformerConfig",
    "EncoderDecoderConfig",
    "MusicgenConfig",
    "RagConfig",
    "SpeechEncoderDecoderConfig",
    "TimmBackboneConfig",
    "VisionEncoderDecoderConfig",
    "VisionTextDualEncoderConfig",
    "LlamaConfig",
}





def 							A			(  _UpperCAmelCase       :     Optional[int]					)       ->				Optional[int]:







			'''simple docstring'''
			_UpperCAmelCase	 =     None

			# source code of `config_class`
			_UpperCAmelCase	 =     inspect.getsource(_UpperCAmelCase					)
			_UpperCAmelCase	 =     _re_checkpoint.findall(_UpperCAmelCase					)

			# Each `checkpoint` is a tuple of a checkpoint name and a checkpoint link.
			# For example, `('bert-base-uncased', 'https://huggingface.co/bert-base-uncased')`
			for ckpt_name, ckpt_link in checkpoints:
						# allow the link to end with `/`
						if ckpt_link.endswith('/'					):
									_UpperCAmelCase	 =     ckpt_link[:-1]

						# verify the checkpoint name corresponds to the checkpoint link
						_UpperCAmelCase	 =     F"https://huggingface.co/{ckpt_name}"
						if ckpt_link == ckpt_link_from_name:
									_UpperCAmelCase	 =     ckpt_name
									break

			return checkpoint





def 							A			(  )       ->				Tuple:







			'''simple docstring'''
			_UpperCAmelCase	 =     []

			for config_class in list(CONFIG_MAPPING.values()					):
						# Skip deprecated models
						if "models.deprecated" in config_class.__module__:
									continue
						_UpperCAmelCase	 =     get_checkpoint_from_config_class(_UpperCAmelCase					)

						_UpperCAmelCase	 =     config_class.__name__
						if checkpoint is None and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
									configs_without_checkpoint.append(_UpperCAmelCase					)

			if len(_UpperCAmelCase					) > 0:
						_UpperCAmelCase	 =     '\n'.join(sorted(_UpperCAmelCase					)					)
						raise ValueError(F"The following configurations don't contain any valid checkpoint:\n{message}"					)


if __name__ == "__main__":
							check_config_docstrings_have_checkpoints()





import unittest

from knapsack import knapsack as k







class     __lowerCAmelCase					(    unittest.TestCase		):



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



						"""simple docstring"""






						_UpperCAmelCase	 =     0
						_UpperCAmelCase	 =     [0]
						_UpperCAmelCase	 =     [0]
						_UpperCAmelCase	 =     len(A)
						self.assertEqual(k.knapsack(A				,	A				,	A				,	A)				,	0)

						_UpperCAmelCase	 =     [60]
						_UpperCAmelCase	 =     [10]
						_UpperCAmelCase	 =     len(A)
						self.assertEqual(k.knapsack(A				,	A				,	A				,	A)				,	0)



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



						"""simple docstring"""






						_UpperCAmelCase	 =     3
						_UpperCAmelCase	 =     [1, 2, 3]
						_UpperCAmelCase	 =     [3, 2, 1]
						_UpperCAmelCase	 =     len(A)
						self.assertEqual(k.knapsack(A				,	A				,	A				,	A)				,	5)



			def 					_lowerCamelCase (		self     :						Tuple)     ->					Tuple:



						"""simple docstring"""






						_UpperCAmelCase	 =     50
						_UpperCAmelCase	 =     [60, 1_00, 1_20]
						_UpperCAmelCase	 =     [10, 20, 30]
						_UpperCAmelCase	 =     len(A)
						self.assertEqual(k.knapsack(A				,	A				,	A				,	A)				,	2_20)


if __name__ == "__main__":
							unittest.main()
