
"""simple docstring"""







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


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

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


lowerCamelCase__        =		{
    """CLIPConfigMixin""",
    """DecisionTransformerConfigMixin""",
    """EncoderDecoderConfigMixin""",
    """RagConfigMixin""",
    """SpeechEncoderDecoderConfigMixin""",
    """VisionEncoderDecoderConfigMixin""",
    """VisionTextDualEncoderConfigMixin""",
}
def    __lowerCAmelCase    ():
	__lowerCAmelCase      :						Tuple						      =				[]

	for config_class in list(CONFIG_MAPPING.values()		):
		__lowerCAmelCase      :						Dict						      =				False

		# source code of `config_class`
		__lowerCAmelCase      :						Optional[Any]						      =				inspect.getsource(_UpperCamelCase		)
		__lowerCAmelCase      :						Dict						      =				_re_checkpoint.findall(_UpperCamelCase		)

		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')`
			__lowerCAmelCase      ,       __lowerCAmelCase      :						List[str]						      =				checkpoint

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

		__lowerCAmelCase      :						Dict						      =				config_class.__name__
		if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
			configs_without_checkpoint.append(_UpperCamelCase		)

	if len(_UpperCamelCase		) > 0:
		__lowerCAmelCase      :						List[Any]						      =				'\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()

"""simple docstring"""







import os
import tempfile
import unittest
from pathlib import Path

from transformers import AutoConfig, is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
							import tensorflow as tf

							from transformers import TensorFlowBenchmark, TensorFlowBenchmarkArguments




@require_tf
class 			A__	(     unittest.TestCase):

		def 							__lowerCamelCase							(				self	,		_SCREAMING_SNAKE_CASE			):
			for model_result in results.values():
				for batch_size, sequence_length in zip(model_result['bs']	,		model_result['ss']			):
					__lowerCAmelCase      :						Optional[Any]						      =				model_result['result'][batch_size][sequence_length]
					self.assertIsNotNone(_SCREAMING_SNAKE_CASE			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Dict						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						int						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		eager_mode=_SCREAMING_SNAKE_CASE	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Tuple						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Optional[int]						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						int						      =				'sgugger/tiny-distilbert-classification'
			__lowerCAmelCase      :						Any						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		only_pretrain_model=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Optional[int]						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Optional[Any]						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[int]						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						str						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						List[str]						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Tuple						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Union[str, Any]						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						int						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Any						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		eager_mode=_SCREAMING_SNAKE_CASE	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Dict						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE	,		[config]			)
			__lowerCAmelCase      :						str						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[Any]						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						Tuple						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						int						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Any						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE	,		[config]			)
			__lowerCAmelCase      :						Dict						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Any						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						str						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						str						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						List[str]						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_train_result			)
			self.check_results_dict_not_empty(results.memory_train_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[str]						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						Any						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						List[str]						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						List[Any]						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE	,		[config]			)
			__lowerCAmelCase      :						List[Any]						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_train_result			)
			self.check_results_dict_not_empty(results.memory_train_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[int]						      =				'patrickvonplaten/t5-tiny-random'
			__lowerCAmelCase      :						int						      =				AutoConfig.from_pretrained(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						List[str]						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Dict						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE	,		configs=[config]			)
			__lowerCAmelCase      :						Any						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		@unittest.skipIf(is_tf_available() and len(tf.config.list_physical_devices('GPU'			)			) == 0	,		'Cannot do xla on CPU.'			)
		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						List[str]						      =				'sshleifer/tiny-gpt2'
			__lowerCAmelCase      :						List[Any]						      =				TensorFlowBenchmarkArguments(
			    models=[MODEL_ID]	,		training=_SCREAMING_SNAKE_CASE	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		use_xla=_SCREAMING_SNAKE_CASE	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
			__lowerCAmelCase      :						Optional[int]						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
			__lowerCAmelCase      :						Dict						      =				benchmark.run()
			self.check_results_dict_not_empty(results.time_inference_result			)
			self.check_results_dict_not_empty(results.memory_inference_result			)

		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Optional[int]						      =				'sshleifer/tiny-gpt2'
			with tempfile.TemporaryDirectory() as tmp_dir:
				__lowerCAmelCase      :						List[str]						      =				TensorFlowBenchmarkArguments(
				    models=[MODEL_ID]	,		inference=_SCREAMING_SNAKE_CASE	,		save_to_csv=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		inference_time_csv_file=os.path.join(_SCREAMING_SNAKE_CASE	,		'inf_time.csv'			)	,		inference_memory_csv_file=os.path.join(_SCREAMING_SNAKE_CASE	,		'inf_mem.csv'			)	,		env_info_csv_file=os.path.join(_SCREAMING_SNAKE_CASE	,		'env.csv'			)	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
				__lowerCAmelCase      :						Tuple						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
				benchmark.run()
				self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE	,		'inf_time.csv'			)			).exists()			)
				self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE	,		'inf_mem.csv'			)			).exists()			)
				self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE	,		'env.csv'			)			).exists()			)







		def 							__lowerCamelCase							(				self			):
			__lowerCAmelCase      :						Tuple						      =				'sshleifer/tiny-gpt2'

			def _check_summary_is_not_empty(_SCREAMING_SNAKE_CASE			):
				self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'sequential'			)			)
				self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'cumulative'			)			)
				self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'current'			)			)
				self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE	,		'total'			)			)

			with tempfile.TemporaryDirectory() as tmp_dir:
				__lowerCAmelCase      :						Any						      =				TensorFlowBenchmarkArguments(
				    models=[MODEL_ID]	,		inference=_SCREAMING_SNAKE_CASE	,		sequence_lengths=[8]	,		batch_sizes=[1]	,		log_filename=os.path.join(_SCREAMING_SNAKE_CASE	,		'log.txt'			)	,		log_print=_SCREAMING_SNAKE_CASE	,		trace_memory_line_by_line=_SCREAMING_SNAKE_CASE	,		eager_mode=_SCREAMING_SNAKE_CASE	,		multi_process=_SCREAMING_SNAKE_CASE	,		)
				__lowerCAmelCase      :						Any						      =				TensorFlowBenchmark(_SCREAMING_SNAKE_CASE			)
				__lowerCAmelCase      :						int						      =				benchmark.run()
				_check_summary_is_not_empty(result.inference_summary			)
				self.assertTrue(Path(os.path.join(_SCREAMING_SNAKE_CASE	,		'log.txt'			)			).exists()			)