



"""simple docstring"""







import unittest

from transformers import (
    MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
    TextaTextGenerationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from transformers.utils import is_torch_available

from .test_pipelines_common import ANY


if is_torch_available():
			import torch

@is_pipeline_test
class       _a  ( unittest.TestCase):
			__magic_name__     					=     MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
			__magic_name__     					=     TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING



			def 				__lowercase					(			self							:				List[Any]   ,	_lowercase							:				Optional[int]   ,	_lowercase							:				Any   ,	_lowercase							:				str		)							->					Tuple:
									snake_case   :			List[str]						    = TextaTextGenerationPipeline(model=_lowercase   ,	tokenizer=_lowercase		)
									return generator, ["Something to write", "Something else"]



			def 				__lowercase					(			self							:				Optional[int]   ,	_lowercase							:				int   ,	_lowercase							:				Optional[Any]		)							->					str:
									snake_case   :			List[str]						    = generator("Something there"		)
									self.assertEqual(_lowercase   ,	[{"generated_text": ANY(_lowercase		)}]		)
									# These are encoder decoder, they don't just append to incoming string
									self.assertFalse(outputs[0]["generated_text"].startswith("Something there"		)		)

									snake_case   :			int						    = generator(["This is great !", "Something else"]   ,	num_return_sequences=2   ,	do_sample=_lowercase		)
									self.assertEqual(
									    _lowercase   ,	[
									        [{"generated_text": ANY(_lowercase		)}, {"generated_text": ANY(_lowercase		)}],
									        [{"generated_text": ANY(_lowercase		)}, {"generated_text": ANY(_lowercase		)}],
									    ]   ,	)

									snake_case   :			Dict						    = generator(
									    ["This is great !", "Something else"]   ,	num_return_sequences=2   ,	batch_size=2   ,	do_sample=_lowercase		)
									self.assertEqual(
									    _lowercase   ,	[
									        [{"generated_text": ANY(_lowercase		)}, {"generated_text": ANY(_lowercase		)}],
									        [{"generated_text": ANY(_lowercase		)}, {"generated_text": ANY(_lowercase		)}],
									    ]   ,	)

									with self.assertRaises(_lowercase		):
															generator(4		)



			@require_torch
			def 				__lowercase					(			self							:				List[str]		)							->					Tuple:
									snake_case   :			Optional[Any]						    = pipeline("text2text-generation"   ,	model="patrickvonplaten/t5-tiny-random"   ,	framework="pt"		)
									# do_sample=False necessary for reproducibility
									snake_case   :			Optional[Any]						    = generator("Something there"   ,	do_sample=_lowercase		)
									self.assertEqual(_lowercase   ,	[{"generated_text": ""}]		)

									snake_case   :			Dict						    = 3
									snake_case   :			List[str]						    = generator(
									    "Something there"   ,	num_return_sequences=_lowercase   ,	num_beams=_lowercase   ,	)
									snake_case   :			Optional[Any]						    = [
									    {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide Beide"},
									    {"generated_text": "Beide Beide Beide Beide Beide Beide Beide Beide"},
									    {"generated_text": ""},
									]
									self.assertEqual(_lowercase   ,	_lowercase		)

									snake_case   :			Optional[int]						    = generator("This is a test"   ,	do_sample=_lowercase   ,	num_return_sequences=2   ,	return_tensors=_lowercase		)
									self.assertEqual(
									    _lowercase   ,	[
									        {"generated_token_ids": ANY(torch.Tensor		)},
									        {"generated_token_ids": ANY(torch.Tensor		)},
									    ]   ,	)
									snake_case   :			Any						    = generator.model.config.eos_token_id
									snake_case   :			List[str]						    = "<pad>"
									snake_case   :			Any						    = generator(
									    ["This is a test", "This is a second test"]   ,	do_sample=_lowercase   ,	num_return_sequences=2   ,	batch_size=2   ,	return_tensors=_lowercase   ,	)
									self.assertEqual(
									    _lowercase   ,	[
									        [
									            {"generated_token_ids": ANY(torch.Tensor		)},
									            {"generated_token_ids": ANY(torch.Tensor		)},
									        ],
									        [
									            {"generated_token_ids": ANY(torch.Tensor		)},
									            {"generated_token_ids": ANY(torch.Tensor		)},
									        ],
									    ]   ,	)



			@require_tf
			def 				__lowercase					(			self							:				Union[str, Any]		)							->					Tuple:
									snake_case   :			Tuple						    = pipeline("text2text-generation"   ,	model="patrickvonplaten/t5-tiny-random"   ,	framework="tf"		)
									# do_sample=False necessary for reproducibility
									snake_case   :			Tuple						    = generator("Something there"   ,	do_sample=_lowercase		)
									self.assertEqual(_lowercase   ,	[{"generated_text": ""}]		)








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


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

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


A		=						{
    'CLIPConfigMixin',
    'DecisionTransformerConfigMixin',
    'EncoderDecoderConfigMixin',
    'RagConfigMixin',
    'SpeechEncoderDecoderConfigMixin',
    'VisionEncoderDecoderConfigMixin',
    'VisionTextDualEncoderConfigMixin',
}

def  __SCREAMING_SNAKE_CASE		(			):
						"""simple docstring"""






						snake_case   :			Union[str, Any]						    = []

						for config_class in list(CONFIG_MAPPING.values() ):
												snake_case   :			List[str]						    = False

												# source code of `config_class`
												snake_case   :			Optional[int]						    = inspect.getsource(lowerCamelCase_ )
												snake_case   :			Optional[int]						    = _re_checkpoint.findall(lowerCamelCase_ )

												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')`
																		snake_case    ,			snake_case   :			Tuple						    = checkpoint

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

												snake_case   :			Any						    = config_class.__name__
												if not checkpoint_found and name not in CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPOINT_CHECK:
																		configs_without_checkpoint.append(lowerCamelCase_ )

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


if __name__ == "__main__":
			check_config_docstrings_have_checkpoints()



