




"""simple docstring"""




import enum
import os
from hashlib import shaaaa
from typing import Optional

from .. import config
from .logging import get_logger


lowerCAmelCase							:			Any     							=							get_logger(__name__)






class     __magic_name__							(       enum.Enum				):






				'''simple docstring'''
				__UpperCamelCase			  =						"all_checks"
				__UpperCamelCase			  =						"basic_checks"
				__UpperCamelCase			  =						"no_checks"






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''




def     a__ (				snake_case__       , snake_case__       , snake_case__=None				)						->					Dict:
			if expected_checksums is None:
						logger.info("""Unable to verify checksums."""				)
						return
			if len(set(snake_case__				) - set(snake_case__				)				) > 0:
						raise ExpectedMoreDownloadedFiles(str(set(snake_case__				) - set(snake_case__				)				)				)
			if len(set(snake_case__				) - set(snake_case__				)				) > 0:
						raise UnexpectedDownloadedFile(str(set(snake_case__				) - set(snake_case__				)				)				)
			lowerCamelCase			      =					[url for url in expected_checksums if expected_checksums[url] != recorded_checksums[url]]
			lowerCamelCase			      =					""" for """ + verification_name if verification_name is not None else """"""
			if len(snake_case__				) > 0:
						raise NonMatchingChecksumError(
						    F'Checksums didn\'t match{for_verification_name}:\n'
						    F'{bad_urls}\n'
						    """Set `verification_mode='no_checks'` to skip checksums verification and ignore this error"""				)
			logger.info("""All the checksums matched successfully""" + for_verification_name				)






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''






class     __magic_name__							(       UpperCAmelCase__				):






				'''simple docstring'''




def     a__ (				snake_case__       , snake_case__				)						->					List[Any]:
			if expected_splits is None:
						logger.info("""Unable to verify splits sizes."""				)
						return
			if len(set(snake_case__				) - set(snake_case__				)				) > 0:
						raise ExpectedMoreSplits(str(set(snake_case__				) - set(snake_case__				)				)				)
			if len(set(snake_case__				) - set(snake_case__				)				) > 0:
						raise UnexpectedSplits(str(set(snake_case__				) - set(snake_case__				)				)				)
			lowerCamelCase			      =					[
			    {"""expected""": expected_splits[name], """recorded""": recorded_splits[name]}
			    for name in expected_splits
			    if expected_splits[name].num_examples != recorded_splits[name].num_examples
			]
			if len(snake_case__				) > 0:
						raise NonMatchingSplitsSizesError(str(snake_case__				)				)
			logger.info("""All the splits matched successfully."""				)



def     a__ (				snake_case__       , snake_case__ = True				)						->					dict:
			if record_checksum:
						lowerCamelCase			      =					shaaaa()
						with open(snake_case__       , """rb"""				) as f:
									for chunk in iter(lambda: f.read(1 << 20				)       , b""""""				):
												m.update(snake_case__				)
									lowerCamelCase			      =					m.hexdigest()
			else:
						lowerCamelCase			      =					None
			return {"num_bytes": os.path.getsize(snake_case__				), "checksum": checksum}



def     a__ (				snake_case__				)						->					List[Any]:
			if dataset_size and config.IN_MEMORY_MAX_SIZE:
						return dataset_size < config.IN_MEMORY_MAX_SIZE
			else:
						return False









"""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     __magic_name__							(       unittest.TestCase				):






				'''simple docstring'''
				__UpperCamelCase			  =						MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
				__UpperCamelCase			  =						TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING





				def    _lowerCAmelCase				(       self		, _a		, _a		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					TextaTextGenerationPipeline(model=_a		, tokenizer=_a )
							return generator, ["Something to write", "Something else"]





				def    _lowerCAmelCase				(       self		, _a		, _a ):





							"""simple docstring"""
							lowerCamelCase			      =					generator("""Something there""" )
							self.assertEqual(_a		, [{"""generated_text""": ANY(_a )}] )
							# These are encoder decoder, they don't just append to incoming string
							self.assertFalse(outputs[0]["""generated_text"""].startswith("""Something there""" ) )

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

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

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





				@require_torch
				def    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					pipeline("""text2text-generation"""		, model="""patrickvonplaten/t5-tiny-random"""		, framework="""pt""" )
							# do_sample=False necessary for reproducibility
							lowerCamelCase			      =					generator("""Something there"""		, do_sample=_a )
							self.assertEqual(_a		, [{"""generated_text""": """"""}] )

							lowerCamelCase			      =					3
							lowerCamelCase			      =					generator(
							    """Something there"""		, num_return_sequences=_a		, num_beams=_a		, )
							lowerCamelCase			      =					[
							    {"""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(_a		, _a )

							lowerCamelCase			      =					generator("""This is a test"""		, do_sample=_a		, num_return_sequences=2		, return_tensors=_a )
							self.assertEqual(
							    _a		, [
							        {"""generated_token_ids""": ANY(torch.Tensor )},
							        {"""generated_token_ids""": ANY(torch.Tensor )},
							    ]		, )
							lowerCamelCase			      =					generator.model.config.eos_token_id
							lowerCamelCase			      =					"""<pad>"""
							lowerCamelCase			      =					generator(
							    ["""This is a test""", """This is a second test"""]		, do_sample=_a		, num_return_sequences=2		, batch_size=2		, return_tensors=_a		, )
							self.assertEqual(
							    _a		, [
							        [
							            {"""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    _lowerCAmelCase				(       self ):





							"""simple docstring"""
							lowerCamelCase			      =					pipeline("""text2text-generation"""		, model="""patrickvonplaten/t5-tiny-random"""		, framework="""tf""" )
							# do_sample=False necessary for reproducibility
							lowerCamelCase			      =					generator("""Something there"""		, do_sample=_a )
							self.assertEqual(_a		, [{"""generated_text""": """"""}] )



